Skip to content
Snippets Groups Projects
Commit fcddf624 authored by Kevin S. Hahn's avatar Kevin S. Hahn
Browse files

adds option to keep data from bootstrap sort

- uses shutil.copy instead of shutil.move
parent 93231d60
No related branches found
No related tags found
No related merge requests found
......@@ -120,7 +120,7 @@ def sort(args):
with open(filepath, 'rb') as fd:
for chunk in iter(lambda: fd.read(1048577 * hash_.block_size), ''):
hash_.update(chunk)
status, detail = util.insert_file(db.acquisitions, None, None, filepath, hash_.hexdigest(), data_path, quarantine_path)
status, detail = util.insert_file(db.acquisitions, None, None, filepath, hash_.hexdigest(), data_path, quarantine_path, args.keep)
if status != 200:
print detail
......@@ -221,6 +221,7 @@ sort_parser = subparsers.add_parser(
formatter_class=argparse.RawDescriptionHelpFormatter,
)
sort_parser.add_argument('-q', '--quick', action='store_true', help='omit computing of file checksums')
sort_parser.add_argument('-k', '--keep', action='store_true', help='do not remove the files after sorting')
sort_parser.add_argument('db_uri', help='database URI')
sort_parser.add_argument('path', help='filesystem path to data')
sort_parser.add_argument('sort_path', help='filesystem path to sorted data')
......@@ -236,6 +237,7 @@ dbinitsort_parser.add_argument('db_uri', help='database URI')
dbinitsort_parser.add_argument('path', help='filesystem path to data')
dbinitsort_parser.add_argument('sort_path', help='filesystem path to sorted data')
dbinitsort_parser.add_argument('-q', '--quick', action='store_true', help='omit computing of file checksums')
dbinitsort_parser.add_argument('-k', '--keep', action='store_true', help='do not remove the files after sorting')
dbinitsort_parser.add_argument('-j', '--json', help='JSON file container users and groups')
dbinitsort_parser.add_argument('-f', '--force', action='store_true', help='wipe out any existing db data')
dbinitsort_parser.set_defaults(func=dbinitsort)
......
......@@ -15,7 +15,7 @@ import scitran.data
PROJECTION_FIELDS = ['timestamp', 'permissions', 'public']
def insert_file(dbc, _id, file_info, filepath, digest, data_path, quarantine_path):
def insert_file(dbc, _id, file_info, filepath, digest, data_path, quarantine_path, keep=False):
filename = os.path.basename(filepath)
if _id is None:
try:
......@@ -62,7 +62,10 @@ def insert_file(dbc, _id, file_info, filepath, digest, data_path, quarantine_pat
success = dbc.update(file_spec, {'$set': {'files.$': file_info}})
if not success['updatedExisting']:
dbc.update({'_id': _id}, {'$push': {'files': file_info}})
shutil.move(filepath, container_path + '/' + filename)
if not keep:
shutil.move(filepath, container_path + '/' + filename)
else:
shutil.copy(filepath, container_path + '/' + filename)
log.debug('Done %s' % os.path.basename(filepath)) # must use filepath, since filename is updated for sorted files
return 200, 'Success'
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment