# HG changeset patch # User Marco Fabiani # Date 1338288926 -3600 # Node ID e24aea2d14a4e7b7b744c6cb1dbe800d588faa31 # Parent 273fc80d9623f262b92bdc0fd5d7268f3692c5bd - v0.6: use server.cfg, maintain dir structure with dir upload diff -r 273fc80d9623 -r e24aea2d14a4 README --- a/README Fri May 25 13:14:05 2012 +0100 +++ b/README Tue May 29 11:55:26 2012 +0100 @@ -20,6 +20,7 @@ Installation: - no installation required, simply copy the script sworduploader.py to a suitable location. The first time you run the script, it will create the sword2_logging.conf file. +- a server.cfg file is also available. If the --servicedoc option is not used, sworduploader will read the first line of server.cfg and use it as the server's URL. If the server.cfg is missing, it will default to C4DM's server. ----------------------------------------------- Usage: @@ -40,17 +41,17 @@ optional arguments: -h, --help show this help message and exit --username USER_NAME DSpace username. - --zip 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. --title TITLE Title (ignored for METS packages). --author AUTHOR [AUTHOR ...] Author(s) (ignored for METS packages). Accepts multiple entries in the format "Surname, Name" --date DATE Date of creation (string) (ignored for METS packages). - --servicedoc DSPACEURL - Url of the SWORDv2 service document (default: - http://c4dm.eecs.qmul.ac.uk/rdr/swordv2/servicedocument + --zip 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. + --servicedoc SD Url of the SWORDv2 service document (default: use + server.cfg if available, otherwise http://c4dm.eecs.qm + ul.ac.uk/rdr/swordv2/servicedocument If the submission is created successfully, it will remain open to be completed with the necessary metadata and licenses, using the DSpace web interface. The diff -r 273fc80d9623 -r e24aea2d14a4 server.cfg --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/server.cfg Tue May 29 11:55:26 2012 +0100 @@ -0,0 +1,1 @@ +http://c4dm.eecs.qmul.ac.uk/rdr/swordv2/servicedocument \ No newline at end of file diff -r 273fc80d9623 -r e24aea2d14a4 sworduploader.py --- a/sworduploader.py Fri May 25 13:14:05 2012 +0100 +++ b/sworduploader.py Tue May 29 11:55:26 2012 +0100 @@ -2,10 +2,10 @@ """ -SWORD2 DSpace bulk uploader - v0.5 +SWORD2 DSpace bulk uploader - v0.6 A python script to submit large numbers of files to a SWORD2-compatible repository, specifically DSpace 1.8x. -Built on the SWORD2 python client library: https://bitbucket.org/beno/python-sword2/overview with modifications. +Built on the SWORD2 python client library: https://github.com/swordapp/python-client-sword2. Dependencies: @@ -14,6 +14,13 @@ - sword2 library: https://github.com/swordapp/python-client-sword2 ----------------------------------- +Updates log: + +v0.6: - now uploading a directory will also maintain the path structure + - introduced a file where to specify the server (server.cfg) +v0.5: changed the default server to C4DM live server + +----------------------------------- Centre for Digital Music, Queen Mary, University of London Copyright (c) 2012 Marco Fabiani @@ -53,7 +60,7 @@ parser.add_argument("--author", dest="author", type=str,nargs="+", help="Author(s) (ignored for METS packages). Accepts multiple entries in the format \"Surname, Name\"") parser.add_argument("--date", dest="date", type=str,nargs=1, help="Date of creation (string) (ignored for METS packages).") 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.") -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") +parser.add_argument("--servicedoc", dest="sd", type=str,nargs=1, help="Url of the SWORDv2 service document (default: use server.cfg if available, otherwise http://c4dm.eecs.qmul.ac.uk/rdr/swordv2/servicedocument") args = parser.parse_args() data = args.data[0] @@ -63,7 +70,12 @@ storezip = False if args.sd == None: - sd = "http://c4dm.eecs.qmul.ac.uk/rdr/swordv2/servicedocument" + try: + f = open("server.cfg", "r") + sd = f.readline() + print "server.cfg: ", sd + except: + sd = "http://c4dm.eecs.qmul.ac.uk/rdr/swordv2/servicedocument" else: sd = args.sd[0] @@ -192,12 +204,15 @@ creation_receipt = c.create(col_iri = collection.href, metadata_entry = entry, in_progress=True) # Add the files + # Get the longest common path in order to send the correct filename to keep the structure + common = os.path.commonprefix(fileslist) for f in fileslist: - print "Uploading file ",os.path.basename(f) + filename = os.path.relpath(f,common) + print "Uploading file ", filename payload = open(f,"rb") deposit_receipt = c.add_file_to_resource(edit_media_iri = creation_receipt.edit_media, payload = payload, - filename = os.path.basename(f), + filename = filename, mimetype = 'application/zip', packaging = 'http://purl.org/net/sword/package/Binary') payload.close()