示例#1
0
def get_documentation(step):
    if "'params'" in step:
        doc = base_utils.parse_string(string = step,
                                      left_separator = "'doc'",
                                      right_separator = "'params'")
    else:
        doc = base_utils.parse_string(string = step,
                                      left_separator = "'doc'",
                                      right_separator = "'python_path'")
    doc = doc.strip(":").strip().strip(",").strip("'")
    two_spaces = True
    while two_spaces:
        if "  " in doc:
            doc = doc.replace("  ", " ")
        else:
            two_spaces = False
    description = base_utils.parse_string(string = doc,
                                          left_separator = "description:",
                                          right_separator = "usage:")
    description = description.replace("\\n", "").strip()
    if len(description) < 1:
        description = "Unavailable"
    usage = base_utils.parse_string(string = doc,
                                    left_separator = "usage:",
                                    right_separator = "tags:")
    usage = usage.replace("\\n", "").strip()
    if len(usage) < 1:
        usage = "Unavailable"
    tags = base_utils.parse_string(string = doc,
                                   left_separator = "tags:")
    tags = tags.replace("\\n", "").strip()
    if len(tags) < 1:
        tags = "Unavailable"
    return description, usage, tags
示例#2
0
 def do(self):
     super(self.__class__, self).do()
     self.ignore_errors = self.ignore_errors[self.platform]
     if self.dmesg_file == None:
         hal_dmesg = self.adb_connection.parse_dmesg(grep_for="HAL")
         hal_elogcat = self.adb_connection.parse_logcat(grep_for="E/HAL")
         hal_ilogcat = self.adb_connection.parse_logcat(grep_for="I/HAL")
     else:
         self.dmesg_file = os.path.join(self.file_path, self.dmesg_file)
         self.logcat_file = os.path.join(self.file_path, self.logcat_file)
         with open(self.dmesg_file, "r") as d_file:
             hal_dmesg = base_utils.parse_string(d_file.read(),
                                                 grep_for="HAL")
         with open(self.logcat_file, "r") as l_file:
             hal_elogcat = base_utils.parse_string(l_file.read(),
                                                   grep_for="E/HAL")
             hal_ilogcat = base_utils.parse_string(l_file.read(),
                                                   grep_for="I/HAL")
     if "\r\n" in hal_dmesg:
         dmesg_new_line = "\r\n"
     else:
         dmesg_new_line = "\n"
     if "\r\n" in hal_elogcat:
         logcat_new_line = "\r\n"
     else:
         logcat_new_line = "\n"
     self.hal_dmesg_lines = hal_dmesg.split(dmesg_new_line)
     self.hal_elogcat_lines = hal_elogcat.split(logcat_new_line)
     self.hal_ilogcat_lines = hal_ilogcat.split(logcat_new_line)
示例#3
0
def get_category(step):
    category = base_utils.parse_string(string = step,
                                       left_separator = "'category'",
                                       right_separator = "'class'")
    category = category.strip(":").strip().strip(",").strip("'")
    py_path = base_utils.parse_string(string = step,
                                      left_separator = "'python_path'",
                                      right_separator = "'step'")
    py_path = py_path.strip(":").strip().strip(",").strip("'")

    if category not in categories:
        query = "INSERT INTO `testlib`.`categories` (`id`,`name`,`python_path`) VALUES (NULL,'" + category + "','" + py_path + "')"
        cursor.execute(query)
        categories.append(category)
    return category
示例#4
0
    def parse_cmd_output(self,
                         cmd,
                         grep_for=None,
                         multiple_grep=None,
                         left_separator=None,
                         right_separator=None,
                         strip=False,
                         dont_split=False,
                         timeout=60,
                         ignore_error=False):
        """
        By default gets the output from adb shell command
        Can grep for strings or cut for delimiters
        """
        # tmp file name should be uniq to allow getting output from
        # multiple devices at the same time

        tmp_file_name = "tmp_{0}_{1}_{2}".format(
            "5037" if self.port == None else str(self.port),
            self.serial.split(":")[0], str(int(round(time.time() * 1000000))))
        self.run_cmd(cmd,
                     soutfile=tmp_file_name,
                     timeout=timeout,
                     dont_split=dont_split,
                     ignore_error=ignore_error)
        with open(tmp_file_name, 'r') as f:
            string = f.read()
            string = base_utils.parse_string(string, \
                        grep_for = grep_for, multiple_grep = multiple_grep, \
                        left_separator = left_separator, \
                        right_separator = right_separator, strip = strip)
        os.remove(tmp_file_name)
        return string
