Beispiel #1
0
def get_svninfo():
    from SSHHelper import SSHHelper
    ssh = SSHHelper("localhost")
    try:
        result = ssh.exe_cmd("svn info", shell=True)
    except Exception, e:
        traceback.print_exc()
        message = "svn get failed with error %s" % str(e)
        print message
        return (False, message.replace("'", "\\'"))
Beispiel #2
0
def get_svninfo():
    from SSHHelper import SSHHelper
    ssh = SSHHelper("localhost")
    try:
        result = ssh.exe_cmd("svn info", shell=True)
    except Exception, e:
        traceback.print_exc()
        message = "svn get failed with error %s" % str(e)
        print message
        return (False, message.replace("'","\\'"))
Beispiel #3
0
 def POST(self):
     rawdata = web.input(f={})
     imagename = rawdata.f.filename.replace("\\", "/").split("/")[-1]
     extentname = os.path.splitext(imagename)
     imagedata = rawdata.f.file.read()
     self.get_request()
     self.request["requestbody"] = {"filename": rawdata.f.filename}
     os.chdir(Server.workdirectory)
     hashname = hashlib.sha224(str(self.request["requestheaders"]) + self.request["remote_address"]).hexdigest()
     filename = self.generate_filename(hashname) + extentname[1]
     imagefile = open(filename, "wb")
     imagefile.write(imagedata)
     imagefile.close()
     sshhelper = SSHHelper("localhost")
     data = sshhelper.exe_cmd("zbarimg --raw -q %s" % filename, shell=True, printcmd=False)
     os.remove(filename)
     if data.code == 0:
         return self.message_helper(data.stdout, "200 OK")
     else:
         return self.message_helper(data.stderr, "500 Internal Server Error")
Beispiel #4
0
 def GET(self):
     self.get_request()
     rawdata = web.input()
     os.chdir(Server.workdirectory)
     try:
         data = Utils.get_dict_from_json(rawdata.data)
         self.request["parameters"] = {"data": str(data)}
         suitename = data["suite_name"]
         svnflag = True if data.get("svnlink") and data.get("comment") else False
         if not svnflag and data.get("ci_link"):
             return self.message_helper("Please input svn link and comment", "200 OK")
         baseline_paths = os.path.split(os.path.join(data["baseline_path"].replace("\\\\", "\\"), suitename))
         output_paths = os.path.split(os.path.join(data["output_path"].replace("\\\\", "\\"), suitename))
         helper = SSHHelper("localhost")
         if not data.get("ci_link"):
             ci_link = None
             baseline_path = Utils.get_filestr(baseline_paths)
             os.chdir(baseline_path)
             if svnflag:
                 result = helper.exe_cmd(
                     self.generate_svn_command("svn revert -R . --no-auth-cache"), shell=True, printcmd=False
                 )
                 if result.code != 0:
                     return self.message_helper("svn revert failed %s" % result.stderr, "200 OK")
                 result = helper.exe_cmd(
                     self.generate_svn_command("svn up . --no-auth-cache"), shell=True, printcmd=False
                 )
                 if result.code != 0:
                     return self.message_helper("svn update failed %s" % result.stderr, "200 OK")
         else:
             ci_link = data["ci_link"]
             job_name = ci_link.split("/")[-3]
             work_path = os.path.join(Server.workdirectory, job_name)
             baseline_path = os.path.join(work_path, os.path.split(data["baseline_path"].replace("\\\\", "\\"))[-1])
             if os.path.exists(baseline_path):
                 os.chdir(baseline_path)
                 result = helper.exe_cmd(
                     self.generate_svn_command("svn up . --no-auth-cache"), shell=True, printcmd=False
                 )
                 if result.code != 0:
                     return self.message_helper("svn update failed %s" % result.stderr, "200 OK")
             else:
                 if not os.path.exists(work_path):
                     os.mkdir(work_path)
                 os.chdir(work_path)
                 result = helper.exe_cmd(
                     self.generate_svn_command("svn co %s --no-auth-cache" % data["svnlink"]),
                     shell=True,
                     printcmd=False,
                 )
                 if result.code != 0:
                     return self.message_helper("svn checkout failed %s" % result.stderr, "200 OK")
                 os.chdir(baseline_path)
             baseline_paths = os.path.split(os.path.join(baseline_path, suitename))
         base_filename = suitename + ".base"
         baseline_caselist = Utils.get_json_from_file(baseline_paths, base_filename)
         if not ci_link:
             output_caselist = Utils.get_json_from_file(output_paths, base_filename)
         else:
             ci_basefile = ci_link + "/" + suitename + "/" + base_filename
             api = Request(method="GET", base_url=ci_basefile)
             resp = api.send()
             if resp.result["status"] != "200":
                 return self.message_helper("Invalid CI link %s" % ci_basefile, "200 OK")
             output_caselist = resp.result["data"]
         for baseline in data["baseline"]:
             casename, assertionname = baseline.split("/")
             if type(output_caselist[casename][assertionname]) == dict and output_caselist[casename][
                 assertionname
             ].get("image_type"):
                 image_name = (
                     output_caselist[casename][assertionname]["image_name"]
                     + "."
                     + output_caselist[casename][assertionname]["image_type"]
                 )
                 self.copy_image(suitename, image_name, baseline_paths, output_paths, ci_link)
             if not baseline_caselist.get(casename):
                 baseline_caselist[casename] = {}
             baseline_caselist[casename][assertionname] = output_caselist[casename][assertionname]
         Utils.dump_dict_to_file(baseline_caselist, baseline_paths, base_filename)
         web.ctx.headers = [("Access-Control-Allow-Origin", "*")]
         if svnflag:
             result = helper.exe_cmd(
                 self.generate_svn_command("svn add . --no-auth-cache --force"), shell=True, printcmd=False
             )
             if result.code != 0:
                 return self.message_helper("svn add failed %s" % result.stderr, "200 OK")
             result = helper.exe_cmd(
                 self.generate_svn_command("""svn ci . -m "%s" --no-auth-cache""" % data["comment"]),
                 shell=True,
                 printcmd=False,
             )
             if result.code != 0:
                 return self.message_helper("svn checkin failed %s" % result.stderr, "200 OK")
             return self.message_helper("Update Successful in svn", "200 OK")
         else:
             return self.message_helper("Update Successful in local without checkin", "200 OK")
     except Exception:
         info = sys.exc_info()
         err = []
         for filename, lineno, function, text in traceback.extract_tb(info[2]):
             err.append(filename + "line:" + str(lineno) + "in" + str(function))
             err.append(str(text))
         traceback.print_exc()
         return self.message_helper(
             "Problem on updating code logic:\n %s" % "\n".join(err), "500 Internal Server Error"
         )