1
0
mirror of https://github.com/openSUSE/osc.git synced 2024-11-10 06:46:15 +01:00

Run a small demo when the cpio module is invoked as a script

It just reads in a cpio archive and print the headers.
This commit is contained in:
Marcus Huewe 2019-01-15 19:46:00 +01:00
parent 245df33444
commit 1c4385a579

View File

@ -254,3 +254,16 @@ class CpioWrite:
self.add('TRAILER!!!', '') self.add('TRAILER!!!', '')
self.add_padding() self.add_padding()
return ''.join(self.cpio) return ''.join(self.cpio)
if __name__ == '__main__':
if len(sys.argv) != 2:
print('usage: %s /path/to/file.cpio' % sys.argv[0])
sys.exit(1)
# a potential user might want to pass a bytes instead of a str
# to make sure that the CpioError's file attribute is always a
# bytes
cpio = CpioRead(sys.argv[1])
cpio.read()
for hdr in cpio:
print(hdr)