Mercurial > hg > sworduploader
comparison sworduploader.py @ 13:cc6c7235d08a
v0.5: changed "save_zip" to False, unless --zip arg is used
author | Marco Fabiani <marco.fabiani@eecs.qmul.ac.uk> |
---|---|
date | Fri, 18 May 2012 16:20:04 +0100 |
parents | ed98a232e4a5 |
children | 273fc80d9623 |
comparison
equal
deleted
inserted
replaced
12:ed98a232e4a5 | 13:cc6c7235d08a |
---|---|
1 #!usr/bin/env/ python | 1 #!usr/bin/env/ python |
2 | 2 |
3 """ | 3 """ |
4 | 4 |
5 SWORD2 DSpace bulk uploader - v0.4 | 5 SWORD2 DSpace bulk uploader - v0.5 |
6 | 6 |
7 A python script to submit large numbers of files to a SWORD2-compatible repository, specifically DSpace 1.8x. | 7 A python script to submit large numbers of files to a SWORD2-compatible repository, specifically DSpace 1.8x. |
8 Built on the SWORD2 python client library: https://bitbucket.org/beno/python-sword2/overview with modifications. | 8 Built on the SWORD2 python client library: https://bitbucket.org/beno/python-sword2/overview with modifications. |
9 | 9 |
10 Dependencies: | 10 Dependencies: |
51 parser.add_argument("--username", dest="user_name", type=str,nargs=1, help="DSpace username.") | 51 parser.add_argument("--username", dest="user_name", type=str,nargs=1, help="DSpace username.") |
52 parser.add_argument("--zip", action="store_true",dest="zip",default=False, help="If \"data\" is a directory, compress it and post it as a single file. The zip file will be saved along with the individual files.") | 52 parser.add_argument("--zip", action="store_true",dest="zip",default=False, help="If \"data\" is a directory, compress it and post it as a single file. The zip file will be saved along with the individual files.") |
53 parser.add_argument("--title", dest="title", type=str,nargs=1, help="Title (ignored for METS packages).") | 53 parser.add_argument("--title", dest="title", type=str,nargs=1, help="Title (ignored for METS packages).") |
54 parser.add_argument("--author", dest="author", type=str,nargs="+", help="Author(s) (ignored for METS packages). Accepts multiple entries in the format \"Surname, Name\"") | 54 parser.add_argument("--author", dest="author", type=str,nargs="+", help="Author(s) (ignored for METS packages). Accepts multiple entries in the format \"Surname, Name\"") |
55 parser.add_argument("--date", dest="date", type=str,nargs=1, help="Date of creation (string) (ignored for METS packages).") | 55 parser.add_argument("--date", dest="date", type=str,nargs=1, help="Date of creation (string) (ignored for METS packages).") |
56 parser.add_argument("--servicedoc", dest="dspaceurl", type=str,nargs=1, help="Url of the SWORDv2 service document (default: http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/servicedocument") | 56 parser.add_argument("--servicedoc", dest="sd", type=str,nargs=1, help="Url of the SWORDv2 service document (default: http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/servicedocument") |
57 | 57 |
58 args = parser.parse_args() | 58 args = parser.parse_args() |
59 data = args.data[0] | 59 data = args.data[0] |
60 storezip = True | 60 if args.zip: |
61 | 61 storezip = True |
62 if args.dspaceurl == None: | |
63 dspaceurl = "http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/servicedocument" | |
64 else: | 62 else: |
65 dspaceurl = args.dspaceurl[0] | 63 storezip = False |
64 | |
65 if args.sd == None: | |
66 sd = "http://c4dm.eecs.qmul.ac.uk/smdmrd-test/swordv2/servicedocument" | |
67 else: | |
68 sd = args.sd[0] | |
66 | 69 |
67 | 70 |
68 try: | 71 try: |
69 # Connect to SWORD server | 72 # Connect to SWORD server: it will always try to authenticate (no anonymous submissions! |
70 attempts = 3 # Number of attempts left to connect to server | 73 attempts = 3 # Number of attempts left to connect to server |
71 connected = False | 74 connected = False |
72 while attempts>0 and not connected: | 75 while attempts>0 and not connected: |
73 print "Connecting to SWORD server. Remaining attempts: ", attempts | 76 print "Connecting to SWORD server. Remaining attempts: ", attempts |
74 # Try to login, get service document | 77 # Try to login, get service document |
75 # Get username and password | 78 # Get username and password |
76 if args.user_name == None: | 79 if args.user_name == None: |
77 user_name = raw_input("DSpace Username: ") | 80 user_name = raw_input("Username: ") |
78 else: | 81 else: |
79 user_name = args.user_name[0] | 82 user_name = args.user_name[0] |
80 print "DSpace Username: ",user_name | 83 print "Username: ",user_name |
81 user_pass = getpass.getpass("DSpace password:") | 84 user_pass = getpass.getpass("Password:") |
82 # Connect to the server | 85 # Connect to the server |
83 c = Connection(dspaceurl, user_name=user_name, user_pass=user_pass,keep_history=False) | 86 c = Connection(sd, user_name=user_name, user_pass=user_pass,keep_history=False) |
84 | 87 |
85 # Get service document | 88 # Get service document |
86 try: | 89 try: |
87 c.get_service_document() | 90 c.get_service_document() |
88 except: # Server error | 91 except: # Server error |