def main(): ''' Launches the other functions wihch attempt to run multiple copyit.py instances if manifests and matching sidecar directories are found inside of the input directory. ''' args = parse_args() all_files = find_manifest(args) processed_dirs = [] log_names = [] print '\n\n**** All of these folders will be copied to %s\n' % args.o for i in all_files: print i for i in all_files: absolute_path = os.path.join(args.o, os.path.basename(i)) if os.path.isdir(absolute_path): print('%s already exists, skipping') % (absolute_path) else: desktop_logs_dir = make_desktop_logs_dir() if args.l: log_name = copyit.main( ['-l', os.path.join(args.input, i), args.o] ) log_names.append(log_name) else: log_name = copyit.main( [os.path.join(args.input, i), args.o] ) log_names.append(log_name) processed_dirs.append(os.path.basename(os.path.join(args.input, i))) print '********\nWARNING - Please check the ifiscripts_logs directory on your Desktop to verify if ALL of your transfers were successful' analyze_reports(log_names, desktop_logs_dir)
def main(): ''' Launches the other functions wihch attempt to run multiple copyit.py instances if manifests and matching sidecar directories are found inside of the input directory. ''' args = parse_args() all_files = find_manifest(args) processed_dirs = [] log_names = [] print '\n\n**** All of these folders will be copied to %s\n' % args.o for i in all_files: print i for i in all_files: absolute_path = os.path.join(args.o, os.path.basename(i)) if os.path.isdir(absolute_path): print('%s already exists, skipping') % (absolute_path) else: desktop_logs_dir = make_desktop_logs_dir() if args.l: log_name = copyit.main( ['-l', os.path.join(args.input, i), args.o]) log_names.append(log_name) else: log_name = copyit.main([os.path.join(args.input, i), args.o]) log_names.append(log_name) processed_dirs.append(os.path.basename(os.path.join(args.input, i))) print '********\nWARNING - Please check the ifiscripts_logs directory on your Desktop to verify if ALL of your transfers were successful' analyze_reports(log_names, desktop_logs_dir)
def move_files(inputs, sip_path): ''' Runs moveit.py on all inputs ''' log_names = [] for item in inputs: log_name = copyit.main([item, os.path.join(sip_path, 'objects')]) log_names.append(log_name) consolidate_logs(log_names, sip_path) return log_names
def main(): ''' Launches functions ''' log_names = [] args = parse_args() desktop_logs_dir = ififuncs.make_desktop_logs_dir() for i in args.i: log_names.append(copyit.main([i, args.o])) print '********\nWARNING - Please check the ifiscripts_logs directory on your Desktop to verify if ALL of your transfers were successful' masscopy.analyze_reports(log_names, desktop_logs_dir)
def move_files(inputs, sip_path, args): ''' Runs moveit.py on all inputs ''' log_names = [] for item in inputs: cmd = [item, os.path.join(sip_path, 'objects')] if args.move: cmd.append('-move') log_name = copyit.main(cmd) log_names.append(log_name) consolidate_logs(log_names, sip_path) return log_names
def move_files(inputs, sip_path, args, user): ''' Runs moveit.py on all inputs ''' log_names = [] for item in inputs: cmd = [item, os.path.join(sip_path, 'objects')] if args.move: cmd.append('-move') if args.l: cmd.append('-l') log_name = copyit.main(cmd) log_names.append(log_name) if args.rename_uuid: if os.path.isfile(item): objects_dir = os.path.join(sip_path, 'objects') uuid = os.path.basename(sip_path) old_basename, ext = os.path.splitext(item) new_path = os.path.join(objects_dir, uuid + ext) os.rename(os.path.join(objects_dir, os.path.basename(item)), new_path) manifest = os.path.join( os.path.dirname(new_path), os.path.basename(item)) + '_manifest.md5' updated_lines = [] ififuncs.generate_log( log_name, 'EVENT = Filename change - eventDetail=original filename replaced with uuid, eventOutcomeDetailNote=%s replaced with %s, agentName=%s, agentName=sipcreator.py))' % (os.path.basename(item), uuid + ext, user)) with open(manifest, 'r') as file_object: checksums = file_object.readlines() for line in checksums: if os.path.basename(item) in line: line = line.replace(os.path.basename(item), os.path.basename(new_path)) updated_lines.append(line) with open(manifest, 'w') as fo: for lines in updated_lines: fo.write(lines) consolidate_logs(log_names, sip_path) return log_names
def main(args_): ''' Launch all the functions for creating an IFI SIP. ''' args = parse_args(args_) source = args.input sip_path = ififuncs.check_for_sip([source]) if sip_path is not None: oe_path = os.path.dirname(sip_path) uuid = os.path.basename(sip_path) sip_manifest = os.path.join(oe_path, uuid) + '_manifest.md5' start = datetime.datetime.now() print args if args.user: user = args.user else: user = ififuncs.get_user() new_log_textfile = os.path.join(sip_path, 'logs' + '/' + uuid + '_sip_log.log') ififuncs.generate_log(new_log_textfile, 'EVENT = package_update.py started') ififuncs.generate_log( new_log_textfile, 'eventDetail=package_update.py %s' % ififuncs.get_script_version('package_update.py')) ififuncs.generate_log(new_log_textfile, 'Command line arguments: %s' % args) ififuncs.generate_log(new_log_textfile, 'EVENT = agentName=%s' % user) if not os.path.isdir(args.new_folder): os.makedirs(args.new_folder) for filenames in args.i: if args.copy: for filename in filenames: copyit.main([filename, args.new_folder]) ififuncs.generate_log( new_log_textfile, 'EVENT = eventType=file movement,' ' eventOutcomeDetailNote=%s has been moved into %s' ' agentName=copyit.py' % (filename, args.new_folder)) # this is hardcoded - pick this apart so that any folder can be added to. sipcreator.consolidate_manifests(sip_path, 'metadata/supplemental', new_log_textfile) log_manifest = os.path.join( os.path.dirname(new_log_textfile), os.path.basename(filename) + '_manifest.md5') ififuncs.manifest_update(sip_manifest, log_manifest) ififuncs.sort_manifest(sip_manifest) else: # add test to see if it actually deleted - what if read only? shutil.move(filename, args.new_folder) ififuncs.generate_log( new_log_textfile, 'EVENT = eventType=file movement,' ' eventOutcomeDetailNote=%s has been moved into %s' ' agentName=shutil.move()' % (filename, args.new_folder)) print '%s has been moved into %s' % (filename, args.new_folder) relative_filename = filename.replace(args.input + '/', '') relative_new_folder = args.new_folder.replace(args.input + '/', '') update_manifest( sip_manifest, relative_filename, os.path.join(relative_new_folder, os.path.basename(relative_filename)), new_log_textfile) ififuncs.generate_log(new_log_textfile, 'EVENT = package_update.py finished') ififuncs.checksum_replace(sip_manifest, new_log_textfile, 'md5') finish = datetime.datetime.now() print '\n', user, 'ran this script at %s and it finished at %s' % (start, finish)
def main(args_): ''' Launch all the functions for creating an IFI SIP. ''' args = parse_args(args_) source = args.input sip_path = ififuncs.check_for_sip([source]) if sip_path is not None: oe_path = os.path.dirname(sip_path) uuid = os.path.basename(sip_path) sip_manifest = os.path.join(oe_path, uuid) + '_manifest.md5' else: # this is assuming that the other workflow will be the # special collections workflow that has the uuid as the parent. # some real checks should exist for this whole if/else flow. sip_path = args.input oe_path = os.path.dirname(args.input) uuid = os.path.basename(sip_path) sip_manifest = os.path.join(oe_path, uuid + '_manifest.md5') start = datetime.datetime.now() print(args) if args.user: user = args.user else: user = ififuncs.get_user() new_log_textfile = os.path.join(sip_path, 'logs' + '/' + uuid + '_sip_log.log') ififuncs.generate_log(new_log_textfile, 'EVENT = package_update.py started') ififuncs.generate_log( new_log_textfile, 'eventDetail=package_update.py %s' % ififuncs.get_script_version('package_update.py')) ififuncs.generate_log(new_log_textfile, 'Command line arguments: %s' % args) ififuncs.generate_log(new_log_textfile, 'EVENT = agentName=%s' % user) if not os.path.isdir(args.new_folder): os.makedirs(args.new_folder) if isinstance(args.i[0], (list, )): args.i = args.i[0] for filenames in args.i: if args.copy: copyit.main([filenames, args.new_folder]) ififuncs.generate_log( new_log_textfile, 'EVENT = eventType=file movement,' ' eventOutcomeDetailNote=%s has been moved into %s' ' agentName=copyit.py' % (filenames, args.new_folder)) # this is hardcoded - pick this apart so that any folder can be added to. # this must be fixed in normalise.py as well. relative_new_path = args.new_folder.replace(sip_path, '') print((relative_new_path, 'relative')) if (relative_new_path[0] == '/') or relative_new_path[0] == '\\': relative_new_path = relative_new_path[1:].replace('\\', '/') sipcreator.consolidate_manifests(sip_path, relative_new_path, new_log_textfile) log_manifest = os.path.join( os.path.dirname(new_log_textfile), os.path.basename(filenames) + '_manifest.md5') ififuncs.manifest_update(sip_manifest, log_manifest) ififuncs.sort_manifest(sip_manifest) else: # add test to see if it actually deleted - what if read only? shutil.move(filenames, args.new_folder) ififuncs.generate_log( new_log_textfile, 'EVENT = eventType=file movement,' ' eventOutcomeDetailNote=%s has been moved into %s' ' agentName=shutil.move()' % (filenames, args.new_folder)) print(('%s has been moved into %s' % (filenames, args.new_folder))) relative_filename = filenames.replace( os.path.dirname(args.input) + '/', '').replace('\\', '/') relative_filename = filenames.replace( os.path.dirname(args.input) + '\\', '').replace('\\', '/') relative_new_folder = args.new_folder.replace( os.path.dirname(args.input) + '/', '').replace('\\', '/') relative_new_folder = args.new_folder.replace( os.path.dirname(args.input) + '\\', '').replace('\\', '/') update_manifest( sip_manifest, relative_filename, os.path.join(relative_new_folder, os.path.basename(relative_filename)).replace( '\\', '/'), new_log_textfile) ififuncs.generate_log(new_log_textfile, 'EVENT = package_update.py finished') ififuncs.checksum_replace(sip_manifest, new_log_textfile, 'md5') finish = datetime.datetime.now() print('\n- %s ran this script at %s and it finished at %s' % (user, start, finish))