2020-03-13 21:59:49 +00:00
|
|
|
import argparse
|
|
|
|
import os
|
|
|
|
import re
|
2020-06-25 05:27:12 +00:00
|
|
|
import send2trash
|
2020-03-13 21:59:49 +00:00
|
|
|
import shutil
|
2020-11-07 08:01:27 +00:00
|
|
|
import subprocess
|
2020-03-13 21:59:49 +00:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
from voussoirkit import betterhelp
|
|
|
|
from voussoirkit import bytestring
|
|
|
|
from voussoirkit import pathclass
|
2021-01-14 10:31:43 +00:00
|
|
|
from voussoirkit import subproctools
|
2021-01-14 10:31:28 +00:00
|
|
|
from voussoirkit import vlogging
|
2020-03-13 21:59:49 +00:00
|
|
|
from voussoirkit import winglob
|
2020-11-07 08:01:27 +00:00
|
|
|
from voussoirkit import winwhich
|
|
|
|
|
2021-01-29 00:51:34 +00:00
|
|
|
log = vlogging.getLogger(__name__, 'rarpar')
|
2021-01-14 10:31:28 +00:00
|
|
|
|
2020-11-07 08:01:27 +00:00
|
|
|
WINRAR = winwhich.which('winrar')
|
|
|
|
PAR2 = winwhich.which('phpar2')
|
2020-03-13 21:59:49 +00:00
|
|
|
|
|
|
|
RESERVE_SPACE_ON_DRIVE = 30 * bytestring.GIBIBYTE
|
|
|
|
|
2020-11-20 09:53:52 +00:00
|
|
|
COMPRESSION_STORE = 0
|
|
|
|
COMPRESSION_MAX = 5
|
|
|
|
|
2020-06-23 00:41:51 +00:00
|
|
|
class RarParException(Exception):
|
|
|
|
pass
|
|
|
|
|
2020-11-06 08:20:20 +00:00
|
|
|
class RarExists(RarParException):
|
|
|
|
pass
|
|
|
|
|
2020-06-23 00:41:51 +00:00
|
|
|
class NotEnoughSpace(RarParException):
|
|
|
|
pass
|
|
|
|
|
2020-03-13 21:59:49 +00:00
|
|
|
def RARCOMMAND(
|
2020-08-24 05:17:50 +00:00
|
|
|
path,
|
2020-03-13 21:59:49 +00:00
|
|
|
basename,
|
|
|
|
workdir,
|
2020-10-23 14:52:57 +00:00
|
|
|
compression=None,
|
2020-11-20 10:19:34 +00:00
|
|
|
dictionary_size=None,
|
2020-03-13 21:59:49 +00:00
|
|
|
password=None,
|
2020-10-23 14:52:57 +00:00
|
|
|
profile=None,
|
2020-03-13 21:59:49 +00:00
|
|
|
rec=None,
|
|
|
|
rev=None,
|
2020-11-20 09:55:03 +00:00
|
|
|
solid=False,
|
2020-03-13 21:59:49 +00:00
|
|
|
volume=None,
|
|
|
|
):
|
|
|
|
'''
|
|
|
|
winrar
|
|
|
|
a = make archive
|
2020-10-23 14:52:57 +00:00
|
|
|
-cp{profile} = use compression profile. this must come first so that
|
|
|
|
all subsequent options override the ones provided by
|
|
|
|
the profile.
|
2020-03-13 21:59:49 +00:00
|
|
|
-ibck = run in the background
|
|
|
|
-ma = rar5 mode
|
2020-10-23 14:52:57 +00:00
|
|
|
-m{compression} = 0: store, 5: max
|
2020-11-20 10:19:34 +00:00
|
|
|
-md{x}[kmg] = x kilobytes/megabytes/gigabytes dictionary size
|
2020-03-13 21:59:49 +00:00
|
|
|
-mt1 = thread count: 1
|
|
|
|
-v{x}M = split into x megabyte volumes
|
|
|
|
-ri x:y = x priority (lower is less pri) y ms sleep between ops
|
|
|
|
-r = include subdirectories
|
2020-11-20 09:55:03 +00:00
|
|
|
-s = solid
|
2020-03-13 21:59:49 +00:00
|
|
|
-ep1 = arcnames will start relative to the main folder,
|
|
|
|
instead of having the whole abspath of the input_pattern.
|
|
|
|
-rr{x}% = x% recovery record
|
|
|
|
-rv{x}% = x% recovery volumes
|
|
|
|
-hp{x} = encrypt with password x
|
|
|
|
-y = yes on all prompts
|
|
|
|
-x = exclude certain filenames
|
|
|
|
destination
|
|
|
|
workdir/basename.rar
|
|
|
|
files to include
|
|
|
|
input_pattern
|
|
|
|
'''
|
2020-11-07 08:01:27 +00:00
|
|
|
command = [WINRAR, 'a']
|
2020-10-23 14:52:57 +00:00
|
|
|
|
|
|
|
if profile is not None:
|
|
|
|
command.append(f'-cp{profile}')
|
|
|
|
|
|
|
|
command.extend([
|
2020-11-07 08:01:27 +00:00
|
|
|
'-ibck', '-ma', '-mt1', '-ri1:30', '-ep1',
|
|
|
|
'-y', '-xthumbs.db', '-xdesktop.ini',
|
2020-10-23 14:52:57 +00:00
|
|
|
])
|
|
|
|
|
|
|
|
if compression is not None:
|
|
|
|
command.append(f'-m{compression}')
|
|
|
|
|
2020-11-20 10:19:34 +00:00
|
|
|
if dictionary_size is not None:
|
|
|
|
command.append(f'-md{dictionary_size}')
|
|
|
|
|
2020-11-20 09:55:03 +00:00
|
|
|
if solid:
|
|
|
|
command.append('-s')
|
|
|
|
|
2020-03-13 21:59:49 +00:00
|
|
|
if volume is not None:
|
|
|
|
command.append(f'-v{volume}M')
|
|
|
|
|
|
|
|
if rec is not None:
|
|
|
|
command.append(f'-rr{rec}%')
|
|
|
|
|
|
|
|
if rev is not None:
|
|
|
|
command.append(f'-rv{rev}%')
|
|
|
|
|
|
|
|
if password is not None:
|
|
|
|
command.append(f'-hp{password}')
|
|
|
|
|
2020-08-24 05:21:36 +00:00
|
|
|
if path.is_dir:
|
|
|
|
command.append('-r')
|
|
|
|
|
2020-08-24 05:17:50 +00:00
|
|
|
if path.is_dir:
|
|
|
|
input_pattern = path.absolute_path + '\\*'
|
|
|
|
else:
|
|
|
|
input_pattern = path.absolute_path
|
|
|
|
|
2020-11-07 08:01:27 +00:00
|
|
|
command.append(f'{workdir.absolute_path}{os.sep}{basename}.rar')
|
|
|
|
command.append(f'{input_pattern}')
|
2020-03-13 21:59:49 +00:00
|
|
|
|
|
|
|
return command
|
|
|
|
|
|
|
|
def PARCOMMAND(workdir, basename, par):
|
|
|
|
'''
|
|
|
|
phpar2
|
|
|
|
c = create pars
|
|
|
|
-t1 = thread count: 1
|
|
|
|
-r{x} = x% recovery
|
|
|
|
destination
|
|
|
|
workdir/basename.par2
|
|
|
|
'''
|
|
|
|
command = [
|
2020-11-07 08:01:27 +00:00
|
|
|
PAR2,
|
|
|
|
'c', '-t1',
|
2020-03-13 21:59:49 +00:00
|
|
|
f'-r{par}',
|
2020-11-07 08:01:27 +00:00
|
|
|
f'{workdir.absolute_path}{os.sep}{basename}',
|
|
|
|
f'{workdir.absolute_path}{os.sep}{basename}*.rar',
|
2020-03-13 21:59:49 +00:00
|
|
|
]
|
|
|
|
return command
|
|
|
|
|
|
|
|
def assert_enough_space(pathsize, workdir, moveto, rec, rev, par):
|
|
|
|
plus_percent = (rec + rev + par) / 100
|
|
|
|
needed = pathsize * (1 + plus_percent)
|
|
|
|
reserve = RESERVE_SPACE_ON_DRIVE + needed
|
|
|
|
|
2020-10-29 22:53:03 +00:00
|
|
|
workdir_drive = os.path.splitdrive(workdir.absolute_path)[0] + os.sep
|
2020-03-13 21:59:49 +00:00
|
|
|
free_space = shutil.disk_usage(workdir_drive).free
|
|
|
|
|
|
|
|
if moveto is not None:
|
|
|
|
moveto_drive = os.path.splitdrive(moveto.absolute_path)[0]
|
2020-08-24 05:20:04 +00:00
|
|
|
moveto_drive = pathclass.Path(moveto_drive)
|
|
|
|
free_space = min(free_space, shutil.disk_usage(moveto_drive.absolute_path).free)
|
2020-03-13 21:59:49 +00:00
|
|
|
|
|
|
|
message = ' '.join([
|
|
|
|
f'For {bytestring.bytestring(pathsize)},',
|
|
|
|
f'Reserving {bytestring.bytestring(reserve)} /',
|
|
|
|
f'{bytestring.bytestring(free_space)}.',
|
|
|
|
])
|
2021-01-14 10:31:28 +00:00
|
|
|
log.debug(message)
|
2020-03-13 21:59:49 +00:00
|
|
|
|
|
|
|
if reserve > free_space:
|
2020-06-23 00:41:51 +00:00
|
|
|
raise NotEnoughSpace('Please leave more space')
|
2020-03-13 21:59:49 +00:00
|
|
|
|
|
|
|
def move(pattern, directory):
|
|
|
|
files = winglob.glob(pattern)
|
|
|
|
for file in files:
|
|
|
|
print(file)
|
|
|
|
shutil.move(file, directory)
|
|
|
|
|
2020-11-20 10:19:34 +00:00
|
|
|
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
|
|
|
|
|
2020-11-20 10:06:49 +00:00
|
|
|
def normalize_password(password):
|
|
|
|
if password is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if not isinstance(password, str):
|
|
|
|
raise TypeError(f'password must be a {str}, not {type(password)}')
|
|
|
|
|
|
|
|
if password == '':
|
|
|
|
return None
|
|
|
|
|
|
|
|
return password
|
|
|
|
|
|
|
|
def normalize_percentage(rec):
|
2020-03-13 21:59:49 +00:00
|
|
|
if rec is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if rec == 0:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if isinstance(rec, str):
|
|
|
|
rec = rec.strip('%')
|
|
|
|
|
|
|
|
rec = int(rec)
|
|
|
|
|
|
|
|
if not (0 <= rec <= 100):
|
|
|
|
raise ValueError(f'rec, rev, par {rec} must be 0-100.')
|
|
|
|
|
|
|
|
return rec
|
|
|
|
|
|
|
|
def _normalize_volume(volume, pathsize):
|
|
|
|
if volume is None:
|
|
|
|
return None
|
|
|
|
|
|
|
|
if isinstance(volume, int):
|
|
|
|
return volume
|
|
|
|
|
|
|
|
if isinstance(volume, float):
|
|
|
|
return int(volume)
|
|
|
|
|
|
|
|
if isinstance(volume, str):
|
|
|
|
volume = volume.strip()
|
|
|
|
|
|
|
|
if volume == '100%':
|
|
|
|
return None
|
|
|
|
|
|
|
|
minmax_parts = re.findall(r'(min|max)\((.+?), (.+?)\)', volume)
|
|
|
|
if minmax_parts:
|
|
|
|
(func, left, right) = minmax_parts[0]
|
|
|
|
func = {'min': min, 'max': max}[func]
|
|
|
|
left = _normalize_volume(left, pathsize=pathsize)
|
|
|
|
right = _normalize_volume(right, pathsize=pathsize)
|
|
|
|
return func(left, right)
|
|
|
|
|
|
|
|
if volume.endswith('%'):
|
|
|
|
volume = volume[:-1]
|
|
|
|
volume = float(volume) / 100
|
|
|
|
volume = (pathsize * volume) / bytestring.MIBIBYTE
|
|
|
|
volume = max(1, volume)
|
|
|
|
return int(volume)
|
|
|
|
|
|
|
|
return int(volume)
|
|
|
|
|
|
|
|
raise TypeError(f'Invalid volume {type(volume)}.')
|
|
|
|
|
|
|
|
def normalize_volume(volume, pathsize):
|
|
|
|
volume = _normalize_volume(volume, pathsize)
|
|
|
|
if volume is not None and volume < 1:
|
|
|
|
raise ValueError('Volume must be >= 1.')
|
|
|
|
return volume
|
|
|
|
|
|
|
|
def run_script(script, dry=False):
|
2020-06-25 05:26:27 +00:00
|
|
|
'''
|
|
|
|
`script` can be a list of strings, which are command line commands, or
|
|
|
|
callable Python functions. They will be run in order, and the sequence
|
|
|
|
will terminate if any step returns a bad status code. Your Python functions
|
|
|
|
must return either 0 or None to be considered successful, all other return
|
|
|
|
values will be considered failures.
|
|
|
|
'''
|
2020-03-13 21:59:49 +00:00
|
|
|
status = 0
|
|
|
|
|
2021-01-14 10:31:43 +00:00
|
|
|
for command in script:
|
|
|
|
if isinstance(command, str):
|
|
|
|
print(command)
|
|
|
|
elif isinstance(command, list):
|
|
|
|
subproctools.print_command(command)
|
|
|
|
else:
|
2020-03-13 21:59:49 +00:00
|
|
|
print(command)
|
|
|
|
|
2021-01-14 10:31:43 +00:00
|
|
|
if dry:
|
|
|
|
continue
|
|
|
|
|
2020-03-13 21:59:49 +00:00
|
|
|
if isinstance(command, str):
|
|
|
|
status = os.system(command)
|
2020-11-07 08:01:27 +00:00
|
|
|
elif isinstance(command, list):
|
|
|
|
# sys.stdout is None indicates pythonw.
|
|
|
|
creationflags = subprocess.CREATE_NO_WINDOW if sys.stdout is None else 0
|
|
|
|
status = subprocess.run(command, creationflags=creationflags).returncode
|
2020-03-13 21:59:49 +00:00
|
|
|
else:
|
|
|
|
status = command()
|
2020-06-25 05:26:27 +00:00
|
|
|
if status not in [0, None]:
|
2020-08-24 05:18:10 +00:00
|
|
|
print('!!!! error status:', status)
|
2020-03-13 21:59:49 +00:00
|
|
|
break
|
|
|
|
|
|
|
|
return status
|
|
|
|
|
|
|
|
def rarpar(
|
|
|
|
path,
|
|
|
|
*,
|
|
|
|
basename=None,
|
2020-10-23 14:52:57 +00:00
|
|
|
compression=None,
|
2020-11-20 10:19:34 +00:00
|
|
|
dictionary_size=None,
|
2020-03-13 21:59:49 +00:00
|
|
|
dry=False,
|
|
|
|
moveto=None,
|
|
|
|
par=None,
|
|
|
|
password=None,
|
2020-10-23 14:52:57 +00:00
|
|
|
rar_profile=None,
|
2020-06-25 05:27:12 +00:00
|
|
|
recycle_original=False,
|
2020-03-13 21:59:49 +00:00
|
|
|
rec=None,
|
|
|
|
rev=None,
|
2020-11-20 09:55:03 +00:00
|
|
|
solid=False,
|
2020-03-13 21:59:49 +00:00
|
|
|
volume=None,
|
|
|
|
workdir='.',
|
|
|
|
):
|
|
|
|
path = pathclass.Path(path)
|
|
|
|
|
2020-11-20 10:03:29 +00:00
|
|
|
# Validation ###################################################################################
|
|
|
|
|
2020-03-13 21:59:49 +00:00
|
|
|
path.assert_exists()
|
|
|
|
|
|
|
|
workdir = pathclass.Path(workdir)
|
|
|
|
workdir.assert_is_directory()
|
|
|
|
|
2020-11-20 10:03:29 +00:00
|
|
|
if moveto is not None:
|
2020-03-13 21:59:49 +00:00
|
|
|
moveto = pathclass.Path(moveto)
|
|
|
|
moveto.assert_is_directory()
|
|
|
|
|
2020-11-20 10:03:29 +00:00
|
|
|
if compression not in [None, 0, 1, 2, 3, 4, 5]:
|
|
|
|
raise ValueError(f'compression must be 0-5 or None, not {compression}.')
|
2020-03-13 21:59:49 +00:00
|
|
|
|
2020-11-20 10:19:34 +00:00
|
|
|
dictionary_size = normalize_dictionary_size(dictionary_size)
|
|
|
|
|
2020-11-20 09:55:03 +00:00
|
|
|
if type(solid) is not bool:
|
|
|
|
raise TypeError(f'solid must be True or False, not {solid}.')
|
|
|
|
|
2020-11-20 10:03:29 +00:00
|
|
|
password = normalize_password(password)
|
|
|
|
|
|
|
|
pathsize = path.size
|
2020-03-13 21:59:49 +00:00
|
|
|
volume = normalize_volume(volume, pathsize)
|
2020-11-20 10:06:49 +00:00
|
|
|
rec = normalize_percentage(rec)
|
|
|
|
rev = normalize_percentage(rev)
|
|
|
|
par = normalize_percentage(par)
|
2020-03-13 21:59:49 +00:00
|
|
|
|
|
|
|
if RESERVE_SPACE_ON_DRIVE:
|
|
|
|
assert_enough_space(
|
|
|
|
pathsize,
|
|
|
|
workdir=workdir,
|
|
|
|
moveto=moveto,
|
|
|
|
rec=rec or 0,
|
|
|
|
rev=rev or 0,
|
|
|
|
par=par or 0,
|
|
|
|
)
|
|
|
|
|
|
|
|
timestamp = time.strftime('%Y-%m-%d')
|
|
|
|
if not basename:
|
|
|
|
basename = f'{path.basename} ({timestamp})'
|
|
|
|
else:
|
|
|
|
basename = basename.format(timestamp=timestamp)
|
|
|
|
|
2020-11-07 07:50:45 +00:00
|
|
|
existing = None
|
|
|
|
if workdir:
|
|
|
|
existing = existing or workdir.glob(f'{basename}*.rar')
|
|
|
|
if moveto:
|
|
|
|
existing = existing or moveto.glob(f'{basename}*.rar')
|
|
|
|
|
2020-03-13 21:59:49 +00:00
|
|
|
if existing:
|
2020-11-06 08:20:20 +00:00
|
|
|
raise RarExists(f'{existing[0]} already exists.')
|
2020-03-13 21:59:49 +00:00
|
|
|
|
2020-11-20 10:03:29 +00:00
|
|
|
# Script building ##############################################################################
|
2020-03-13 21:59:49 +00:00
|
|
|
|
|
|
|
script = []
|
|
|
|
|
|
|
|
rarcommand = RARCOMMAND(
|
2020-08-24 05:17:50 +00:00
|
|
|
path=path,
|
2020-03-13 21:59:49 +00:00
|
|
|
basename=basename,
|
2020-10-23 14:52:57 +00:00
|
|
|
compression=compression,
|
2020-11-20 10:19:34 +00:00
|
|
|
dictionary_size=dictionary_size,
|
2020-03-13 21:59:49 +00:00
|
|
|
password=password,
|
2020-10-23 14:52:57 +00:00
|
|
|
profile=rar_profile,
|
2020-03-13 21:59:49 +00:00
|
|
|
rec=rec,
|
|
|
|
rev=rev,
|
2020-11-20 09:55:03 +00:00
|
|
|
solid=solid,
|
2020-03-13 21:59:49 +00:00
|
|
|
volume=volume,
|
|
|
|
workdir=workdir,
|
|
|
|
)
|
|
|
|
script.append(rarcommand)
|
|
|
|
|
|
|
|
if par:
|
|
|
|
parcommand = PARCOMMAND(
|
|
|
|
basename=basename,
|
|
|
|
par=par,
|
|
|
|
workdir=workdir,
|
|
|
|
)
|
|
|
|
script.append(parcommand)
|
|
|
|
|
|
|
|
def move_rars():
|
|
|
|
move(f'{workdir.absolute_path}\\{basename}*.rar', f'{moveto.absolute_path}')
|
|
|
|
def move_revs():
|
|
|
|
move(f'{workdir.absolute_path}\\{basename}*.rev', f'{moveto.absolute_path}')
|
|
|
|
def move_pars():
|
|
|
|
move(f'{workdir.absolute_path}\\{basename}*.par2', f'{moveto.absolute_path}')
|
|
|
|
|
|
|
|
if moveto:
|
|
|
|
if True:
|
|
|
|
script.append(move_rars)
|
|
|
|
if rev:
|
|
|
|
script.append(move_revs)
|
|
|
|
if par:
|
|
|
|
script.append(move_pars)
|
|
|
|
|
2020-06-25 05:27:12 +00:00
|
|
|
def recycle():
|
|
|
|
send2trash.send2trash(path.absolute_path)
|
|
|
|
|
|
|
|
if recycle_original:
|
|
|
|
script.append(recycle)
|
|
|
|
|
2020-03-13 21:59:49 +00:00
|
|
|
#### ####
|
|
|
|
|
|
|
|
status = run_script(script, dry)
|
|
|
|
|
|
|
|
return status
|
|
|
|
|
2020-10-13 05:06:09 +00:00
|
|
|
# COMMAND LINE #####################################################################################
|
2020-03-13 21:59:49 +00:00
|
|
|
|
|
|
|
DOCSTRING = '''
|
2020-10-13 04:59:02 +00:00
|
|
|
rarpar
|
|
|
|
======
|
|
|
|
|
|
|
|
> rarpar path <flags>
|
|
|
|
|
2020-03-13 21:59:49 +00:00
|
|
|
path:
|
|
|
|
The input file or directory to rarpar.
|
|
|
|
|
2020-10-13 04:59:02 +00:00
|
|
|
--volume X | X% | min(A, B) | max(A, B):
|
2020-03-13 21:59:49 +00:00
|
|
|
Split rars into volumes of this many megabytes. Should be
|
|
|
|
An integer number of megabytes, or;
|
|
|
|
A percentage "X%" to calculate volumes as X% of the file size, down to
|
|
|
|
a 1 MB minimum, or;
|
|
|
|
A string "min(A, B)" or "max(A, B)" where A and B follow the above rules.
|
|
|
|
|
2020-10-13 04:59:02 +00:00
|
|
|
--rec X:
|
2020-03-13 21:59:49 +00:00
|
|
|
A integer to generate X% recovery record in the rars.
|
|
|
|
See winrar documentation for information about recovery records.
|
|
|
|
|
2020-10-13 04:59:02 +00:00
|
|
|
--rev X:
|
2020-03-13 21:59:49 +00:00
|
|
|
A integer to generate X% recovery volumes.
|
|
|
|
Note that winrar's behavior is the number of revs will always be less than
|
|
|
|
the number of rars. If you don't split volumes, you will have 1 rar and
|
|
|
|
thus 0 revs even if you ask for 100% rev.
|
|
|
|
See winrar documentation for information about recovery volumes.
|
|
|
|
|
2020-10-13 04:59:02 +00:00
|
|
|
--par X:
|
2020-03-13 21:59:49 +00:00
|
|
|
A number to generate X% recovery with par2.
|
|
|
|
|
2020-10-13 04:59:02 +00:00
|
|
|
--basename X:
|
2020-03-13 21:59:49 +00:00
|
|
|
A basename for the rar and par files. You will end up with
|
|
|
|
basename.partXX.rar and basename.par2.
|
|
|
|
Without this argument, the default basename is "basename ({timestamp})".
|
|
|
|
Your string may include {timestamp} including the braces to get the
|
|
|
|
timestamp there.
|
|
|
|
|
2020-10-13 04:59:02 +00:00
|
|
|
--password X:
|
2020-03-13 21:59:49 +00:00
|
|
|
A password with which to encrypt the rar files.
|
|
|
|
|
2020-10-13 04:59:02 +00:00
|
|
|
--workdir X:
|
2020-03-13 21:59:49 +00:00
|
|
|
The directory in which the rars and pars will be generated while the
|
|
|
|
program is working.
|
|
|
|
|
2020-10-13 04:59:02 +00:00
|
|
|
--moveto X:
|
2020-03-13 21:59:49 +00:00
|
|
|
The directory to which the rars and pars will be moved after the program
|
|
|
|
has finished working.
|
|
|
|
|
2020-06-25 05:27:12 +00:00
|
|
|
--recycle:
|
|
|
|
The input file or directory will be recycled at the end.
|
|
|
|
|
2020-03-13 21:59:49 +00:00
|
|
|
--dry:
|
|
|
|
Print the commands that will be run, but don't actually run them.
|
|
|
|
'''
|
|
|
|
|
2020-10-13 05:06:09 +00:00
|
|
|
def rarpar_argparse(args):
|
|
|
|
return rarpar(
|
|
|
|
path=args.path,
|
|
|
|
volume=args.volume,
|
|
|
|
basename=args.basename,
|
2020-11-20 10:19:34 +00:00
|
|
|
dictionary_size=args.dictionary_size,
|
2020-10-13 05:06:09 +00:00
|
|
|
dry=args.dry,
|
|
|
|
moveto=args.moveto,
|
|
|
|
par=args.par,
|
|
|
|
password=args.password,
|
2020-10-23 14:52:57 +00:00
|
|
|
rar_profile=args.rar_profile,
|
2020-10-13 05:06:09 +00:00
|
|
|
rec=args.rec,
|
|
|
|
rev=args.rev,
|
|
|
|
recycle_original=args.recycle_original,
|
2020-11-20 09:55:03 +00:00
|
|
|
solid=args.solid,
|
2020-10-13 05:06:09 +00:00
|
|
|
workdir=args.workdir,
|
|
|
|
)
|
|
|
|
|
2020-03-13 21:59:49 +00:00
|
|
|
def main(argv):
|
2021-01-14 10:31:28 +00:00
|
|
|
argv = vlogging.set_level_by_argv(log, argv)
|
|
|
|
|
2020-03-13 21:59:49 +00:00
|
|
|
parser = argparse.ArgumentParser(description=__doc__)
|
|
|
|
|
|
|
|
parser.add_argument('path')
|
2021-02-21 05:01:55 +00:00
|
|
|
parser.add_argument('--volume')
|
|
|
|
parser.add_argument('--rec')
|
|
|
|
parser.add_argument('--rev')
|
|
|
|
parser.add_argument('--par')
|
|
|
|
parser.add_argument('--basename')
|
|
|
|
parser.add_argument('--password')
|
2020-10-23 14:52:57 +00:00
|
|
|
parser.add_argument('--profile', dest='rar_profile')
|
2021-02-21 05:01:55 +00:00
|
|
|
parser.add_argument('--workdir', default='.')
|
|
|
|
parser.add_argument('--moveto')
|
2020-06-25 05:27:12 +00:00
|
|
|
parser.add_argument('--recycle', dest='recycle_original', action='store_true')
|
2020-11-20 10:19:34 +00:00
|
|
|
parser.add_argument('--dictionary', dest='dictionary_size')
|
2021-02-21 05:01:55 +00:00
|
|
|
parser.add_argument('--solid', action='store_true')
|
|
|
|
parser.add_argument('--dry', action='store_true')
|
2020-03-13 21:59:49 +00:00
|
|
|
parser.set_defaults(func=rarpar_argparse)
|
|
|
|
|
|
|
|
return betterhelp.single_main(argv, parser, DOCSTRING)
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
raise SystemExit(main(sys.argv[1:]))
|