Skip to content

Commit 6d9122e

Browse files
anarcatanarcat
authored andcommitted
also support symlinks
1 parent 22f20e6 commit 6d9122e

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

pywb/manager/manager.py

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -108,24 +108,27 @@ def _assert_coll_exists(self):
108108
'To create a new collection, run\n\n{1} init {0}')
109109
raise IOError(msg.format(self.coll_name, sys.argv[0]))
110110

111-
def add_warcs(self, warcs, hardlink=False):
111+
def add_warcs(self, warcs, method='copy'):
112112
if not os.path.isdir(self.archive_dir):
113113
raise IOError('Directory {0} does not exist'.
114114
format(self.archive_dir))
115115

116116
full_paths = []
117117
for filename in warcs:
118118
filename = os.path.abspath(filename)
119-
if hardlink:
119+
logging.info('%s %s to %s',
120+
method,
121+
filename,
122+
self.archive_dir)
123+
if method == 'hardlink':
120124
os.link(filename, os.path.join(self.archive_dir,
121125
os.path.basename(filename)))
126+
elif method == 'symlink':
127+
os.symlink(filename, os.path.join(self.archive_dir,
128+
os.path.basename(filename)))
122129
else:
123130
shutil.copy2(filename, self.archive_dir)
124131
full_paths.append(os.path.join(self.archive_dir, filename))
125-
logging.info('%s %s to %s',
126-
hardlink and 'Linked' or 'Copied',
127-
filename,
128-
self.archive_dir)
129132

130133
self._index_merge_warcs(full_paths, self.DEF_INDEX_FILE)
131134

@@ -364,13 +367,20 @@ def do_list(r):
364367
# Add Warcs
365368
def do_add(r):
366369
m = CollectionsManager(r.coll_name)
367-
m.add_warcs(r.files, r.hardlink)
370+
m.add_warcs(r.files, r.method)
368371

369372
addwarc_help = 'Copy ARCS/WARCS to collection directory and reindex'
370373
addwarc = subparsers.add_parser('add', help=addwarc_help)
371374
addwarc.add_argument('coll_name')
372375
addwarc.add_argument('files', nargs='+')
373-
addwarc.add_argument('--hardlink', '-l', action='store_true',
376+
addwarc.add_argument('--method', '-m', default='copy',
377+
help='import method (default: %(default)s)',
378+
choices=('copy', 'symlink', 'hardlink'))
379+
addwarc.add_argument('--symlink', '-s', action='store_const',
380+
dest='method', const='symlink',
381+
help='symlink files into storage instead of copying')
382+
addwarc.add_argument('--hardlink', '-l', action='store_const',
383+
dest='method', const='hardlink',
374384
help='hardlink files into storage instead of copying')
375385
addwarc.set_defaults(func=do_add)
376386

0 commit comments

Comments
 (0)