예제 #1
0
 def send_delete_project_request(self, api_data):
     # type: (dict) -> bool
     """
     Send request to delete Project.
     :param api_data: api data set
     :return: result
     """
     self.headers['token'] = api_data['token']
     try:
         response = requests.delete(url=self.project_url + '/' +
                                    str(api_data['project_id']),
                                    headers=self.headers,
                                    json=self.project_payload)
         if response.status_code == 200:
             return True
         print_line('Delete Project failed. Status code: {0}'.format(
             response.status_code))
         return False
     except requests.exceptions.HTTPError as http_exception:
         print_line('HTTP Error: {0}'.format(http_exception))
         return False
     except requests.exceptions.ConnectionError as connection_exception:
         print_line('Connection error: {0}'.format(connection_exception))
         return False
     except requests.exceptions.Timeout as timeout_exception:
         print_line('Connection timeout: {0}'.format(timeout_exception))
         return False
     except requests.exceptions.RequestException as request_exception:
         print_line('Request exception: {0}'.format(request_exception))
         return False
예제 #2
0
    def collect_data_for_set_yarn_lock_system_path(self, api_data):
        # type: (dict) -> bool
        """
        Create Component Set with packages from yarn.lock file.
        :param api_data: api data set
        :return: result
        """
        components = api_data['components']
        api_data['components'] = []
        if self.components_helper.get_components_yarn_lock(api_data=api_data):
            api_data[
                'platform_number'] = self.web_api.get_platform_number_by_name(
                    api_data=api_data)
            if api_data['platform_number'] == -1:
                print_line("No such platform: {0}".format(
                    api_data['platform']))
                return False

            api_data[
                'project_number'] = self.web_api.get_project_number_by_name(
                    api_data=api_data)
            if api_data['project_number'] == -1:
                print_line("No such project: {0}".format(api_data['project']))
                return False

            api_data['project_url'] = \
            api_data['organization']['platforms'][api_data['platform_number']]['projects'][api_data['project_number']][
                'url']

            for component in api_data['components']:
                components.append(component)
            api_data['components'] = components
            return True
        return False
예제 #3
0
    def save_config_to_file(api_data):
        """
        Save data into config fle in yaml format.
        :param api_data: api data set
        :return: result
        """

        file_name = '.surepatch.yaml'
        file_path = os.path.expanduser('~')
        full_path = os.path.join(file_path, file_name)

        config = dict(
            team=api_data['team'],
            user=api_data['user'],
            password=api_data['password'],
            auth_token=api_data['auth_token'],
            logo=api_data['logo']
        )

        with open(full_path, 'w') as yaml_config_file:
            try:
                yaml.dump(config, yaml_config_file)
                return True

            except yaml.YAMLError as yaml_exception:
                print_line('Config file save in yaml format exception: {0}.'.format(yaml_exception))
                return False

            finally:
                yaml_config_file.close()
예제 #4
0
    def delete_project(self, api_data):
        # type: (dict) -> bool
        """
        Run action: Delete defined Project.
        :param api_data: api data set
        :return: result
        """
        api_data['platform_number'] = self.web_api.get_platform_number_by_name(
            api_data=api_data)
        if api_data['platform_number'] == -1:
            print_line("Platform {0} does not exist.".format(
                api_data['platform']))
            return False

        api_data['project_number'] = self.web_api.get_project_number_by_name(
            api_data=api_data)
        if api_data['project_number'] == -1:
            print_line("Project {0} does not exist.".format(
                api_data['project']))
            return False

        api_data['project_id'] = api_data['organization']['platforms'][
            api_data['platform_number']]['projects'][
                api_data['project_number']]['id']

        return self.web_api.send_delete_project_request(api_data=api_data)
