Exemplo n.º 1
0
 def upload(self, id=None):
     if request.method == "GET":
         c.uuid=id
         return render('/upload_form.mako')
     else:
         workdir = os.path.join("/tmp","%s%s" % (request.POST['user'],time()))
         os.makedirs(workdir)
         myfile = request.POST['file']
         permanent_file = open(os.path.join(workdir,
                                         myfile.filename.lstrip(os.sep)),
                                         'w')
         shutil.copyfileobj(myfile.file, permanent_file)
         myfile.file.close()
         permanent_file.close()
         
         metadata_file = open(os.path.join(workdir,
                                         "metadata.plist"),
                                         'w')
         
         
         metadata_file.write("""<?xml version="1.0" encoding="UTF-8"?>
         <!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
         <plist version="1.0">
             <dict>
                 <key>Description</key>
                 <string>%s</string>
                 <key>Title</key>
                 <string>%s</string>
             </dict>
         </plist>
         """ % (request.POST['description'],request.POST['title']))
         metadata_file.close()
         
         pcast = PCast.PCast()
         (status, pcast_result, pcast_stdout, pcast_stderr) = pcast.submit(username = request.POST['user'],
                                                                   password = request.POST['password'],
                                                                   file_path = permanent_file.name,
                                                                   metadata = metadata_file.name,
                                                                   workflow_uuid = request.POST['uuid'],
                                                                   )
         try:
             upload_uuid = pcast_stdout.split("\n")[0].rsplit(' ',1)[1]
         except Exception, e:
             upload_uuid = "N/A"
         c.pcast_upload_uuid = upload_uuid
         c.pcast_result = pcast_result
         c.pcast_stdout = pcast_stdout
         c.pcast_stderr = pcast_stderr
         c.status = status
         log.info("%s -- %s, username = '******', status = %s" % (request.remote_addr, request.url, request.POST['user'], pcast_result))
         log.info("Upload UUID : %s" % (upload_uuid))
         log.info("Upload File : %s" % (permanent_file.name))
         
         if status == 0:
             shutil.rmtree(workdir, False, lambda x,y,z: log.error("Couldn't remove %s : %s" % (y,z)))
         return render('/debug_upload.mako')
Exemplo n.º 2
0
 def workflows_xml(self):
      if request.method == "GET":
          log.debug("%s -- %s" % (request.host, request.url))
          return render('/workflows_form.mako')
      else:
          pcast = PCast.PCast()
          (status, pcast_result, pcast_stdout, pcast_stderr) = pcast.getWorkflows(username = request.POST['user'],
                                         password = request.POST['password'])
          if(status != 0):
              c.exception = pcast_result
              c.code = status
              log.error("%s -- %s, username = '******', status = %s" % (request.remote_addr, request.url, request.POST['user'], pcast_result))
              return render('/pcast_error.mako')
          else:
              return Response(pcast_stdout, content_type="text/xml")    
Exemplo n.º 3
0
 def workflows(self):
     if request.method == "GET":
         log.debug("%s -- %s" % (request.host, request.url))
         return render('/workflows_form.mako')
     else:
         pcast = PCast.PCast()
         (status, pcast_result, pcast_stdout, pcast_stderr) = pcast.getWorkflows(username = request.POST['user'],
                                        password = request.POST['password'])
         if(status != 0):
             c.exception = pcast_result
             c.code = status
             log.error("%s -- %s, username = '******', status = %s" % (request.remote_addr, request.url, request.POST['user'], pcast_result))
             return render('/pcast_error.mako')
         else:
             flows = plistlib.readPlistFromString(pcast_stdout)
             c.user = request.POST['user']
             c.workflows = [{'name':x['name'], 'uuid':x['uuid'], 'description':x['description']} for x in flows['workflows']]
             log.debug("%s -- %s, username = '******', status = %s" % (request.remote_addr, request.url, request.POST['user'], pcast_result))
             return render('/workflows.mako')