|
2 | 2 |
|
3 | 3 | from pathlib import Path |
4 | 4 |
|
5 | | -from pycpio import PyCPIO |
6 | 5 | from zenlib.util import get_kwargs |
7 | 6 |
|
| 7 | +from pycpio import PyCPIO |
| 8 | + |
8 | 9 |
|
9 | 10 | def main(): |
10 | | - arguments = [{'flags': ['-i', '--input'], 'help': 'input file'}, |
11 | | - {'flags': ['-a', '--append'], 'help': 'append to archive'}, |
12 | | - {'flags': ['--recursive'], 'action': 'store', 'help': 'append to archive recursively'}, |
13 | | - {'flags': ['--relative'], 'action': 'store', 'help': 'append to archive relative to this path'}, |
14 | | - {'flags': ['--absolute'], 'action': 'store_true', 'help': 'allow absolute paths'}, |
15 | | - {'flags': ['--reproducible'], 'action': 'store_true', 'help': 'Set mtime to 0, start inodes at 0'}, |
16 | | - {'flags': ['--rm', '--delete'], 'action': 'store', 'help': 'delete from archive'}, |
17 | | - {'flags': ['-n', '--name'], 'action': 'store', 'help': 'Name/path override for append'}, |
18 | | - {'flags': ['-s', '--symlink'], 'action': 'store', 'help': 'create symlink'}, |
19 | | - {'flags': ['-c', '--chardev'], 'action': 'store', 'help': 'create character device'}, |
20 | | - {'flags': ['--major'], 'action': 'store', 'help': 'major number for character/block device', 'type': int}, |
21 | | - {'flags': ['--minor'], 'action': 'store', 'help': 'minor number for character/block device', 'type': int}, |
22 | | - {'flags': ['-u', '--set-owner'], 'action': 'store', 'help': 'set UID on all files', 'dest': 'uid'}, |
23 | | - {'flags': ['-g', '--set-group'], 'action': 'store', 'help': 'set GID on all files', 'dest': 'gid'}, |
24 | | - {'flags': ['-m', '--set-mode'], 'action': 'store', 'help': 'set mode on all files', 'type': int, 'dest': 'mode'}, |
25 | | - {'flags': ['-z', '--compress'], 'action': 'store', 'help': 'compression type'}, |
26 | | - {'flags': ['-o', '--output'], 'help': 'output file'}, |
27 | | - {'flags': ['-l', '--list'], 'action': 'store_true', 'help': 'list CPIO contents'}, |
28 | | - {'flags': ['-p', '--print'], 'action': 'store_true', 'help': 'print CPIO contents'}] |
29 | | - |
30 | | - kwargs = get_kwargs(package=__package__, description='PyCPIO', arguments=arguments, drop_default=True) |
| 11 | + arguments = [ |
| 12 | + {"flags": ["-i", "--input"], "help": "input file"}, |
| 13 | + {"flags": ["-a", "--append"], "help": "append to archive"}, |
| 14 | + {"flags": ["--recursive"], "action": "store", "help": "append to archive recursively"}, |
| 15 | + {"flags": ["--relative"], "action": "store", "help": "append to archive relative to this path"}, |
| 16 | + {"flags": ["--absolute"], "action": "store_true", "help": "allow absolute paths"}, |
| 17 | + {"flags": ["--reproducible"], "action": "store_true", "help": "Set mtime to 0, start inodes at 0"}, |
| 18 | + {"flags": ["--rm", "--delete"], "action": "store", "help": "delete from archive"}, |
| 19 | + {"flags": ["-n", "--name"], "action": "store", "help": "Name/path override for append"}, |
| 20 | + {"flags": ["-s", "--symlink"], "action": "store", "help": "create symlink"}, |
| 21 | + {"flags": ["-c", "--chardev"], "action": "store", "help": "create character device"}, |
| 22 | + {"flags": ["--major"], "action": "store", "help": "major number for character/block device", "type": int}, |
| 23 | + {"flags": ["--minor"], "action": "store", "help": "minor number for character/block device", "type": int}, |
| 24 | + {"flags": ["-u", "--set-owner"], "action": "store", "help": "set UID on all files", "dest": "uid"}, |
| 25 | + {"flags": ["-g", "--set-group"], "action": "store", "help": "set GID on all files", "dest": "gid"}, |
| 26 | + { |
| 27 | + "flags": ["-m", "--set-mode"], |
| 28 | + "action": "store", |
| 29 | + "help": "set mode on all files", |
| 30 | + "type": int, |
| 31 | + "dest": "mode", |
| 32 | + }, |
| 33 | + {"flags": ["-z", "--compress"], "action": "store", "help": "compression type"}, |
| 34 | + {"flags": ["-o", "--output"], "help": "output file"}, |
| 35 | + {"flags": ["-l", "--list"], "action": "store_true", "help": "list CPIO contents"}, |
| 36 | + {"flags": ["-p", "--print"], "action": "store_true", "help": "print CPIO contents"}, |
| 37 | + ] |
| 38 | + |
| 39 | + kwargs = get_kwargs(package=__package__, description="PyCPIO", arguments=arguments, drop_default=True) |
31 | 40 |
|
32 | 41 | c = PyCPIO(**kwargs) |
33 | | - if input_file := kwargs.get('input'): |
| 42 | + if input_file := kwargs.get("input"): |
34 | 43 | c.read_cpio_file(Path(input_file)) |
35 | 44 |
|
36 | | - if rm_args := kwargs.get('rm'): |
| 45 | + if rm_args := kwargs.get("rm"): |
37 | 46 | c.remove_cpio(rm_args) |
38 | 47 |
|
39 | | - if symlink_dest := kwargs.get('symlink'): |
40 | | - if name := kwargs.get('name'): |
| 48 | + if symlink_dest := kwargs.get("symlink"): |
| 49 | + if name := kwargs.get("name"): |
41 | 50 | c.add_symlink(name, symlink_dest) |
42 | 51 | else: |
43 | | - raise ValueError('Symlink requires a name') |
| 52 | + raise ValueError("Symlink requires a name") |
44 | 53 |
|
45 | | - if chardev_path := kwargs.get('chardev'): |
46 | | - major = kwargs.get('major') |
47 | | - minor = kwargs.get('minor') |
| 54 | + if chardev_path := kwargs.get("chardev"): |
| 55 | + major = kwargs.get("major") |
| 56 | + minor = kwargs.get("minor") |
48 | 57 | if major is None: |
49 | | - raise ValueError('Character device requires major number') |
| 58 | + raise ValueError("Character device requires major number") |
50 | 59 | if minor is None: |
51 | | - raise ValueError('Character device requires minor number') |
| 60 | + raise ValueError("Character device requires minor number") |
52 | 61 | c.add_chardev(chardev_path, major, minor) |
53 | 62 |
|
54 | | - if append_file := kwargs.get('append'): |
55 | | - cmdargs = {'relative': kwargs.get('relative'), |
56 | | - 'path': Path(append_file), |
57 | | - 'name': kwargs.get('name'), |
58 | | - 'absolute': kwargs.get('absolute')} |
| 63 | + if append_file := kwargs.get("append"): |
| 64 | + cmdargs = { |
| 65 | + "relative": kwargs.get("relative"), |
| 66 | + "path": Path(append_file), |
| 67 | + "name": kwargs.get("name"), |
| 68 | + "absolute": kwargs.get("absolute"), |
| 69 | + } |
59 | 70 |
|
60 | 71 | c.append_cpio(**cmdargs) |
61 | 72 |
|
62 | | - if recursive_path := kwargs.get('recursive'): |
63 | | - cmdargs = {'relative': kwargs.get('relative'), 'path': Path(recursive_path)} |
| 73 | + if recursive_path := kwargs.get("recursive"): |
| 74 | + cmdargs = {"relative": kwargs.get("relative"), "path": Path(recursive_path)} |
64 | 75 | c.append_recursive(**cmdargs) |
65 | 76 |
|
66 | | - if output_file := kwargs.get('output'): |
67 | | - compression = kwargs.get('compress') |
| 77 | + if output_file := kwargs.get("output"): |
| 78 | + compression = kwargs.get("compress") |
68 | 79 | c.write_cpio_file(Path(output_file), compression=compression) |
69 | 80 |
|
70 | | - if kwargs.get('list'): |
| 81 | + if kwargs.get("list"): |
71 | 82 | print(c.list_files()) |
72 | 83 |
|
73 | | - if kwargs.get('print'): |
| 84 | + if kwargs.get("print"): |
74 | 85 | print(c) |
75 | 86 |
|
76 | 87 |
|
77 | | -if __name__ == '__main__': |
| 88 | +if __name__ == "__main__": |
78 | 89 | main() |
0 commit comments