예제 #5
0
 def send_restore_project_request(self, api_data):
     # type: (dict) -> bool
     """
     Send request to restore defined Project from archive.
     :param api_data: api data set
     :return: result
     """
     self.headers['token'] = api_data['token']
     self.project_payload = dict(newProject=dict(
         id=api_data['project_id'],
         url=api_data['project_url'],
         options=dict(updated=datetime.datetime.now().isoformat() + 'Z',
                      state='open',
                      archived=None)))
     try:
         response = requests.put(url=self.project_url,
                                 headers=self.headers,
                                 json=self.project_payload)
         if response.status_code == 200:
             return True
         print_line('Archive Platform failed. Status code: {0}'.format(
             response.status_code))
         return False
     except requests.exceptions.HTTPError as http_exception:
         print_line('HTTP Error: {0}'.format(http_exception))
         return False
     except requests.exceptions.ConnectionError as connection_exception:
         print_line('Connection error: {0}'.format(connection_exception))
         return False
     except requests.exceptions.Timeout as timeout_exception:
         print_line('Connection timeout: {0}'.format(timeout_exception))
         return False
     except requests.exceptions.RequestException as request_exception:
         print_line('Request exception: {0}'.format(request_exception))
         return False
예제 #6
0
    def archive_project(self, api_data):
        # type: (dict) -> bool
        """
        Run action: Archive defined Project.
        :param api_data: api data set
        :return: result
        """
        api_data['platform_number'] = self.web_api.get_platform_number_by_name(
            api_data=api_data)
        if api_data['platform_number'] == -1:
            print_line("Platform {0} does not exist.".format(
                api_data['platform']))
            return False

        api_data['project_number'] = self.web_api.get_project_number_by_name(
            api_data=api_data)
        if api_data['project_number'] == -1:
            print_line("Project {0} does not exist.".format(
                api_data['project']))
            return False

        organization = api_data['organization']
        platforms = organization['platforms']
        platform = platforms[api_data['platform_number']]
        projects = platform['projects']
        project = projects[api_data['project_number']]
        project_id = project['id']
        project_url = project['url']
        api_data['project_id'] = project_id
        api_data['project_url'] = project_url

        return self.web_api.send_archive_project_request(api_data=api_data)
예제 #7
0
    def archive_platform(self, api_data):
        # type: (dict) -> bool
        """
        Run action: Archive defined Platform.
        :param api_data: api data set
        :return: result
        """

        # Get Platform Id by name

        api_data['platform_id'] = self.web_api.get_platform_id_by_name(api_data=api_data)

        if api_data['platform_id'] == -1:
            print_line("Platform {0} does not exist.".format(api_data['platform']))
            return False

        # Get separate parameters for request

        organization = api_data['organization']
        platforms = organization['platforms']
        platform_number = self.web_api.get_platform_number_by_name(api_data=api_data)
        platform = platforms[platform_number]
        platform_url = platform['url']
        api_data['platform_url'] = platform_url

        # Normal response

        return self.web_api.send_archive_platform_request(api_data=api_data)
예제 #8
0
    def select_login_method(self, api_data):
        # type: (dict) -> bool
        """
        Select login method for current session.
        :param api_data: api data set
        :return: result, modify api_data
        """

        # If auth_token or user/password presents in command line

        if api_data['login_method'] == 'token' or api_data[
                'login_method'] == 'username_and_password':
            if api_data['team'] is None or api_data['team'] == '':
                print_line('Token authorization requires --team parameter.')
                return False

            return True

        # If login will be with data from config file

        elif api_data['login_method'] == 'config_file':
            if self.load_config_from_file(api_data=api_data):
                if api_data['auth_token'] is not None and api_data[
                        'auth_token'] != '':
                    api_data['login_method'] = 'token'
                else:
                    api_data['login_method'] = 'username_and_password'
                return True

        # Otherwise

        return False
예제 #9
0
 def send_create_new_component_set_request(self, api_data):
     # type: (dict) -> bool
     """
     Send request to Surepatch server to create new Component Set.
     :param api_data: api data set
     :return:
     """
     self.headers['token'] = api_data['token']
     self.components_payload['set_name'] = api_data['set']
     self.components_payload['project_url'] = api_data['project_url']
     self.components_payload['components'] = api_data['components']
     try:
         response = requests.post(url=self.components_url,
                                  headers=self.headers,
                                  json=self.components_payload)
         if response.status_code == 200:
             return True
         print_line('Create component set failed. Status code: {0}'.format(
             response.status_code))
         return False
     except requests.exceptions.HTTPError as http_exception:
         print_line('HTTP Error: {0}'.format(http_exception))
         return False
     except requests.exceptions.ConnectionError as connection_exception:
         print_line('Connection error: {0}'.format(connection_exception))
         return False
     except requests.exceptions.Timeout as timeout_exception:
         print_line('Connection timeout: {0}'.format(timeout_exception))
         return False
     except requests.exceptions.RequestException as request_exception:
         print_line('Request exception: {0}'.format(request_exception))
         return False
