try:
        colid = args.pop(0)
    except:
        _exit(usage, 1)

    if args:
        destDir = args[0]
    else:
        destDir = "."

    # ---
    trnkbs2ds = TranskribusDownloader(options.server,
                                      proxies,
                                      loggingLevel=logging.WARN)
    __Trnskrbs_do_login_stuff(trnkbs2ds, options, trace=trace, traceln=traceln)

    if options.trp:
        traceln("- Loading trp data from %s" % options.trp)
        #         trp = json.load(open(options.trp, "rb",encoding='utf-8'))
        trp = json.load(open(options.trp, "rt", encoding='utf-8'))

        traceln(
            "- Downloading collection %s to folder %s, as specified by trp data"
            % (colid, os.path.abspath(destDir)))
        if not options.docid:
            options.docid = trp["md"]["docId"]
            traceln(" read docId from TRP: docId = %s" % options.docid)
        logging.basicConfig(level=logging.INFO)
        col_ts, docFolder, lFileList = trnkbs2ds.download_document_by_trp(
            colid,
        'https_proxy': options.https_proxy
    }

    # ---
    #source collection(s)
    try:
        colid = int(args[0])
    except Exception as e:
        _exit(usage, 1, e)
    try:
        docid = int(args[0])
    except Exception as e:
        _exit(usage, 1, e)
    try:
        page = int(args[0])
    except Exception as e:
        _exit(usage, 1, e)

    # ---
    doer = listPageLocks(options.server, proxies, loggingLevel=logging.INFO)
    __Trnskrbs_do_login_stuff(doer, options, trace=trace, traceln=traceln)

    # ---
    # do the job...
    try:
        resp = doer.getListofLockedPages(colid, docid, page)
    except Exception as e:
        _exit("", 1, e)
    traceln(resp)
    traceln("- Done")
Esempio n. 3
0
def main():
    usage = "%s <directory> <coldId> [<docId>]" % sys.argv[0]
    version = "v.01"
    description = """Upload the transcript(s) from the DS structure to Transkribus, either of the collection or one of its document(s). 
The <directory> must have been created by transkribus_downloader.py and should contain the 'col' directory and a trp.json file for the collection, and one per document (the 'out', 'ref', 'run', 'xml' folders are not used).
The page transcript from the single page PageXml files are uploaded. (The multi-page xml file(s) are ignored))    
""" + _Trnskrbs_description

    #prepare for the parsing of the command line
    parser = OptionParser(usage=usage, version=version)
    parser.description = description

    #"-s", "--server",  "-l", "--login" ,   "-p", "--pwd",   "--https_proxy"    OPTIONS
    __Trnskrbs_basic_options(parser,
                             TranskribusTranscriptUploader.sDefaultServerUrl)

    parser.add_option("-q",
                      "--quiet",
                      dest='bQuiet',
                      action="store_true",
                      default=False,
                      help="Quiet mode")
    parser.add_option("--trp",
                      dest='trp',
                      action="store",
                      type="string",
                      help="download the content specified by the trp file.")
    parser.add_option("--toolname",
                      dest='tool',
                      action="store",
                      type="string",
                      default="",
                      help="Set the Toolname metadata in Transkribus.")
    parser.add_option("--message",
                      dest='message',
                      action="store",
                      type="string",
                      default="",
                      help="Set the message metadata in Transkribus.")
    parser.add_option("--set_status",
                      dest='set_status',
                      action="store",
                      type="string",
                      default=None,
                      help="Set the status of the uploaded trasnscript.")

    # ---
    #parse the command line
    (options, args) = parser.parse_args()
    proxies = {} if not options.https_proxy else {
        'https_proxy': options.https_proxy
    }

    iVerbose = 0 if options.bQuiet else 2
    # ---
    try:
        sDSDir = args.pop(0)
    except:
        _exit(usage, 1)
    if not (sDSDir.endswith(sCOL) or sDSDir.endswith(sCOL + os.path.sep)):
        sColDSDir = os.path.abspath(os.path.join(sDSDir, sCOL))
    else:
        sColDSDir = os.path.abspath(sDSDir)
    if not (os.path.exists(sColDSDir) and os.path.isdir(sColDSDir)):
        raise ValueError("Non-existing folder: %s " % sColDSDir)

    try:
        colid = args.pop(0)
    except:
        _exit(usage, 1)

    try:
        docid = args.pop(0)
    except:
        docid = None

    # ---
    doer = TranskribusTranscriptUploader(options.server,
                                         proxies,
                                         loggingLevel=logging.WARN)
    __Trnskrbs_do_login_stuff(doer, options, trace=trace, traceln=traceln)

    if options.trp:
        trp = json.load(open(options.trp, "r", encoding='utf-8'))
        traceln("- Uploading to collection %s, as specified by trp data" %
                (colid))
        if not docid:
            docid = trp["md"]["docId"]
            traceln(" read docId from TRP: docId = %s" % docid)
        sToolname = options.tool if options.tool else "Transkribus_uploader (--trp)"
        lFileList = doer.uploadDocumentTranscript_by_trp(
            colid,
            docid,
            trp,
            sColDSDir,
            sNote=options.message,
            sToolName=sToolname,
            iVerbose=iVerbose,
            status=options.set_status)
        #traceln(map(lambda x: x.encode('utf-8'), lFileList))
    else:
        if docid == None:
            sToolname = options.tool if options.tool else "Transkribus_uploader"
            doer.uploadCollectionTranscript(colid,
                                            sColDSDir,
                                            sNote=options.message,
                                            sToolName=sToolname,
                                            iVerbose=iVerbose,
                                            status=options.set_status)

        else:
            sToolname = options.tool if options.tool else "Transkribus_uploader (docid)"
            doer.uploadDocumentTranscript(colid,
                                          docid,
                                          sColDSDir,
                                          sNote=options.message,
                                          sToolName=sToolname,
                                          iVerbose=iVerbose,
                                          status=options.set_status)

    traceln('- DONE, all transcripts were uploaded. See in collection %s' %
            colid)