|
3 | 3 | from pathlib import Path |
4 | 4 |
|
5 | 5 | from pycpio import PyCPIO |
6 | | -from zenlib.util import init_logger, init_argparser, process_args |
| 6 | +from zenlib.util import get_kwargs_from_args, get_args_n_logger |
7 | 7 |
|
8 | 8 |
|
9 | 9 | def main(): |
10 | | - logger = init_logger(__package__) |
11 | | - argparser = init_argparser(prog=__package__, description='PyCPIO') |
12 | | - |
13 | | - argparser.add_argument('-i', '--input', help='input file') |
14 | | - |
15 | | - argparser.add_argument('-a', '--append', action='store', help='append to archive') |
16 | | - argparser.add_argument('--recursive', action='store_true', help='append to archive recursively') |
17 | | - argparser.add_argument('--relative', action='store', help='append to archive relative to this path') |
18 | | - argparser.add_argument('--absolute', action='store_true', help='allow absolute paths') |
19 | | - argparser.add_argument('--rm', '--delete', action='store', help='delete from archive') |
20 | | - argparser.add_argument('-n', '--name', action='store', help='Name/path override for append') |
21 | | - |
22 | | - argparser.add_argument('-s', '--symlink', action='store', help='create symlink') |
23 | | - argparser.add_argument('-c', '--chardev', action='store', help='create character device') |
24 | | - |
25 | | - argparser.add_argument('--major', action='store', help='major number for character/block device') |
26 | | - argparser.add_argument('--minor', action='store', help='minor number for character/block device') |
27 | | - |
28 | | - argparser.add_argument('-u', '--set-owner', action='store', help='set UID on all files') |
29 | | - argparser.add_argument('-g', '--set-group', action='store', help='set GID on all files') |
30 | | - argparser.add_argument('-m', '--set-mode', action='store', help='set mode on all files') |
31 | | - |
32 | | - argparser.add_argument('-o', '--output', help='output file') |
33 | | - |
34 | | - argparser.add_argument('-l', '--list', action='store_true', help='list CPIO contents') |
35 | | - argparser.add_argument('-p', '--print', action='store_true', help='print CPIO contents') |
36 | | - |
37 | | - args = process_args(argparser, logger=logger) |
38 | | - kwargs = {'logger': logger} |
39 | | - |
40 | | - if args.name: |
41 | | - kwargs['name'] = args.name |
42 | | - |
43 | | - if args.set_owner: |
44 | | - kwargs['uid'] = int(args.set_owner) |
45 | | - |
46 | | - if args.set_group: |
47 | | - kwargs['gid'] = int(args.set_group) |
48 | | - |
49 | | - if args.set_mode: |
50 | | - kwargs['mode'] = int(args.set_mode, 8) |
| 10 | + arguments = [{'flags': ['-i', '--input'], 'help': 'input file'}, |
| 11 | + {'flags': ['-a', '--append'], 'help': 'append to archive'}, |
| 12 | + {'flags': ['--recursive'], 'action': 'store_true', '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': ['--rm', '--delete'], 'action': 'store', 'help': 'delete from archive'}, |
| 16 | + {'flags': ['-n', '--name'], 'action': 'store', 'help': 'Name/path override for append'}, |
| 17 | + {'flags': ['-s', '--symlink'], 'action': 'store', 'help': 'create symlink'}, |
| 18 | + {'flags': ['-c', '--chardev'], 'action': 'store', 'help': 'create character device'}, |
| 19 | + {'flags': ['--major'], 'action': 'store', 'help': 'major number for character/block device', 'type': int}, |
| 20 | + {'flags': ['--minor'], 'action': 'store', 'help': 'minor number for character/block device', 'type': int}, |
| 21 | + {'flags': ['-u', '--set-owner'], 'action': 'store', 'help': 'set UID on all files', 'type': int, 'dest': 'uid'}, |
| 22 | + {'flags': ['-g', '--set-group'], 'action': 'store', 'help': 'set GID on all files', 'type': int, 'dest': 'gid'}, |
| 23 | + {'flags': ['-m', '--set-mode'], 'action': 'store', 'help': 'set mode on all files', 'type': int, 'dest': 'mode'}, |
| 24 | + {'flags': ['-o', '--output'], 'help': 'output file'}, |
| 25 | + {'flags': ['-l', '--list'], 'action': 'store_true', 'help': 'list CPIO contents'}, |
| 26 | + {'flags': ['-p', '--print'], 'action': 'store_true', 'help': 'print CPIO contents'}] |
| 27 | + |
| 28 | + args, logger = get_args_n_logger(package=__package__, description='PyCPIO', arguments=arguments) |
| 29 | + kwargs = get_kwargs_from_args(args, logger=logger) |
51 | 30 |
|
52 | 31 | c = PyCPIO(**kwargs) |
53 | 32 | if args.input: |
|
0 commit comments