Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: allow symlinkinkg and hardlinking files instead of just copying #409

Open
wants to merge 4 commits into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 25 additions & 4 deletions pywb/manager/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -108,17 +108,29 @@ 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):
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)
shutil.copy2(filename, self.archive_dir)
logging.info('%s %s to %s',
method.title(),
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)))
elif method == 'copy':
shutil.copy2(filename, self.archive_dir)
else:
raise NotImplementedError('unknown method name: %s' % method)
full_paths.append(os.path.join(self.archive_dir, filename))
logging.info('Copied ' + filename + ' to ' + self.archive_dir)

self._index_merge_warcs(full_paths, self.DEF_INDEX_FILE)

Expand Down Expand Up @@ -357,12 +369,21 @@ def do_list(r):
# Add Warcs
def do_add(r):
m = CollectionsManager(r.coll_name)
m.add_warcs(r.files)
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('--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)

# Reindex All
Expand Down