예제 #10
0
    def run_action(self, api_data):
        """
        Main routing method for app actions.
        :param api_data: api data set
        :return: result, modify api_data
        """

        if not self.check_action_type_match(api_data=api_data):
            return False

        if api_data['action'] == Actions.SAVE_CONFIG:
            return self.save_config_to_file(api_data=api_data)

        if not self.select_login_method(api_data=api_data):
            return False

        if not self.action_login_server_success(api_data=api_data):
            return False

        if not self.get_organization_parameters_from_server(api_data=api_data):
            return False

        if api_data['action'] == Actions.CREATE_PLATFORM:
            return self.action_create_new_platform(api_data=api_data)

        elif api_data['action'] == Actions.CREATE_PROJECT:
            return self.action_create_new_project(api_data=api_data)

        elif api_data['action'] == Actions.CREATE_SET:
            return self.action_create_new_set(api_data=api_data)

        elif api_data['action'] == Actions.SHOW_PLATFORMS or \
                api_data['action'] == Actions.SHOW_PROJECTS or \
                api_data['action'] == Actions.SHOW_SET or \
                api_data['action'] == Actions.SHOW_ISSUES:
            return self.action_show_platforms_projects_or_sets(api_data=api_data)

        elif api_data['action'] == Actions.DELETE_PLATFORM:
            return self.action_delete_platform(api_data=api_data)

        elif api_data['action'] == Actions.DELETE_PROJECT:
            return self.action_delete_project(api_data=api_data)

        elif api_data['action'] == Actions.ARCHIVE_PLATFORM:
            return self.action_archive_platform(api_data=api_data)

        elif api_data['action'] == Actions.ARCHIVE_PROJECT:
            return self.action_archive_project(api_data=api_data)

        elif api_data['action'] == Actions.RESTORE_PLATFORM:
            return self.action_restore_platform(api_data=api_data)

        elif api_data['action'] == Actions.RESTORE_PROJECT:
            return self.action_restore_project(api_data=api_data)

        print_line("Unknown action code: {0}.".format(api_data['action']))
        return False
예제 #11
0
    def collect_data_for_set_npm_auto_system_path(self, api_data):
        # type: (dict) -> bool
        """
        Create Component Set with NPM packages, collected from shell command (npm list --json)
        and stored in file, defined in path.
        :param api_data: api data set
        :return: result
        """

        # Get components

        components = api_data['components']
        api_data['components'] = []

        if self.components_helper.get_components_npm_auto_system_path(
                api_data=api_data):

            # Get platform number

            api_data[
                'platform_number'] = self.web_api.get_platform_number_by_name(
                    api_data=api_data)

            if api_data['platform_number'] == -1:
                print_line("No such platform: {0}".format(
                    api_data['platform']))
                return False

            # Get Project number

            api_data[
                'project_number'] = self.web_api.get_project_number_by_name(
                    api_data=api_data)

            if api_data['project_number'] == -1:
                print_line("No such project: {0}".format(api_data['project']))
                return False

            # Get project URL

            api_data['project_url'] = api_data['organization']['platforms'][
                api_data['platform_number']]['projects'][
                    api_data['project_number']]['url']

            for component in api_data['components']:
                components.append(component)

            # Normal output

            api_data['components'] = components
            return True

        # Otherwise

        return False
예제 #12
0
    def collect_data_for_set_gemfile_lock_auto_system_path(self, api_data):
        # type: (dict) -> bool
        """
        Create Component Set with Ruby packages, collected from Gemfile.lock file,
        defined by --file parameter.
        :param api_data:
        :return:
        """

        # Get components

        components = api_data['components']
        api_data['components'] = []

        if self.components_helper.get_components_gemfile_lock_auto_system_path(
                api_data=api_data):

            # Get Platform number

            api_data[
                'platform_number'] = self.web_api.get_platform_number_by_name(
                    api_data=api_data)

            if api_data['platform_number'] == -1:
                print_line("No such platform: {0}".format(
                    api_data['platform']))
                return False

            # Get Project number

            api_data[
                'project_number'] = self.web_api.get_project_number_by_name(
                    api_data=api_data)

            if api_data['project_number'] == -1:
                print_line("No such project: {0}".format(api_data['project']))
                return False

            # Get Project URL

            api_data['project_url'] = api_data['organization']['platforms'][
                api_data['platform_number']]['projects'][
                    api_data['project_number']]['url']

            for component in api_data['components']:
                components.append(component)

            # Normal output

            api_data['components'] = components
            return True

        # Otherwise

        return False
예제 #13
0
    def collect_data_for_set_any_auto_user_path(self, api_data):
        # type: (dict) -> bool
        """
        Create Component Set with different packages, collected in file,
        defined by path with simple multiline format: name=version…
        :param api_data:
        :return:
        """

        # Get components

        components = api_data['components']
        api_data['components'] = []

        if self.components_helper.get_components_any_auto_user_path(
                api_data=api_data):

            # Get Platform number
            api_data[
                'platform_number'] = self.web_api.get_platform_number_by_name(
                    api_data=api_data)

            if api_data['platform_number'] == -1:
                print_line("No such platform: {0}".format(
                    api_data['platform']))
                return False

            # Get Project number

            api_data[
                'project_number'] = self.web_api.get_project_number_by_name(
                    api_data=api_data)

            if api_data['project_number'] == -1:
                print_line("No such project: {0}".format(api_data['project']))
                return False

            # Get Project URL

            api_data['project_url'] = api_data['organization']['platforms'][
                api_data['platform_number']]['projects'][
                    api_data['project_number']]['url']

            for component in api_data['components']:
                components.append(component)

            # Normal output

            api_data['components'] = components
            return True

        # Otherwise

        return False
예제 #14
0
    def collect_data_for_set_any_manual_user_none(self, api_data):
        # type: (dict) -> bool
        """
        Create Component Set with different packages, asked in interactive mode.
        :param api_data: api data set
        :return: result
        """

        # Get components

        components = api_data['components']
        api_data['components'] = []

        if self.components_helper.get_components_any_manual_user_none(
                api_data=api_data):

            # Get Platform number

            api_data[
                'platform_number'] = self.web_api.get_platform_number_by_name(
                    api_data=api_data)

            if api_data['platform_number'] == -1:
                print_line("No such platform: {0}".format(
                    api_data['platform']))
                return False

            # Get Project number

            api_data[
                'project_number'] = self.web_api.get_project_number_by_name(
                    api_data=api_data)

            if api_data['project_number'] == -1:
                print_line("No such project: {0}".format(api_data['project']))
                return False

            # Get Project URL

            api_data['project_url'] = api_data['organization']['platforms'][
                api_data['platform_number']]['projects'][
                    api_data['project_number']]['url']

            for component in api_data['components']:
                components.append(component)

            # Normal output

            api_data['components'] = components
            return True

        # Otherwise

        return False
예제 #15
0
    def collect_data_for_set_php_composer_json_system_path(self, api_data):
        # type: (dict) -> bool
        """
        Create Component Set with packages from PHP Composer.json file.
        :param api_data: api data set
        :return: result
        """

        # Get components

        components = api_data['components']
        api_data['components'] = []

        if self.components_helper.get_components_php_composer_json_system_path(
                api_data=api_data):

            # Get Platform number

            api_data[
                'platform_number'] = self.web_api.get_platform_number_by_name(
                    api_data=api_data)

            if api_data['platform_number'] == -1:
                print_line("No such platform: {0}".format(
                    api_data['platform']))
                return False

            # Get Project number

            api_data[
                'project_number'] = self.web_api.get_project_number_by_name(
                    api_data=api_data)

            if api_data['project_number'] == -1:
                print_line("No such project: {0}".api_data['project'])
                return False

            # Get Project URL

            api_data['project_url'] = api_data['organization']['platforms'][
                api_data['platform_number']]['projects'][
                    api_data['project_number']]['url']

            for component in api_data['components']:
                components.append(component)

            # Normal output

            api_data['components'] = components
            return True

        # Otherwise

        return False
