Esempio n. 1
0
def pull_from_cuit_and_submit_to_pcp(operation, params):
    statsd.incr("pull_from_cuit_and_submit_to_pcp")
    print "pulling from tahoe"
    params = loads(operation.params)
    video_id = params['video_id']
    workflow = params['workflow']
    video = Video.objects.get(id=video_id)
    if workflow == "":
        return ("failed", "no workflow specified")

    ouuid = operation.uuid
    cuit_file = video.file_set.filter(video=video, location_type="cuit")[0]

    filename = cuit_file.filename
    extension = os.path.splitext(filename)[1]
    tmpfilename = os.path.join(settings.TMP_DIR, str(ouuid) + extension)
    sftp_get(filename, tmpfilename)
    operation.log(info="downloaded from cuit")

    print "submitting to PCP"
    pcp = PCP(settings.PCP_BASE_URL, settings.PCP_USERNAME,
              settings.PCP_PASSWORD)
    filename = str(ouuid) + extension
    print "submitted with filename %s" % filename

    title = "%s-%s" % (str(ouuid), strip_special_characters(video.title))
    print "submitted with title %s" % title
    pcp.upload_file(open(tmpfilename, "r"), filename, workflow, title,
                    video.description)
    return ("submitted", "submitted to PCP")
Esempio n. 2
0
def pull_from_s3_and_submit_to_pcp(operation, params):
    statsd.incr("pull_from_s3_and_submit_to_pcp")
    print "pulling from S3"
    params = loads(operation.params)
    video_id = params['video_id']
    workflow = params['workflow']
    video = Video.objects.get(id=video_id)
    ouuid = operation.uuid
    filename = video.filename()
    suffix = video.extension()

    conn = boto.connect_s3(
        settings.AWS_ACCESS_KEY,
        settings.AWS_SECRET_KEY)
    bucket = conn.get_bucket(settings.AWS_S3_UPLOAD_BUCKET)
    k = Key(bucket)
    k.key = video.s3_key()

    t = tempfile.NamedTemporaryFile(suffix=suffix)
    k.get_contents_to_file(t)
    t.seek(0)

    operation.log(info="downloaded from S3")
    # TODO: figure out how to re-use submit_to_pcp()
    print "submitting to PCP"
    pcp = PCP(settings.PCP_BASE_URL, settings.PCP_USERNAME,
              settings.PCP_PASSWORD)
    filename = str(ouuid) + suffix
    print "submitted with filename %s" % filename

    title = "%s-%s" % (str(ouuid), strip_special_characters(video.title))
    print "submitted with title %s" % title
    pcp.upload_file(t, filename, workflow, title, video.description)
    return ("submitted", "submitted to PCP")
Esempio n. 3
0
def pull_from_tahoe_and_submit_to_pcp(operation, params):
    statsd.incr("pull_from_tahoe_and_submit_to_pcp")
    print "pulling from tahoe"
    params = loads(operation.params)
    video_id = params['video_id']
    workflow = params['workflow']
    video = Video.objects.get(id=video_id)
    ouuid = operation.uuid
    url = video.tahoe_download_url()
    if url == "":
        return ("failed", "does not have a tahoe stored file")
    if workflow == "":
        return ("failed", "no workflow specified")
    filename = video.filename()
    suffix = video.extension()
    t = tempfile.NamedTemporaryFile(suffix=suffix)
    r = urllib2.urlopen(url)
    t.write(r.read())
    t.seek(0)
    operation.log(info="downloaded from tahoe")
    # TODO: figure out how to re-use submit_to_pcp()
    print "submitting to PCP"
    pcp = PCP(settings.PCP_BASE_URL, settings.PCP_USERNAME,
              settings.PCP_PASSWORD)
    filename = str(ouuid) + suffix
    print "submitted with filename %s" % filename

    title = "%s-%s" % (str(ouuid), strip_special_characters(video.title))
    print "submitted with title %s" % title
    pcp.upload_file(t, filename, workflow, title, video.description)
    return ("submitted", "submitted to PCP")
Esempio n. 4
0
 def test_kino_connection(self):
     workflows = []
     try:
         p = PCP(settings.PCP_BASE_URL,
                 settings.PCP_USERNAME,
                 settings.PCP_PASSWORD)
         workflows = p.workflows()
     except:
         workflows = []
     self.assertTrue(len(workflows) > 0)
Esempio n. 5
0
def get_pcp_workflows():
    """ returns list of workflows and error message.

    if it succeeds, error message will be an empty string
    if it fails, workflows will be an empty list """
    error_message = ""
    try:
        p = PCP(settings.PCP_BASE_URL,
                settings.PCP_USERNAME,
                settings.PCP_PASSWORD)
        workflows = p.workflows()
    except Exception, e:
        error_message = str(e)
        workflows = []
Esempio n. 6
0
def submit_to_pcp(operation, params):
    statsd.incr("submit_to_pcp")
    ouuid = operation.uuid

    # ignore the passed in params and use the ones from the operation object
    params = loads(operation.params)
    pcp = PCP(settings.PCP_BASE_URL, settings.PCP_USERNAME,
              settings.PCP_PASSWORD)
    # TODO: probably don't always want it to be .mp4
    filename = str(ouuid) + (operation.video.filename() or ".mp4")
    fileobj = open(params['tmpfilename'])
    title = "%s-%s" % (str(ouuid),
                       strip_special_characters(operation.video.title))
    pcp.upload_file(fileobj, filename, params['pcp_workflow'], title,
                    operation.video.description)
    return ("submitted", "")