Skip to content

Commit

Permalink
also support symlinks
Browse files Browse the repository at this point in the history
  • Loading branch information
anarcat committed Nov 13, 2018
1 parent 22f20e6 commit 30a9442
Showing 1 changed file with 18 additions and 8 deletions.
26 changes: 18 additions & 8 deletions pywb/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,24 +108,27 @@ 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))

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)

Expand Down Expand Up @@ -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)

Expand Down

0 comments on commit 30a9442

Please sign in to comment.