Beispiel #1
0
def push_zip(progname, configbase, options, args):
    """
    push RO in zip format
    
    ro push <zip> | -d <dir> [ -f ] [-- new ] [ -r <rosrs_uri> ] [ -t <access_token> [ --asynchronous ] ]    
    """
    ro_config = getroconfig(configbase, options)
    ro_options = {
        "zip": args[2],
        "rosrs_uri":          ro_config['rosrs_uri'],
        "rosrs_access_token": ro_config['rosrs_access_token'],
        "force":          options.force,
        "roId": args[2].replace(".zip", "").split("/")[-1]
        }

    if options.roident:
        ro_options["roId"] = options.roident
    if options.verbose:
        echo = "ro push %(zip)s -r %(rosrs_uri)s -t %(rosrs_access_token)s -i %(roId)s" % dict(ro_options.items() + {'zip':args[2], 'roId':ro_options["roId"]}.items())
        if options.asynchronous:
         echo+=" --asynchronous"
        if options.new:
            echo+=" --new"
        print echo
    rosrs = ROSRS_Session(ro_options["rosrs_uri"], ro_options["rosrs_access_token"])
    if options.new:
        (status, reason, headers, data) = ro_remote_metadata.sendZipRO(rosrs, ro_options["rosrs_uri"], ro_options["roId"], open(args[2], 'rb').read(),"zip/create")
    else:
        (status, reason, headers, data) = ro_remote_metadata.sendZipRO(rosrs, ro_options["rosrs_uri"], ro_options["roId"], open(args[2], 'rb').read())
    jobUri = headers["location"]
    (job_status, target_id, processed_resources, submitted_resources) = ro_utils.parse_job(rosrs, headers["location"])
    print "Your Research Object %s is already processed" % target_id
    print "Job URI: %s" % jobUri
    if options.asynchronous:
        return  handle_asynchronous_zip_push(rosrs, headers["location"])
    #with esc option
    print   "If you don't want to wait until the operation is finished press [ENTER]"
    while printZipJob(ro_utils.parse_job(rosrs, jobUri),jobUri):
        i, o, e = select.select( [sys.stdin], [], [], 2 )
        if (i) and "" == sys.stdin.readline().strip():
            print "You can check the process status using job URI: %s" % jobUri
            return
    if options.verbose:
        print "Status: %s" % status
        print "Reason: %s" % reason
        print "Headers: %s" % headers
        print "Data: %s" % data
    log.debug("Status: %s" % status)
    log.debug("Reason: %s" % reason)
    log.debug("Headers: %s" % headers)
    log.debug("Data: %s" % data)
    return 0
def push_zip(progname, configbase, options, args):
    """
    push RO in zip format
    
    ro push <zip> | -d <dir> [ -f ] [ -r <rosrs_uri> ] [ -t <access_token> ]    
    """
    if options.verbose:
        print "ro push %(zip)s -r %(rosrs_uri)s -t %(rosrs_access_token)s" % dict(vars(options).items() + {'zip':args[2]}.items())
    ro_config = ro_utils.readconfig(configbase)
    ro_options = {
        "zip": args[2],
        "rosrs_uri":      options.rosrs_uri or getoptionvalue(ro_config['rosrs_uri'], "URI for ROSRS service:          "),
        "rosrs_access_token": options.rosrs_access_token or getoptionvalue(ro_config['rosrs_access_token'],
                                                                                      "Access token for ROSRS service: "),
        "force":          options.force,
        "roId": args[2].replace(".zip", "").split("/")[-1]
        }
    
    rosrs = ROSRS_Session(ro_options["rosrs_uri"], ro_options["rosrs_access_token"])

    (status, reason, headers, data) = ro_remote_metadata.sendZipRO(rosrs, ro_options["rosrs_uri"], ro_options["roId"], open(args[2], 'rb').read())
    if options.verbose:
        print "Status: %s" % status
        print "Reason: %s" % reason
        print "Headers: %s" % headers
        print "Data: %s" % data
    log.debug("Status: %s" % status)
    log.debug("Reason: %s" % reason)
    log.debug("Headers: %s" % headers)
    log.debug("Data: %s" % data)
    return 0