Skip to content

Commit

Permalink
accession - adds more args for greater automation,also more error han…
Browse files Browse the repository at this point in the history
…dling
  • Loading branch information
kieranjol committed Feb 5, 2018
1 parent 6041424 commit b8130c6
Showing 1 changed file with 35 additions and 5 deletions.
40 changes: 35 additions & 5 deletions accession.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,17 @@ def parse_args(args_):
parser.add_argument(
'source', help='Input directory'
)
parser.add_argument(
'-user',
help='Declare who you are. If this is not set, you will be prompted.')
parser.add_argument(
'-number',
help='Enter the Accession number for the representation.The parent Object Entry number will be replaced with this name.'
)
parser.add_argument(
'-force',
help='Renames OE with accession number without confirmation.', action='store_true'
)
parsed_args = parser.parse_args(args_)
return parsed_args
def main(args_):
Expand All @@ -36,18 +47,37 @@ def main(args_):
if uuid_directory is not None:
oe_path = os.path.dirname(uuid_directory)
oe_number = os.path.basename(oe_path)
user = ififuncs.get_user()
accession_number = ififuncs.get_accession_number()
if args.user:
user = args.user
else:
user = ififuncs.get_user()
if args.number:
if args.number[:3] != 'aaa':
print 'First three characters must be \'aaa\' and last four characters must be four digits'
accession_number = ififuncs.get_accession_number()
elif len(args.number[3:]) != 4:
accession_number = ififuncs.get_accession_number()
print 'First three characters must be \'aaa\' and last four characters must be four digits'
elif not args.number[3:].isdigit():
accession_number = ififuncs.get_accession_number()
print 'First three characters must be \'aaa\' and last four characters must be four digits'
else:
accession_number = args.number
else:
accession_number = ififuncs.get_accession_number()
accession_path = os.path.join(
os.path.dirname(oe_path), accession_number
)
uuid = os.path.basename(uuid_directory)
new_uuid_path = os.path.join(accession_path, uuid)
logs_dir = os.path.join(new_uuid_path, 'logs')
sipcreator_log = os.path.join(logs_dir, uuid) + '_sip_log.log'
proceed = ififuncs.ask_yes_no(
'Do you want to rename %s with %s' % (oe_number, accession_number)
)
if args.force:
proceed = 'Y'
else:
proceed = ififuncs.ask_yes_no(
'Do you want to rename %s with %s' % (oe_number, accession_number)
)
if proceed == 'Y':
os.rename(oe_path, accession_path)
ififuncs.generate_log(
Expand Down

0 comments on commit b8130c6

Please sign in to comment.