Skip to content

Commit 767e97f

Browse files
authored
Merge pull request #3 from MITLibraries/instanceSelect
Instance select and unit tests
2 parents c91ff4f + 38ae325 commit 767e97f

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+417
-795
lines changed

README.md

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,9 +12,8 @@ All of these scripts require a secrets.py file in the same directory that must c
1212
1313
password='my_dspace_password'
1414
filePath = '/Users/dspace_user/dspace-data-collection/data/'
15-
handlePrefix = 'http://dspace.myuni.edu/handle/'
1615
verify = True or False (no quotes). Use False if using an SSH tunnel to connect to the DSpace API
17-
skippedCollections = A list of the 'uuid' of any collections that you wish the script to skip. (e.g. ['45794375-6640-4efe-848e-082e60bae375'])
16+
skipColl = A list of the 'uuid' of any collections that you wish the script to skip. (e.g. ['45794375-6640-4efe-848e-082e60bae375'])
1817
```
1918
The 'filePath' is directory into which output files will be written and 'handlePrefix' may or may not vary from your DSpace URL depending on your configuration. This secrets.py file will be ignored according to the repository's .gitignore file so that DSpace login details will not be inadvertently exposed through GitHub.
2019

addKeyValuePairOnHandleCSV.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,27 +6,17 @@
66
import urllib3
77
import dsFunc
88

9-
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
10-
11-
secretsVersion = input('To edit production server, enter the name of the \
12-
secrets file: ')
13-
if secretsVersion != '':
14-
try:
15-
secrets = __import__(secretsVersion)
16-
print('Editing Production')
17-
except ImportError:
18-
secrets = __import__('secrets')
19-
print('Editing Development')
20-
else:
21-
secrets = __import__('secrets')
22-
print('Editing Development')
9+
inst = input('To edit production server, enter the name of the secrets file: ')
10+
secrets = dsFunc.instSelect(inst)
2311

2412
baseURL = secrets.baseURL
2513
email = secrets.email
2614
password = secrets.password
2715
filePath = secrets.filePath
2816
verify = secrets.verify
29-
skippedCollections = secrets.skippedCollections
17+
skipColl = secrets.skipColl
18+
19+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
3020

3121
startTime = time.time()
3222
data = {'email': email, 'password': password}

addKeyValuePairToCollection.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77
import argparse
88
import dsFunc
99

10-
secretsVersion = input('To edit production server, enter the name of the \
11-
secrets file: ')
12-
if secretsVersion != '':
13-
try:
14-
secrets = __import__(secretsVersion)
15-
print('Editing Production')
16-
except ImportError:
17-
secrets = __import__('secrets')
18-
print('Editing Development')
19-
else:
20-
secrets = __import__('secrets')
21-
print('Editing Development')
10+
inst = input('To edit production server, enter the name of the secrets file: ')
11+
secrets = dsFunc.instSelect(inst)
12+
13+
baseURL = secrets.baseURL
14+
email = secrets.email
15+
password = secrets.password
16+
filePath = secrets.filePath
17+
verify = secrets.verify
18+
skipColl = secrets.skipColl
2219

2320
parser = argparse.ArgumentParser()
2421
parser.add_argument('-k', '--key', help='the key to be added. optional - if \
@@ -50,13 +47,6 @@
5047

5148
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
5249

53-
baseURL = secrets.baseURL
54-
email = secrets.email
55-
password = secrets.password
56-
filePath = secrets.filePath
57-
verify = secrets.verify
58-
skippedCollections = secrets.skippedCollections
59-
6050
startTime = time.time()
6151
data = {'email': email, 'password': password}
6252
header = {'content-type': 'application/json', 'accept': 'application/json'}
@@ -91,7 +81,7 @@
9181
itemID = items[k]['uuid']
9282
itemList.append(itemID)
9383
offset = offset + 200
94-
84+
9585
dsFunc.elapsedTime(startTime, 'Item list creation time')
9686

9787
recordsEdited = 0

addKeyValuePairToCommunity.py

Lines changed: 11 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77
import argparse
88
import dsFunc
99

10-
secretsVersion = input('To edit production server, enter the name of the \
11-
secrets file: ')
12-
if secretsVersion != '':
13-
try:
14-
secrets = __import__(secretsVersion)
15-
print('Editing Production')
16-
except ImportError:
17-
secrets = __import__('secrets')
18-
print('Editing Development')
19-
else:
20-
secrets = __import__('secrets')
21-
print('Editing Development')
10+
inst = input('To edit production server, enter the name of the secrets file: ')
11+
secrets = dsFunc.instSelect(inst)
12+
13+
baseURL = secrets.baseURL
14+
email = secrets.email
15+
password = secrets.password
16+
filePath = secrets.filePath
17+
verify = secrets.verify
18+
skipColl = secrets.skipColl
2219

2320
parser = argparse.ArgumentParser()
2421
parser.add_argument('-k', '--key', help='the key to be added. optional - if \
@@ -50,13 +47,6 @@
5047

5148
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
5249

53-
baseURL = secrets.baseURL
54-
email = secrets.email
55-
password = secrets.password
56-
filePath = secrets.filePath
57-
verify = secrets.verify
58-
skippedCollections = secrets.skippedCollections
59-
6050
startTime = time.time()
6151
data = {'email': email, 'password': password}
6252
header = {'content-type': 'application/json', 'accept': 'application/json'}
@@ -81,7 +71,7 @@
8171
verify=verify).json()
8272
for j in range(0, len(collections)):
8373
collectionID = collections[j]['uuid']
84-
if collectionID not in skippedCollections:
74+
if collectionID not in skipColl:
8575
offset = 0
8676
items = ''
8777
while items != []:
@@ -102,7 +92,7 @@
10292
itemID = items[k]['uuid']
10393
itemList.append(itemID)
10494
offset = offset + 200
105-
95+
10696
dsFunc.elapsedTime(startTime, 'Item list creation time')
10797

10898
recordsEdited = 0

addNewItemsToCollection.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,15 @@
99
import argparse
1010
import dsFunc
1111

12-
secretsVersion = input('To edit production server, enter the name of the \
13-
secrets file: ')
14-
if secretsVersion != '':
15-
try:
16-
secrets = __import__(secretsVersion)
17-
print('Editing Production')
18-
except ImportError:
19-
secrets = __import__('secrets')
20-
print('Editing Development')
21-
else:
22-
secrets = __import__('secrets')
23-
print('Editing Development')
12+
inst = input('To edit production server, enter the name of the secrets file: ')
13+
secrets = dsFunc.instSelect(inst)
14+
15+
baseURL = secrets.baseURL
16+
email = secrets.email
17+
password = secrets.password
18+
filePath = secrets.filePath
19+
verify = secrets.verify
20+
skipColl = secrets.skipColl
2421

2522
parser = argparse.ArgumentParser()
2623
parser.add_argument('-d', '--directory', help='the directory of files to be \
@@ -46,13 +43,6 @@
4643

4744
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
4845

49-
baseURL = secrets.baseURL
50-
email = secrets.email
51-
password = secrets.password
52-
filePath = secrets.filePath
53-
verify = secrets.verify
54-
skippedCollections = secrets.skippedCollections
55-
5646
startTime = time.time()
5747

5848
# ccreate file list and export csv

compareTwoKeysInCommunity.py

Lines changed: 10 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,15 @@
55
import argparse
66
import dsFunc
77

8-
secretsVersion = input('To edit production server, enter the name of the \
9-
secrets file: ')
10-
if secretsVersion != '':
11-
try:
12-
secrets = __import__(secretsVersion)
13-
print('Editing Production')
14-
except ImportError:
15-
secrets = __import__('secrets')
16-
print('Editing Development')
17-
else:
18-
secrets = __import__('secrets')
19-
print('Editing Development')
8+
inst = input('To edit production server, enter the name of the secrets file: ')
9+
secrets = dsFunc.instSelect(inst)
10+
11+
baseURL = secrets.baseURL
12+
email = secrets.email
13+
password = secrets.password
14+
filePath = secrets.filePath
15+
verify = secrets.verify
16+
skipColl = secrets.skipColl
2017

2118
parser = argparse.ArgumentParser()
2219
parser.add_argument('-1', '--key', help='the first key to be output. \
@@ -42,13 +39,6 @@
4239

4340
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
4441

45-
baseURL = secrets.baseURL
46-
email = secrets.email
47-
password = secrets.password
48-
filePath = secrets.filePath
49-
verify = secrets.verify
50-
skippedCollections = secrets.skippedCollections
51-
5242
startTime = time.time()
5343
data = {'email': email, 'password': password}
5444
header = {'content-type': 'application/json', 'accept': 'application/json'}
@@ -75,7 +65,7 @@
7565
for j in range(0, len(collections)):
7666
collectionID = collections[j]['uuid']
7767
print(collectionID)
78-
if collectionID not in skippedCollections:
68+
if collectionID not in skipColl:
7969
offset = 0
8070
items = ''
8171
while items != []:

countInitialedNamesByCollection.py

Lines changed: 6 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -5,27 +5,17 @@
55
import urllib3
66
import dsFunc
77

8-
secretsVersion = input('To edit production server, enter the name of the \
9-
secrets file: ')
10-
if secretsVersion != '':
11-
try:
12-
secrets = __import__(secretsVersion)
13-
print('Editing Production')
14-
except ImportError:
15-
secrets = __import__('secrets')
16-
print('Editing Development')
17-
else:
18-
secrets = __import__('secrets')
19-
print('Editing Development')
20-
21-
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
8+
inst = input('To edit production server, enter the name of the secrets file: ')
9+
secrets = dsFunc.instSelect(inst)
2210

2311
baseURL = secrets.baseURL
2412
email = secrets.email
2513
password = secrets.password
2614
filePath = secrets.filePath
2715
verify = secrets.verify
28-
skippedCollections = secrets.skippedCollections
16+
skipColl = secrets.skipColl
17+
18+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
2919

3020
startTime = time.time()
3121
data = {'email': email, 'password': password}
@@ -52,7 +42,7 @@
5242
verify=verify).json()
5343
for collection in collections:
5444
collectionID = collection['uuid']
55-
if collectionID not in skippedCollections:
45+
if collectionID not in skipColl:
5646
collectionIds.append(collectionID)
5747

5848
names = []

deleteBitstreamsFromItem.py

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,30 +5,20 @@
55
import urllib3
66
import dsFunc
77

8-
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
9-
10-
secretsVersion = input('To edit production server, enter the name of the \
11-
secrets file: ')
12-
if secretsVersion != '':
13-
try:
14-
secrets = __import__(secretsVersion)
15-
print('Editing Production')
16-
except ImportError:
17-
secrets = __import__('secrets')
18-
print('Editing Development')
19-
else:
20-
secrets = __import__('secrets')
21-
print('Editing Development')
8+
inst = input('To edit production server, enter the name of the secrets file: ')
9+
secrets = dsFunc.instSelect(inst)
2210

2311
baseURL = secrets.baseURL
2412
email = secrets.email
2513
password = secrets.password
2614
filePath = secrets.filePath
2715
verify = secrets.verify
28-
skippedCollections = secrets.skippedCollections
16+
skipColl = secrets.skipColl
2917

3018
itemHandle = input('Enter item handle: ')
3119

20+
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
21+
3222
startTime = time.time()
3323
data = {'email': email, 'password': password}
3424
header = {'content-type': 'application/json', 'accept': 'application/json'}

deleteKeyFromCollection.py

Lines changed: 9 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,18 +7,15 @@
77
import argparse
88
import dsFunc
99

10-
secretsVersion = input('To edit production server, enter the name of the \
11-
secrets file: ')
12-
if secretsVersion != '':
13-
try:
14-
secrets = __import__(secretsVersion)
15-
print('Editing Production')
16-
except ImportError:
17-
secrets = __import__('secrets')
18-
print('Editing Development')
19-
else:
20-
secrets = __import__('secrets')
21-
print('Editing Development')
10+
inst = input('To edit production server, enter the name of the secrets file: ')
11+
secrets = dsFunc.instSelect(inst)
12+
13+
baseURL = secrets.baseURL
14+
email = secrets.email
15+
password = secrets.password
16+
filePath = secrets.filePath
17+
verify = secrets.verify
18+
skipColl = secrets.skipColl
2219

2320
parser = argparse.ArgumentParser()
2421
parser.add_argument('-k', '--deletedKey', help='the key to be deleted. \
@@ -39,13 +36,6 @@
3936

4037
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
4138

42-
baseURL = secrets.baseURL
43-
email = secrets.email
44-
password = secrets.password
45-
filePath = secrets.filePath
46-
verify = secrets.verify
47-
skippedCollections = secrets.skippedCollections
48-
4939
startTime = time.time()
5040
data = {'email': email, 'password': password}
5141
header = {'content-type': 'application/json', 'accept': 'application/json'}

0 commit comments

Comments
 (0)