示例#5
0
 def do(self):
     super(self.__class__, self).do()
     if self.bootchart_file == None:
         string_total = self.adb_connection.parse_file(\
             "/data/local/bootchart.svg")
     else:
         self.bootchart_file = os.path.join(self.file_path,
                                            self.bootchart_file)
         with open(self.bootchart_file, "r") as b_file:
             string_total = b_file.read()
     string_hald = base_utils.parse_string(string_total, grep_for="hald")
     self.hald_time = hal_utils.get_runtime(string_hald)
     self.total_time = hal_utils.get_runtime(string_total)
示例#6
0
def get_step_types(step):
    st_types = []
    step_type = base_utils.parse_string(string = step,
                                        left_separator = "'step'")
    step_type = step_type.strip(":").strip().strip("}").strip("'")
    if step_type not in types:
        step_types = step_type.split(",")
        for st in step_types:
            if st.strip() not in types:
                query = "INSERT INTO `testlib`.`types` (`id`,`name`) VALUES (NULL,'" + st.strip() + "')"
                cursor.execute(query)
                types.append(st.strip())
            st_types.append(st.strip())
    return st_types
示例#7
0
 def parse_cmd_output(self,
                      cmd,
                      grep_for=None,
                      multiple_grep=None,
                      left_separator=None,
                      right_separator=None,
                      strip=False,
                      to_stderr=False):
     """
     By default gets the output from adb shell command
     Can grep for strings or cut for delimiters
     """
     stdout, stderr = self.run_cmd(cmd)
     if to_stderr:
         stdout = stderr
     string = base_utils.parse_string(stdout, grep_for=grep_for, multiple_grep=multiple_grep,
                                      left_separator=left_separator, right_separator=right_separator, strip=strip)
     return string
示例#8
0
def get_params(step):
    params = base_utils.parse_string(string = step,
                                     left_separator = "'params'",
                                     right_separator = "'python_path'")
    params = params.strip(":").strip().strip(",").strip("'")
    parameters = []
    for param in params.split(","):
        if "=" in param:
            name, value = param.split("=")
            name = name.strip()
            value = value.strip().strip("\"")
            if value == "None":
                param_type = None
            elif value.isdigit():
                param_type = "number"
            elif value == "True" or value == "False":
                param_type = "boolean"
            elif re.match("^{.*}$", value) != None:
                param_type = "dict"
            elif re.match("^\[.*\]$", value) != None:
                param_type = "array"
            else:
                param_type = "string"
        else:
            name = param.strip()
            value = None
            param_type = None
        if param_type == None:
            if name == "self" or name == "**kwargs":
                continue
            elif "view_to_check" in name or name == "view_to_find" or name == "confirm_view":
                param_type = "view"
            elif "grep" in name:
                param_type = "string"
            elif "command" in name or "cmd" in name:
                param_type = "string"
            elif "serial" in name:
                param_type = "string"
            elif "path" in name:
                param_type = "string"
            elif "host" in name or "pass" in name or "user" in name:
                param_type = "string"
            elif "name" in name:
                param_type = "string"
            elif "url" in name:
                param_type = "string"
            elif "state" in name:
                param_type = "string"
            elif "folder" in name or "local" == name or "remote" == name or "destination" in name or name == "inode":
                param_type = "string"
            elif "language" in name or "text" in name:
                param_type = "string"
            elif name == "platform":
                param_type = "string"
            elif name == "ip" or name == "dev" or name == "dut" or name == "dev_to_find":
                param_type = "string"
            elif name == "db" or name == "table":
                param_type = "string"
            elif name == "out_file":
                param_type = "string"
            elif "timeout" in name or "_time" in name:
                param_type = "number"
            elif name == "x" or name == "y" or name == "sx" or name == "sy" or name == "ex" or name == "ey":
                param_type = "number"
            elif name == "tab_no":
                param_type = "number"
            elif name == "position":
                param_type = "number"
            elif "columns" in name or "value" in name or "developer_options" in name or "_list" in name:
                param_type = "array"
            else:
                param_type = "string"
        parameter = {}
        parameter["name"] = name
        parameter["value"] = value
        parameter["type"] = param_type
        parameters.append(parameter)
    return parameters
示例#9
0
def get_name(step):
    name = base_utils.parse_string(string = step,
                                   left_separator = "'class'",
                                   right_separator = "'doc'")
    name = name.strip(":").strip().strip(",").strip("'")
    return name