|
15 | 15 | # begin: argument parsing |
16 | 16 | parser = argparse.ArgumentParser() |
17 | 17 |
|
18 | | -parser.add_argument("-v", "--verbose", action="store_true", |
19 | | - help="increase output verbosity") |
| 18 | +parser.add_argument('-v', '--verbose', action='store_true', |
| 19 | + help='increase output verbosity') |
20 | 20 |
|
21 | | -parser.add_argument("-i", "--handle", |
22 | | - help="handle of the object to retreive. optional - if not provided, the script will ask for input") |
| 21 | +parser.add_argument('-i', '--handle', |
| 22 | + help='handle of the object to retreive. optional - if not provided, the script will ask for input') |
23 | 23 |
|
24 | 24 | # bitstream formats: |
25 | 25 | # REM: set number of args |
|
28 | 28 | # '?' == 0 or 1. |
29 | 29 | # An int is an explicit number of arguments to accept. |
30 | 30 | parser.add_argument('-f', '--formats', nargs='*', |
31 | | - help="optional list of bitstream formats. will return all formats if not provided") |
| 31 | + help='optional list of bitstream formats. will return all formats if not provided') |
32 | 32 |
|
33 | | -parser.add_argument("-dl", "--download", action="store_true", |
34 | | - help="download bitstreams (rather than just retreive metadata about them). default: false") |
| 33 | +parser.add_argument('-dl', '--download', action='store_true', |
| 34 | + help='download bitstreams (rather than just retreive metadata about them). default: false') |
35 | 35 |
|
36 | | -parser.add_argument("-rt", "--rtimeout", type=int, |
37 | | - help="response timeout - number of seconds to wait for a response. not a timeout for a download or run of the entire script. default: " + str(response_timeout)) |
| 36 | +parser.add_argument('-rt', '--rtimeout', type=int, |
| 37 | + help='response timeout - number of seconds to wait for a response. not a timeout for a download or run of the entire script. default: ' + str(response_timeout)) |
38 | 38 |
|
39 | | -parser.add_argument("-l", "--limit", type=int, |
40 | | - help="limit to the number of objects to return in a given request. default = " + str(limit)) |
| 39 | +parser.add_argument('-l', '--limit', type=int, |
| 40 | + help='limit to the number of objects to return in a given request. default = ' + str(limit)) |
41 | 41 |
|
42 | 42 | args = parser.parse_args() |
43 | 43 |
|
|
48 | 48 | limit = args.limit |
49 | 49 |
|
50 | 50 | if args.verbose: |
51 | | - print "verbosity turned on" |
| 51 | + print('verbosity turned on') |
52 | 52 |
|
53 | 53 | if args.handle: |
54 | | - print("retreiving object with handle {}").format(args.handle) |
| 54 | + print('retreiving object with handle {}').format(args.handle) |
55 | 55 |
|
56 | 56 | if args.formats: |
57 | | - print('filtering results to the following bitstream formats: %s' % str(args.formats)) |
| 57 | + print('filtering results to the following bitstream formats: {}').format(args.formats) |
58 | 58 | else: |
59 | | - print 'returning bitstreams of any format' |
| 59 | + print('returning bitstreams of any format') |
60 | 60 |
|
61 | 61 | if args.download: |
62 | | - print "downloading bitstreams" |
| 62 | + print('downloading bitstreams') |
63 | 63 |
|
64 | 64 | if args.rtimeout: |
65 | | - print 'response_timeout set to ' + str(response_timeout) |
| 65 | + print('response_timeout set to {}').format(response_timeout) |
66 | 66 |
|
67 | 67 | # end: argument parsing |
68 | 68 |
|
|
72 | 72 | if secretsVersion != '': |
73 | 73 | try: |
74 | 74 | secrets = __import__(secretsVersion) |
75 | | - print 'Editing Production' |
| 75 | + print('Accessing Production') |
76 | 76 | except ImportError: |
77 | | - print 'Editing Stage' |
| 77 | + print('Accessing Stage') |
78 | 78 | else: |
79 | | - print 'Editing Stage' |
| 79 | + print('Accessing Stage') |
80 | 80 |
|
81 | 81 | baseURL = secrets.baseURL |
82 | 82 | email = secrets.email |
|
136 | 136 | f.writerow([fileName]+[itemHandle]) |
137 | 137 |
|
138 | 138 | elif dsObject['type'] == 'item': |
139 | | - if args.verbose: print dsObject['type'] |
| 139 | + if args.verbose: print(dsObject['type']) |
140 | 140 |
|
141 | 141 | itemHandle = dsObject['handle'] |
142 | 142 |
|
|
157 | 157 | bitstreams = bitstreams.json() |
158 | 158 | for bitstream in bitstreams: |
159 | 159 | if args.formats and bitstream['format'] in args.formats or not args.formats: |
160 | | - if args.verbose: print bitstream |
| 160 | + if args.verbose: print(bitstream) |
161 | 161 | sequenceId = str(bitstream['sequenceId']) |
162 | 162 | fileName = bitstream['name'] |
163 | 163 | fileFormat = bitstream['format'] |
|
172 | 172 | for dlBitstream in dlBitstreams: |
173 | 173 | response = requests.get(baseURL + str(dlBitstream['retrieveLink']), headers=header, cookies=cookies, verify=verify, timeout=response_timeout) |
174 | 174 | response.raise_for_status() # ensure we notice bad responses |
175 | | - file = open(filePath + dlBitstream['name'], "wb") |
| 175 | + file = open(filePath + dlBitstream['name'], 'wb') |
176 | 176 | file.write(response.content) |
177 | 177 | file.close() |
178 | 178 | else: |
179 | | - print 'object is of an invalid type for this script (' + dsObject['type'] + '). please enter the handle of an item or a collection.' |
| 179 | + print('object is of an invalid type for this script ({}). please enter the handle of an item or a collection.').format(dsObject['type']) |
180 | 180 |
|
181 | 181 |
|
182 | 182 | logout = requests.post(baseURL+'/rest/logout', headers=header, cookies=cookies, verify=verify, timeout=response_timeout) |
183 | 183 |
|
184 | 184 | elapsedTime = time.time() - startTime |
185 | 185 | m, s = divmod(elapsedTime, 60) |
186 | 186 | h, m = divmod(m, 60) |
187 | | -print 'Total script run time: ', '%d:%02d:%02d' % (h, m, s) |
| 187 | +print('Total script run time: {:01.0f}:{:02.0f}:{:02.0f}').format(h, m, s) |
0 commit comments