From 30a944256824eefed9428fd4193b492345bc4f36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Antoine=20Beaupr=C3=A9?= Date: Mon, 12 Nov 2018 21:33:55 -0500 Subject: [PATCH] also support symlinks --- pywb/manager/manager.py | 26 ++++++++++++++++++-------- 1 file changed, 18 insertions(+), 8 deletions(-) diff --git a/pywb/manager/manager.py b/pywb/manager/manager.py index 98fcd6c15..9def696b6 100644 --- a/pywb/manager/manager.py +++ b/pywb/manager/manager.py @@ -108,7 +108,7 @@ def _assert_coll_exists(self): 'To create a new collection, run\n\n{1} init {0}') raise IOError(msg.format(self.coll_name, sys.argv[0])) - def add_warcs(self, warcs, hardlink=False): + def add_warcs(self, warcs, method='copy'): if not os.path.isdir(self.archive_dir): raise IOError('Directory {0} does not exist'. format(self.archive_dir)) @@ -116,16 +116,19 @@ def add_warcs(self, warcs, hardlink=False): full_paths = [] for filename in warcs: filename = os.path.abspath(filename) - if hardlink: + logging.info('%s %s to %s', + method, + filename, + self.archive_dir) + if method == 'hardlink': os.link(filename, os.path.join(self.archive_dir, os.path.basename(filename))) + elif method == 'symlink': + os.symlink(filename, os.path.join(self.archive_dir, + os.path.basename(filename))) else: shutil.copy2(filename, self.archive_dir) full_paths.append(os.path.join(self.archive_dir, filename)) - logging.info('%s %s to %s', - hardlink and 'Linked' or 'Copied', - filename, - self.archive_dir) self._index_merge_warcs(full_paths, self.DEF_INDEX_FILE) @@ -364,13 +367,20 @@ def do_list(r): # Add Warcs def do_add(r): m = CollectionsManager(r.coll_name) - m.add_warcs(r.files, r.hardlink) + m.add_warcs(r.files, r.method) addwarc_help = 'Copy ARCS/WARCS to collection directory and reindex' addwarc = subparsers.add_parser('add', help=addwarc_help) addwarc.add_argument('coll_name') addwarc.add_argument('files', nargs='+') - addwarc.add_argument('--hardlink', '-l', action='store_true', + addwarc.add_argument('--method', '-m', default='copy', + help='import method (default: %(default)s)', + choices=('copy', 'symlink', 'hardlink')) + addwarc.add_argument('--symlink', '-s', action='store_const', + dest='method', const='symlink', + help='symlink files into storage instead of copying') + addwarc.add_argument('--hardlink', '-l', action='store_const', + dest='method', const='hardlink', help='hardlink files into storage instead of copying') addwarc.set_defaults(func=do_add)