Merge pull request #198 from vbanos/subdir-prefix

New option --subdir-prefix
This commit is contained in:
Barbara Miller 2024-06-04 11:46:07 -07:00 committed by GitHub
commit f7d4286b54
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 6 additions and 1 deletions

View File

@ -91,6 +91,8 @@ def _build_arg_parser(prog='warcprox', show_hidden=False):
help='where to store and load generated certificates')
arg_parser.add_argument('-d', '--dir', dest='directory',
default='./warcs', help='where to write warcs')
arg_parser.add_argument('--subdir-prefix', dest='subdir_prefix', action='store_true',
help='write warcs to --dir subdir equal to the current warc-prefix'),
arg_parser.add_argument('--warc-filename', dest='warc_filename',
default='{prefix}-{timestamp17}-{serialno}-{randomtoken}',
help='define custom WARC filename with variables {prefix}, {timestamp14}, {timestamp17}, {serialno}, {randomtoken}, {hostname}, {shorthostname}, {port}')

View File

@ -55,7 +55,10 @@ class WarcWriter:
self.open_suffix = '' if options.no_warc_open_suffix else '.open'
self.rollover_size = options.rollover_size or 1000000000
self.rollover_idle_time = options.rollover_idle_time or None
self.directory = options.directory or './warcs'
if options.subdir_prefix and options.prefix:
self.directory = os.path.sep.join([options.directory, options.prefix]) or './warcs'
else:
self.directory = options.directory or './warcs'
self.filename_template = options.warc_filename or \
'{prefix}-{timestamp17}-{randomtoken}-{serialno}'
self.last_activity = time.time()