示例#1
0
    def log_event(self, command=None, duration_seconds=None, exception=None):
        self._compute_environment()

        headers = {
            'Content-Type': 'application/json'
        }
        payload = {
            'property': 'mason-cli',
            'event': 'invoke',
            'environment': self.environment,
            'cli': {
                'version': __version__,
                'command': command,
                'instance': self.instance,
                'session': self._sanitized_session(),
                'log_level': self.config.logger.level,
                'exception': exception.__class__.__name__ if exception else None,
                'flags': list({k: v for k, v in
                               click.get_current_context().params.items() if v}.keys()),
                'ci': self.ci,
                'duration': duration_seconds
            }
        }

        url = build_url(self.config.endpoints_store, 'analytics_url')
        try:
            self.handler.post(url, headers=headers, json=payload)
        except Exception as e:
            self.config.logger.debug(e)
示例#2
0
 def __init__(self, device, config: Config):
     self._device = device
     self._auth = {
         'Authorization': 'Basic {}'.format(config.auth_store['api_key'])
     }
     self._progress = None
     self._cur_bytes = 0
     self._url = build_url(config.endpoints_store, 'xray_url') + "/{}/{}"
     self._logger = config.logger
     self._adbkey = os.path.join(expanduser("~"), '.android', 'adbkey')
     self._awaiting_auth = False
示例#3
0
    def _compute_environment(self):
        if self.ci and self.environment:
            return

        self.ci = True if os.getenv("CI") else False

        sample_url = build_url(self.config.endpoints_store, 'deploy_url')
        if 'development' in sample_url:
            self.environment = 'development'
        elif 'staging' in sample_url:
            self.environment = 'staging'
        else:
            self.environment = 'production'
示例#4
0
    def build(self):
        self.config.logger.debug('Starting build for {}:{}...'.format(
            self.project, self.version))

        build = self.config.api.start_build(self.project, self.version,
                                            self.mason_version)

        project_url = build_url(self.config.endpoints_store,
                                'console_projects_url', 'platform_url_base')
        self.config.logger.info(
            inspect.cleandoc("""
            Build queued for OS Config '{0}'.
            You can see the status of your build at
            {1}/{0}
        """.format(self.project, project_url)))

        if self.block:
            self._wait_for_completion(build)
示例#5
0
    def _choose_project(self):
        projects = self.config.api.get_projects() or []

        options = ['Create new project']
        for project in projects:
            options.append(project.get('name'))

        option, index = self.config.interactivity.pick(
            options, 'Choose an existing Mason project or create a new one:')

        if index == 0:
            id = click.prompt('Enter your new project ID')

            base_url = build_url(self.config.endpoints_store,
                                 'console_create_url', 'platform_url_base')
            url = base_url + '/project?name={}'.format(id)
            self.config.interactivity.open(url)

            option = id

        return option
示例#6
0
    def log_config(self, config):
        self._compute_environment()

        try:
            mapped_configs = self._mapped_config(config)
        except Exception as e:
            self.config.logger.debug(e)
            return

        headers = {
            'Content-Type': 'application/json'
        }
        payload = {
            'property': 'configs',
            'event': 'register',
            'environment': self.environment,
            'configs2': mapped_configs
        }

        url = build_url(self.config.endpoints_store, 'analytics_url')
        try:
            self.handler.post(url, headers=headers, json=payload)
        except Exception as e:
            self.config.logger.debug(e)
示例#7
0
 def _get_base_url(self, name: str):
     return build_url(self.endpoints_store, name)