Example #1
0
    #"-s", "--server",  "-l", "--login" ,   "-p", "--pwd",   "--https_proxy"    OPTIONS
    __Trnskrbs_basic_options(parser, DoCopyDocToCollec.sDefaultServerUrl)

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

    # ---
    #source collection
    try:
        colIdFrom = int(args.pop(0))
    except Exception as e:
        _exit(usage, 1, e)
    #target collection
    try:
        colIdTo = int(args.pop(0))
    except Exception as e:
        _exit(usage, 1, e)

    # ---
    # document list
    try:
        lDocId = []
        while args:
            chunk = args.pop(0).strip()
            li = chunk.split('-')
            if li and len(li) == 2:
                docId1, docId2 = [int(i) for i in li]
    #"-s", "--server",  "-l", "--login" ,   "-p", "--pwd",   "--https_proxy"    OPTIONS
    __Trnskrbs_basic_options(parser, listPageLocks.sDefaultServerUrl)

    # ---
    #parse the command line
    (options, args) = parser.parse_args()
    proxies = {} if not options.https_proxy else {
        '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...
Example #3
0
    parser.description = description

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

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

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

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

    # ---
    # do the job...
    try:
        resp = doer.getJobs()
    except Exception as e:
        _exit("", 1, e)
    traceln(json.dumps(resp, sort_keys=True, indent=4, separators=(',', ': ')))
Example #4
0
    #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, DoGetJobs.sDefaultServerUrl)
        
    # ---   
    #parse the command line
    (options, args) = parser.parse_args()
    proxies = {} if not options.https_proxy else {'https_proxy':options.https_proxy}

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

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

    # --- 
    # do the job...
    try:
        resp = doer.getJobs()
    except Exception as e:  _exit("", 1, e)
    traceln( json.dumps(resp, sort_keys=True, indent=4, separators=(',', ': ')))
    
    
    #"-s", "--server",  "-l", "--login" ,   "-p", "--pwd",   "--https_proxy"    OPTIONS
    __Trnskrbs_basic_options(parser, DoGetDocTrp.sDefaultServerUrl)
    parser.add_option("-n", "--n"  , dest='nbTranscript', action="store", type="int", default=1, help="Number of transcripts")
        
    # ---   
    #parse the command line
    (options, args) = parser.parse_args()
    proxies = {} if not options.https_proxy else {'https_proxy':options.https_proxy}

    # --- 
    doer = DoGetDocTrp(options.server, proxies, loggingLevel=logging.WARN)
    __Trnskrbs_do_login_stuff(doer, options, trace=trace, traceln=traceln)
    # --- 
    try:                        colId = int(args.pop(0))
    except Exception as e:      _exit(usage, 1, e)
    try:                        docId   = int(args.pop(0))
    except Exception as e:      _exit(usage, 1, e)
    try:                        sPageRangeSpec = args.pop(0)
    except Exception as e:      sPageRangeSpec = None
    if args:                    _exit(usage, 2, Exception("Extra arguments to the command"))

    oPageRange = PageRangeSpec(sPageRangeSpec) if sPageRangeSpec else None
        
    # --- 
    # do the job...
    resp = doer.run(colId, docId, nrOfTranscripts=options.nbTranscript)
    if oPageRange:
        traceln("Filtering response as per page specification: %s"%oPageRange)
        #let's filter the response (not super efficient but easy to code...
        ldPages = resp["pageList"]["pages"]
                      type="string",
                      help="download the content specified by the trp file.")

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

    # ---

    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'))
Example #7
0
    parser.description = description
    
    #"-s", "--server",  "-l", "--login" ,   "-p", "--pwd",   "--https_proxy"    OPTIONS
    __Trnskrbs_basic_options(parser, listPageLocks.sDefaultServerUrl)
        
    # ---   
    #parse the command line
    (options, args) = parser.parse_args()
    proxies = {} if not options.https_proxy else {'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...
Example #8
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)
    #parse the command line
    (options, args) = parser.parse_args()
    proxies = {} if not options.https_proxy else {
        'https_proxy': options.https_proxy
    }
    # ------------------------------------------------------------------------------------------------
    doer = DoAddDocToCollec(options.server, proxies, loggingLevel=logging.INFO)
    __Trnskrbs_do_login_stuff(doer, options, trace=trace, traceln=traceln)

    # ---
    #target collection
    try:
        colId = int(args.pop(0))
    except Exception as e:
        _exit(usage, 1, e)

    # ---
    # document list
    try:
        lDocId = []
        while args:
            chunk = args.pop(0).strip()
            li = chunk.split('-')
            if li and len(li) == 2:
                docId1, docId2 = [int(i) for i in li]
                lDocId.extend(range(docId1, docId2 + 1))
            else:
                docId = int(chunk)
                lDocId.append(docId)
    except Exception as e: