def process(profile): configuration = Configuration.Instance() if profile in configuration.fetch_available_sections(): configuration.update_section(ACTIVE_PROFILE_SECTION_NAME, {'primary': profile}) custom_print(f"{profile} active profile set") else: custom_print(f"{profile}: profile does not exist", err=True)
def validate_param(self, __input_columns, headers): if __input_columns is not None and len(__input_columns) > 0: for column in __input_columns: if column not in headers: custom_print(f"Unknown column :{column}", err=True) exit() headers = __input_columns return headers
def process(profile_name, profile_data): configuration = Configuration.Instance() if is_valid_url(profile_data[ACCOUNT_KEY_NAME]): configuration.update_section(profile_name, profile_data) custom_print("profile configured properly") else: custom_print(profile_data[ACCOUNT_KEY_NAME] + " :url is not valid", err=True) exit()
def print_response(self, theme, before=None, after=None): if self.table_to_be_printed(): custom_print_table(self.tables, self.headers, theme) custom_print("---------------------------") custom_print("........customer.............\n") custom_print(" \|/ ") custom_print(" /|\ ") custom_print_table(self.tables_customer, self.headers_customer, theme) else: custom_print(self.response.content.decode('utf-8'))
def get(self, uri, params={}): config_info = _auth_header() r = None try: url = build_url(config_info[ACCOUNT_KEY_NAME], uri, params) r = requests.get(url, params, headers=config_info[API_KEY_NAME]) except requests.exceptions.RequestException as e: custom_print(UNABLE_TO_CONNECT_OR_TIMED_OUT, err=True) exit() return r
def create(self, ctx, payload, resource_id): theme = get_theme(resource_id) if theme is None: custom_print("Invalid theme: " + resource_id, err=True) exit() configuration = Configuration.Instance() configuration.update_section(ACTIVE_THEME_SECTION_NAME, {'theme': resource_id}) custom_print(resource_id + " theme is set") exit()
def create(self, uri, payload): config_info = _auth_header() r = None try: url = build_url(config_info[ACCOUNT_KEY_NAME], uri, {}) r = requests.post(url, data=payload, headers=config_info[API_KEY_NAME]) except requests.exceptions.RequestException as e: custom_print(UNABLE_TO_CONNECT_OR_TIMED_OUT, err=True) exit() return r
def process(self, ctx, operation, payload, resource_id): if operation == ApiOperation.CREATE.value: self.create(ctx=ctx, payload=payload, resource_id=resource_id) elif operation == ApiOperation.FETCH.value: _validate_id(resource_id) self.response = self.get(ctx=ctx, payload=payload, resource_id=resource_id) elif operation == ApiOperation.DELETE.value: _validate_id(resource_id) self.response = self.delete(ctx=ctx, payload=payload, resource_id=resource_id) elif operation == ApiOperation.LIST.value: self.response = self.list(ctx=ctx) elif operation == ApiOperation.UPDATE.value: self.update(ctx=ctx, payload=payload, resource_id=resource_id) else: custom_print(OPERATION_NOT_SUPPORTED, err=True) exit() return self
def export(self, _path, _export_format, _file_name=_DEFAULT_OUTPUT_FILE_NAME, compression=False): try: if Export_Formats.CSV.value.lower() == _export_format.lower(): self.export_csv( path=_path, _file_name=_file_name, compression=_get_compression_options(compression)) elif Export_Formats.EXCEL.value.lower() == _export_format.lower(): self.export_excel(path=_path, _file_name=_file_name) elif Export_Formats.HTML.value.lower() == _export_format.lower(): self.export_html(path=_path, _file_name=_file_name) else: custom_print('format not supported', err=True) exit() custom_print('!!! exported !!') except Exception as e: custom_print(e, err=True)
def delete(self, ctx, payload, resource_id): custom_print('delete : operation is not supported for address', err=True) exit()
def list(self, ctx): custom_print('list : operation is not supported for address', err=True) exit()
def update(self, ctx, payload, resource_id): custom_print("update operation is not supported for themes !!", err=True) exit()
def _validate_id(_resource_id): if _resource_id is None: custom_print(ID_IS_NULL, err=True) exit()
def update(self, ctx, payload, resource_id): custom_print( "feature is not available yet.please contact [ [email protected]] .", err=True) exit()