Add dictionary_size, --dictionary.

This commit is contained in:
voussoir 2020-11-20 02:19:34 -08:00
parent cbdc2e34d7
commit 4b23d311c3

View file

@ -35,6 +35,7 @@ def RARCOMMAND(
basename, basename,
workdir, workdir,
compression=None, compression=None,
dictionary_size=None,
password=None, password=None,
profile=None, profile=None,
rec=None, rec=None,
@ -51,6 +52,7 @@ def RARCOMMAND(
-ibck = run in the background -ibck = run in the background
-ma = rar5 mode -ma = rar5 mode
-m{compression} = 0: store, 5: max -m{compression} = 0: store, 5: max
-md{x}[kmg] = x kilobytes/megabytes/gigabytes dictionary size
-mt1 = thread count: 1 -mt1 = thread count: 1
-v{x}M = split into x megabyte volumes -v{x}M = split into x megabyte volumes
-ri x:y = x priority (lower is less pri) y ms sleep between ops -ri x:y = x priority (lower is less pri) y ms sleep between ops
@ -81,6 +83,9 @@ def RARCOMMAND(
if compression is not None: if compression is not None:
command.append(f'-m{compression}') command.append(f'-m{compression}')
if dictionary_size is not None:
command.append(f'-md{dictionary_size}')
if solid: if solid:
command.append('-s') command.append('-s')
@ -156,6 +161,41 @@ def move(pattern, directory):
print(file) print(file)
shutil.move(file, directory) shutil.move(file, directory)
def normalize_dictionary_size(dictionary):
if dictionary is None:
return None
dictionary = dictionary.strip().lower()
if not re.match(r'^\d+(k|m|g)?$', dictionary):
raise ValueError(f'dictionary_size {dictionary} is invalid.')
if re.match(r'^\d+$', dictionary):
dictionary += 'm'
# https://www.winrar-france.fr/winrar_instructions_for_use/source/html/HELPSwMD.htm
VALID = [
'128k',
'256k',
'512k',
'1m',
'2m',
'4m',
'8m',
'16m',
'32m',
'64m',
'128m',
'256m',
'512m',
'1g',
]
if dictionary not in VALID:
raise ValueError(f'dictionary_size {dictionary} is invalid.')
return dictionary
def normalize_password(password): def normalize_password(password):
if password is None: if password is None:
return None return None
@ -262,6 +302,7 @@ def rarpar(
*, *,
basename=None, basename=None,
compression=None, compression=None,
dictionary_size=None,
dry=False, dry=False,
moveto=None, moveto=None,
par=None, par=None,
@ -290,6 +331,8 @@ def rarpar(
if compression not in [None, 0, 1, 2, 3, 4, 5]: if compression not in [None, 0, 1, 2, 3, 4, 5]:
raise ValueError(f'compression must be 0-5 or None, not {compression}.') raise ValueError(f'compression must be 0-5 or None, not {compression}.')
dictionary_size = normalize_dictionary_size(dictionary_size)
if type(solid) is not bool: if type(solid) is not bool:
raise TypeError(f'solid must be True or False, not {solid}.') raise TypeError(f'solid must be True or False, not {solid}.')
@ -334,6 +377,7 @@ def rarpar(
path=path, path=path,
basename=basename, basename=basename,
compression=compression, compression=compression,
dictionary_size=dictionary_size,
password=password, password=password,
profile=rar_profile, profile=rar_profile,
rec=rec, rec=rec,
@ -441,6 +485,7 @@ def rarpar_argparse(args):
path=args.path, path=args.path,
volume=args.volume, volume=args.volume,
basename=args.basename, basename=args.basename,
dictionary_size=args.dictionary_size,
dry=args.dry, dry=args.dry,
moveto=args.moveto, moveto=args.moveto,
par=args.par, par=args.par,
@ -467,6 +512,7 @@ def main(argv):
parser.add_argument('--workdir', dest='workdir', default='.') parser.add_argument('--workdir', dest='workdir', default='.')
parser.add_argument('--moveto', dest='moveto') parser.add_argument('--moveto', dest='moveto')
parser.add_argument('--recycle', dest='recycle_original', action='store_true') parser.add_argument('--recycle', dest='recycle_original', action='store_true')
parser.add_argument('--dictionary', dest='dictionary_size')
parser.add_argument('--solid', dest='solid', action='store_true') parser.add_argument('--solid', dest='solid', action='store_true')
parser.add_argument('--dry', dest='dry', action='store_true') parser.add_argument('--dry', dest='dry', action='store_true')
parser.set_defaults(func=rarpar_argparse) parser.set_defaults(func=rarpar_argparse)