예제 #16
0
    def collect_data_for_set_pip_auto_system_none(self, api_data):
        # type: (dict) -> bool
        """
        Create Component Set with Python PIP packages, collected from shell command.
        :param api_data:
        :return:
        """

        # Get components

        components = api_data['components']
        api_data['components'] = []

        if self.components_helper.get_components_pip_auto_system_none(
                api_data=api_data):

            # Get Platform number

            api_data[
                'platform_number'] = self.web_api.get_platform_number_by_name(
                    api_data=api_data)

            if api_data['platform_number'] == -1:
                print_line("No such platform: {0}".format(
                    api_data['platform']))
                return False

            # Get Project number

            api_data[
                'project_number'] = self.web_api.get_project_number_by_name(
                    api_data=api_data)

            if api_data['project_number'] == -1:
                print_line("No such project: {0}".format(api_data['project']))
                return False

            # Get Project URL

            api_data['project_url'] = api_data['organization']['platforms'][
                api_data['platform_number']]['projects'][
                    api_data['project_number']]['url']

            for component in api_data['components']:
                components.append(component)

            # Normal output

            api_data['components'] = components
            return True

        return False
예제 #17
0
    def restore_project(self, api_data):
        # type: (dict) -> bool
        """
        Run action: Restore Project from Archive.
        :param api_data:
        :return:
        """

        # Get Platform number

        if api_data['platform'] is None or api_data['platform'] == '':
            print_line('Empty platform name.')
            return False

        if api_data['project'] is None or api_data['project'] == '':
            print_line('Empty project name.')
            return False

        # Get archived projects

        if not self.web_api.send_get_archived_projects_request(
                api_data=api_data):
            print_line('There were errors in obtaining archived projects.')
            return False

        api_data['project_id'] = None
        api_data['project_url'] = None
        my_archived_project = dict()

        # Verify archived projects

        for archive_project in api_data['archive_projects']:
            if api_data['project'] == archive_project['name']:
                api_data['project_id'] = archive_project['_id']
                api_data['project_url'] = archive_project['url']
                my_archived_project = archive_project
                break

        if api_data['project_id'] is None:
            print_line("Not such project {0} in archive.".format(
                api_data['project']))
            return False

        if my_archived_project['platform_id']['name'] != api_data['platform']:
            print_line("Defined project {0} not in defined platform "
                       "{1}.".format(api_data['project'],
                                     api_data['platform']))
            return False

        # Sent Restore request

        return self.web_api.send_restore_project_request(api_data=api_data)
예제 #18
0
 def get_request_url(self, server, url):
     # type: (str, str) -> str
     """
     Get request url, depends from server type: dev or prod
     :param server: dev or prod server string
     :param url: url to join
     :return: joined url
     """
     print_line('Send request to "{}" server...'.format(server))
     if server == 'prod':
         return self.base_url_prod + url
     else:
         return self.base_url_dev + url
예제 #19
0
    def delete_platform(self, api_data):
        # type: (dict) -> bool
        """
        Run action: Delete defined Platform.
        :param api_data: api data set
        :return: result
        """
        api_data['platform_id'] = self.web_api.get_platform_id_by_name(api_data=api_data)
        if api_data['platform_id'] == -1:
            print_line("Platform {0} does not exist.".format(api_data['platform']))
            return False

        return self.web_api.send_delete_platform_request(api_data=api_data)
예제 #20
0
    def load_config_from_file(self, api_data):
        """
        Load data from config file in yaml format.
        :param api_data: api data set
        :return: result
        """

        file_name = '.surepatch.yaml'
        file_path = os.path.expanduser('~')
        full_path = os.path.join(file_path, file_name)

        if not os.path.isfile(full_path):
            print_line('Config file does not exist: ~/{0}.'.format(file_name))
            print_line('Create config file first with parameter --action=save_config.')
            return False

        components_helper = ComponentsHelper()
        enc = components_helper.define_file_encoding(full_path)

        if enc == 'undefined':
            print_line('Undefined file encoding. Please, use utf-8 or utf-16.')
            return False

        with open(full_path, 'r') as yaml_config_file:
            try:
                config = yaml.load(yaml_config_file)

                if 'team' not in config:
                    config['team'] = None

                api_data['team'] = config['team']

                if 'user' not in config:
                    config['user'] = None

                api_data['user'] = config['user']

                if 'password' not in config:
                    config['password'] = None

                api_data['password'] = config['password']

                if 'auth_token' not in config:
                    config['auth-token'] = None

                api_data['auth_token'] = config['auth_token']

                if 'logi' not in config:
                    config['logo'] = 'off'

                api_data['logo'] = config['logo']

                return True

            except yaml.YAMLError as yaml_exception:
                print_line('Get an exception while read config file: {0}.'.format(yaml_exception))
                return False

            finally:
                yaml_config_file.close()
예제 #21
0
    def create_project_validate(self, api_data):
        # type: (dict) -> bool
        """
        Run action: CREATE New Project in different cases.
        :return: result, modify api_data
        """
        if api_data['platform'] is None or api_data['platform'] == '':
            print_line('Empty platform name.')
            return False

        if api_data['project'] is None or api_data['project'] == '':
            print_line('Empty project name.')
            return False

        platforms = self.get_my_platforms(api_data=api_data)

        if api_data['platform'] not in platforms:
            print_line("Platform {0} does not exists.".format(
                api_data['platform']))
            return False

        projects = self.get_my_projects(api_data=api_data)

        if api_data['project'] in projects:
            print_line("Project {0} already exists.".format(
                api_data['project']))
            return False

        return True
예제 #22
0
 def select_login_method(self, api_data):
     # type: (dict) -> bool
     if api_data['login_method'] == 'token' or api_data['login_method'] == 'username_and_password':
         if api_data['team'] is None or api_data['team'] == '':
             print_line('Token authorization requires --team parameter.')
             return False
         return True
     elif api_data['login_method'] == 'config_file':
         if self.load_config_from_file(api_data=api_data):
             if api_data['auth_token'] is not None and api_data['auth_token'] != '':
                 api_data['login_method'] = 'token'
             else:
                 api_data['login_method'] = 'username_and_password'
             return True
     return False
예제 #23
0
    def action_show_projects(self, api_data):
        # type: (dict) -> bool
        """
        Print existing project for defined Platform.
        :param api_data: api data set
        :return: result
        """
        projects = []

        if 'organization' not in api_data:
            print_line('Organization info error.')
            return False

        if 'platforms' not in api_data['organization']:
            print_line('Platform info error.')
            return False

        if len(api_data['organization']['platforms']) == 0:
            print_line('You have not Platforms.')
            return False

        platform_number = self.web_api.get_platform_number_by_name(
            api_data=api_data)

        if platform_number == -1:
            print_line("No such platform: {0}.".format(api_data['platform']))
            return False

        if len(api_data['organization']['platforms'][platform_number]
               ['projects']) == 0:
            print_line('You have not Projects.')
            return False

        for project in api_data['organization']['platforms'][platform_number][
                'projects']:
            projects.append({
                'name': project['name'],
                'description': 'default project'
            })

        if 'file' not in api_data:
            api_data['file'] = None

        print_projects(projects=projects,
                       title=api_data['platform'],
                       filename=api_data['file'])

        return True
예제 #24
0
    def create_platform_validate(api_data):
        # type: (dict) -> bool
        """
        Validate parameters/
        :param api_data:
        :return:
        """
        if api_data['platform'] is None or api_data['platform'] == '':
            print_line('Empty platform name, please use --platform flag.')
            return False

        if api_data['description'] is None or api_data['description'] == '':
            print_line('Empty platform description. Change description to "default platform".')
            api_data['description'] = "default platform"

        return True
예제 #25
0
def main():
    """
    Application main function.
    :return: exit code
    """

    arguments = create_parser()

    # Collect app command line parameters into data set

    api_data = dict(
        action=arguments.action,
        team=arguments.team,
        user=arguments.user,
        password=arguments.password,
        file=arguments.file,
        target=arguments.target,
        method=arguments.method,
        format=arguments.format,
        platform=arguments.platform,
        description=arguments.description,
        project=arguments.project,
        set=arguments.set,
        os_type=get_os_platform(),
        os_version=get_os_version(get_os_platform()),
        os_sp=get_os_sp(get_os_platform()),
        os_release=get_os_release(),
        os_machine=get_os_machine(),
        components=[],
        auth_token=arguments.auth_token,
        logo=arguments.logo,
        logging=arguments.logging,
        server=arguments.server
    )

    if arguments.logo is not None:
        if arguments.logo == 'on':
            print_logo()

    # Run application with data set

    if surepatch_api.run_action(api_data=api_data):
        print_line('Complete successfully.')
        return 0
    else:
        print_line('Complete with errors.')
        return 1
