Пример #1
0
def qr_decode(
        element=None,
        image_filepath=None,
        parse_url="http://chorusserver.labs.microstrategy.com:8765/qr_decode"):
    from APIManagement import Request, RequestMode
    try:
        if element:
            element.get_screenshot_as_file("temp_code.png")
            filepath = "temp_code.png"
        elif image_filepath:
            filepath = image_filepath
        else:
            print "No input value"
            return False
        req = Request(base_url=parse_url,
                      method="POST",
                      mode=RequestMode.multi_form,
                      upload_files={"f": filepath})
        req.send()
        if element:
            os.remove(filepath)
        if req.result["status"] == "200":
            return req.result["data"]
        else:
            print "QRDecode Server Error: %s" % req.result["data"]
    except Exception, e:
        traceback.print_exc()
        print "Decode QRCode meets error %s" % str(e)
Пример #2
0
def qr_decode_deprecated(element=None,
                         image_filepath=None,
                         parse_url="http://zxing.org/w/decode"):
    from APIManagement import Request, RequestMode
    try:
        if element:
            element.get_screenshot_as_file("temp_code.png")
            filepath = "temp_code.png"
        elif image_filepath:
            filepath = image_filepath
        else:
            print "No input value"
            return False
        req = Request(base_url=parse_url,
                      method="POST",
                      mode=RequestMode.multi_form,
                      upload_files={"f": filepath})
        req.send()
        data = req.result["data"].split('<pre style="margin:0">')
        if element:
            os.remove(filepath)
        return data[-1].split("</pre>")[0]
    except Exception, e:
        traceback.print_exc()
        print "Decode QRCode meets error %s" % str(e)
        return False
Пример #3
0
 def copy_image(self, suitename, image_name, baseline_paths, output_paths, ci_link):
     image_path = Utils.get_filestr(baseline_paths, image_name)
     if ci_link:
         ci_basefile = ci_link + "/" + suitename + "/" + image_name
         api = Request(method="GET", base_url=ci_basefile)
         resp = api.send()
         if resp.result["status"] != "200":
             raise Exception("picture %s cannot be downloaded" % ci_basefile)
         f = open(image_path, "wb")
         f.write(resp.result["data"])
         f.close()
     else:
         new_image_path = Utils.get_filestr(output_paths, image_name)
         Utils.copy_to_file(new_image_path, image_path)
Пример #4
0
def qr_decode_deprecated(element=None, image_filepath=None, parse_url="http://zxing.org/w/decode"):
    from APIManagement import Request,RequestMode
    try:
        if element:
            element.get_screenshot_as_file("temp_code.png")
            filepath = "temp_code.png"
        elif image_filepath:
            filepath = image_filepath
        else:
            print "No input value"
            return False
        req = Request(base_url=parse_url, method="POST", mode=RequestMode.multi_form,
                      upload_files={"f":filepath})
        req.send()
        data = req.result["data"].split('<pre style="margin:0">')
        if element:
            os.remove(filepath)
        return data[-1].split("</pre>")[0]
    except Exception, e:
        traceback.print_exc()
        print "Decode QRCode meets error %s" % str(e)
        return False
Пример #5
0
def qr_decode(element=None, image_filepath=None, parse_url="http://chorusserver.labs.microstrategy.com:8765/qr_decode"):
    from APIManagement import Request,RequestMode
    try:
        if element:
            element.get_screenshot_as_file("temp_code.png")
            filepath = "temp_code.png"
        elif image_filepath:
            filepath = image_filepath
        else:
            print "No input value"
            return False
        req = Request(base_url=parse_url, method="POST", mode=RequestMode.multi_form,
                      upload_files={"f":filepath})
        req.send()
        if element:
            os.remove(filepath)
        if req.result["status"] == "200":
            return req.result["data"]
        else:
            print "QRDecode Server Error: %s" % req.result["data"]
    except Exception, e:
        traceback.print_exc()
        print "Decode QRCode meets error %s" % str(e)
Пример #6
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"
         )