Skip to content

Commit b8130c6

Browse files
committed
accession - adds more args for greater automation,also more error handling
1 parent 6041424 commit b8130c6

File tree

1 file changed

+35
-5
lines changed

1 file changed

+35
-5
lines changed

accession.py

Lines changed: 35 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,17 @@ def parse_args(args_):
2424
parser.add_argument(
2525
'source', help='Input directory'
2626
)
27+
parser.add_argument(
28+
'-user',
29+
help='Declare who you are. If this is not set, you will be prompted.')
30+
parser.add_argument(
31+
'-number',
32+
help='Enter the Accession number for the representation.The parent Object Entry number will be replaced with this name.'
33+
)
34+
parser.add_argument(
35+
'-force',
36+
help='Renames OE with accession number without confirmation.', action='store_true'
37+
)
2738
parsed_args = parser.parse_args(args_)
2839
return parsed_args
2940
def main(args_):
@@ -36,18 +47,37 @@ def main(args_):
3647
if uuid_directory is not None:
3748
oe_path = os.path.dirname(uuid_directory)
3849
oe_number = os.path.basename(oe_path)
39-
user = ififuncs.get_user()
40-
accession_number = ififuncs.get_accession_number()
50+
if args.user:
51+
user = args.user
52+
else:
53+
user = ififuncs.get_user()
54+
if args.number:
55+
if args.number[:3] != 'aaa':
56+
print 'First three characters must be \'aaa\' and last four characters must be four digits'
57+
accession_number = ififuncs.get_accession_number()
58+
elif len(args.number[3:]) != 4:
59+
accession_number = ififuncs.get_accession_number()
60+
print 'First three characters must be \'aaa\' and last four characters must be four digits'
61+
elif not args.number[3:].isdigit():
62+
accession_number = ififuncs.get_accession_number()
63+
print 'First three characters must be \'aaa\' and last four characters must be four digits'
64+
else:
65+
accession_number = args.number
66+
else:
67+
accession_number = ififuncs.get_accession_number()
4168
accession_path = os.path.join(
4269
os.path.dirname(oe_path), accession_number
4370
)
4471
uuid = os.path.basename(uuid_directory)
4572
new_uuid_path = os.path.join(accession_path, uuid)
4673
logs_dir = os.path.join(new_uuid_path, 'logs')
4774
sipcreator_log = os.path.join(logs_dir, uuid) + '_sip_log.log'
48-
proceed = ififuncs.ask_yes_no(
49-
'Do you want to rename %s with %s' % (oe_number, accession_number)
50-
)
75+
if args.force:
76+
proceed = 'Y'
77+
else:
78+
proceed = ififuncs.ask_yes_no(
79+
'Do you want to rename %s with %s' % (oe_number, accession_number)
80+
)
5181
if proceed == 'Y':
5282
os.rename(oe_path, accession_path)
5383
ififuncs.generate_log(

0 commit comments

Comments
 (0)