예제 #26
0
    def collect_data_for_set_node_modules_system_path(self, api_data):
        components = api_data['components']
        api_data['components'] = []
        if self.components_helper.get_components_node_modules(
                api_data=api_data):
            # Get Platform number

            api_data[
                'platform_number'] = self.web_api.get_platform_number_by_name(
                    api_data=api_data)

            if api_data['platform_number'] == -1:
                print_line("No such platform: {0}".format(
                    api_data['platform']))
                return False

            # Get Project number

            api_data[
                'project_number'] = self.web_api.get_project_number_by_name(
                    api_data=api_data)

            if api_data['project_number'] == -1:
                print_line("No such project: {0}".format(api_data['project']))
                return False

            # Get Project URL

            api_data['project_url'] = \
                api_data['organization']['platforms'][api_data['platform_number']]['projects'][
                    api_data['project_number']][
                    'url']

            for component in api_data['components']:
                components.append(component)

            # Normal output

            api_data['components'] = components
            return True

            # Otherwise

        return False
예제 #27
0
    def restore_platform(self, api_data):
        # type: (dict) -> bool
        """
        Run action: restore Platform from Archive.
        :param api_data: api data set
        :return: result
        """
        if api_data['platform'] is None or api_data['platform'] == '':
            print_line('Empty platform name.')
            return False

        if not self.web_api.send_get_archived_platforms_request(api_data=api_data):
            print_line('There were errors in obtaining archived platforms.')
            return False

        api_data['platform_id'] = None
        api_data['platform_url'] = None

        for archive_platform in api_data['archive_platforms']:
            if api_data['platform'] == archive_platform['name']:
                api_data['platform_id'] = archive_platform['_id']
                api_data['platform_url'] = archive_platform['url']
                break

        if api_data['platform_id'] is None:
            print_line("Not such platform {0} in archive.".format(api_data['platform']))
            return False

        return self.web_api.send_restore_platform_request(api_data=api_data)
예제 #28
0
    def action_show_platforms(api_data):
        # type: (dict) -> bool
        """
        Print existing platforms.
        :param api_data: api data set
        :return: result
        """
        platforms = []

        if 'organization' not in api_data:
            print_line('Organization info error.')
            return False

        if 'platforms' not in api_data['organization']:
            print_line('Platform info error.')
            return False

        if len(api_data['organization']['platforms']) == 0:
            print_line('You have not Platforms.')
            return False

        for platform in api_data['organization']['platforms']:
            platforms.append({'name': platform['name'], 'description': platform['description']})

        print_platforms(platforms=platforms, title="Platforms", filename=api_data['file'])

        return True
예제 #29
0
    def create_platform_validate(api_data):
        # type: (dict) -> bool
        """
        Validate parameters.
        :param api_data: api data set
        :return: result
        """

        # Validate Platform

        if 'platform' not in api_data:
            print_line('There are no --platform parameter given.')
            return False

        if api_data['platform'] is None or api_data['platform'] == '':
            print_line('Empty platform name, please use --platform flag.')
            return False

        # Validate description

        if 'description' not in api_data:
            api_data['description'] = None

        if api_data['description'] is None or api_data['description'] == '':
            print_line('Empty platform description. Change description to "default platform".')
            api_data['description'] = "default platform"

        # Normal output

        return True
예제 #30
0
    def action_show_set(self, api_data):
        # type: (dict) -> bool
        """
        Print current Component set for defined Platform/Project.
        :param api_data: api data set
        :return: result
        """
        my_set = self.components_helper.get_current_set_name(api_data=api_data)

        if my_set[0] is None:
            print_line('Get set name error.')
            return False

        print_line('Current component set: {0}.'.format(my_set[0]))

        components = self.components_helper.get_current_component_set(
            api_data=api_data)[0]['components']

        if components[0] is None:
            print_line('Get component set error.')
            return False

        if 'file' not in api_data:
            api_data['file'] = None

        print_components(components=components,
                         title=api_data['platform'] + '/' +
                         api_data['project'],
                         filename=api_data['file'])

        return True