Пример #1
0
    def create_url_shortcut(self, campaign_url):
        """
        Create a shortcut to open given url

        :rtype: tuple
        :return: Status and output log
        """
        try:
            if os.path.exists(Folders.REPORTS):
                output_path = os.path.join(Folders.REPORTS, self._report_name + ".html")

                if not os.path.isfile(output_path):
                    LOGGER_FWK.info("CREATE_URL_SHORTCUT: Creating url shortcut to campaign result")

                    html_content = "<html>\n"
                    html_content += "<head>\n"
                    html_content += "<meta http-equiv=\"refresh\" content=\"0; URL=%s\">\n" % campaign_url
                    html_content += "</head>\n"
                    html_content += "<body></body>\n"
                    html_content += "</html>"

                    with open(output_path, "w") as fd:
                        fd.write(html_content)

        except Exception as ex:  # pylint: disable=W0703
            error_msg = "CREATE_URL_SHORTCUT: Fail, " + str(ex)
            LOGGER_FWK.error(error_msg)
            return Global.FAILURE, error_msg

        msg = "CREATE_URL_SHORTCUT: Created link to %s" % str(campaign_url)
        return Global.SUCCESS, msg
Пример #2
0
    def load(self):
        """
        Public method which acts as device configuration loader.

        :rtype: dict
        :return: A dict containing all device parameters

        """
        self._load_cli_conf()
        self._load_bench_conf()
        self._load_device_conf()

        # Load the device config from the device catalog
        if not self.device_conf:
            _error(
                "ACS single mode : No device config found for device {0} !".
                format(self._device_model_name),
                AcsConfigException.INVALID_PARAMETER)

        # Override Current DUT parameters from Bench ...
        self._override_parameters_bench()
        # ... and CLI
        self._override_parameters_cli()

        LOGGER_FWK.info('Checking device model integrity...')

        # Asserts All Device Model is valid (Parameters)
        self._validate()

        return self.device_only_params
def add_folder(zip_file, folder):
    for root, _, files in os.walk(folder):
        for f in files:
            full_path = os.path.abspath(os.path.join(root, f))
            path_inside_zip = os.path.relpath(full_path, os.path.abspath(folder))
            LOGGER.info('File added: {0} as {1}'.format(full_path, path_inside_zip))
            zip_file.write(full_path, path_inside_zip)
Пример #4
0
    def _parse_bench_node(self, node):
        """
        Parses XML `Phone` node(s) from Bench Catalog file and maps it into a python structure (dict)

        :return: A dict mapping XML configuration
        :rtype: AttributeDict

        :raise AcsConfigException.INVALID_BENCH_CONFIG: If a (or more) deprecated parameter(s)
            is/are found in a Phone node

        """
        LOGGER_FWK.info(
            'Loading optional device model parameters from CLI and/or BenchConfig '
            'for {0} ({1})...'.format(self._device_name,
                                      self._device_model_name))
        buf_params = AttributeDict()
        # Storing value to avoid recomputing each call
        device_model_name = self.device_model_name

        if device_model_name:
            buf_params["Name"] = device_model_name

        if self.device_conf_filename:
            buf_params["DeviceConfigPath"] = self.device_conf_filename

        # Get phone properties
        for attrs in node.xpath(".//Parameter"):
            name, value, description = attrs.get("name"), attrs.get(
                "value"), attrs.get("description")

            if name in self.PROHIBITIVE_KEYS:
                # Do not allow to override internal keys
                # as it would lead to nasty & unexpected behavior !!
                continue

            # Not supported anymore, raise AcsConfigException.INVALID_BENCH_CONFIG !!
            if name and value:
                buf_params[name] = value
                self._bench_conf_deprecated[name] = (value, description)
            else:
                buf_params.update(attrs.attrib)

        # Report Errors if so
        if self.bench_contains_errors:
            LOGGER_FWK.error(self._report_errors())
            _error(
                'Invalid Bench Parameters format found! {0}'.format(', '.join(
                    self._bench_conf_deprecated.keys())),
                AcsConfigException.INVALID_BENCH_CONFIG)

        # Extracting device modules if so
        buf_params.device_modules = self.extract_device_modules(node)

        return buf_params
def zip_folder(folder, filename):
    try:
        filename = filename + '.zip'
        try:
            zip_file = zipfile.ZipFile(filename,
                                       'w',
                                       compression=zipfile.ZIP_DEFLATED,
                                       allowZip64=True)
        except RuntimeError:  # if ZIP_DEFLATED not support, fallback to default
            zip_file = zipfile.ZipFile(filename, 'w', allowZip64=True)
        LOGGER.info('Create zip file: {0}'.format(filename))
        add_folder(zip_file, folder)
        LOGGER.info("folder {0} has been properly zipped as {1}".format(
            folder, filename))
        zip_file.close()
        status = Global.SUCCESS
        out_file = os.path.abspath(filename)
    except IOError as error:
        LOGGER.error('Cannot create zip file: {0} - {1}'.format(
            filename, error))
        status = Global.FAILURE
        out_file = ""

    if status == Global.SUCCESS:
        LOGGER.info("ZIP FILE: {0}".format(out_file))
    return status, out_file