def __init__(self, config_path_param=None): if config_path_param is None: if os.environ.get('DKCLI_CONFIG_LOCATION') is not None: config_file_location = os.path.expandvars( '${DKCLI_CONFIG_LOCATION}').strip() else: config_file_location = home + "/dev/DKCloudCommand/DKCloudCommand/DKCloudCommandConfig.json" else: config_file_location = config_path_param if not os.path.isfile(config_file_location): raise click.ClickException("Config file '%s' not found" % config_file_location) cfg = DKCloudCommandConfig() if not cfg.init_from_file(config_file_location): s = "Unable to load configuration from '%s'" % config_file_location raise click.ClickException(s) self.dki = DKCloudAPI(cfg) if self.dki is None: s = 'Unable to create and/or connect to backend object.' raise click.ClickException(s) token = self.dki.login() if token is None: s = 'login failed' raise click.ClickException(s)
def __init__(self, config_path_param=None): if config_path_param is None: if os.environ.get('DKCLI_CONFIG_LOCATION') is not None: config_file_location = os.path.expandvars('${DKCLI_CONFIG_LOCATION}').strip() else: config_file_location = home + "/dev/DKCloudCommand/DKCloudCommand/DKCloudCommandConfig.json" else: config_file_location = config_path_param if not os.path.isfile(config_file_location): raise click.ClickException("Config file '%s' not found" % config_file_location) cfg = DKCloudCommandConfig() if not cfg.init_from_file(config_file_location): s = "Unable to load configuration from '%s'" % config_file_location raise click.ClickException(s) self.dki = DKCloudAPI(cfg) if self.dki is None: s = 'Unable to create and/or connect to backend object.' raise click.ClickException(s) token = self.dki.login() if token is None: s = 'login failed' raise click.ClickException(s)
class Backend(object): _short_commands = {} def __init__(self, config_path_param=None): if config_path_param is None: if os.environ.get('DKCLI_CONFIG_LOCATION') is not None: config_file_location = os.path.expandvars( '${DKCLI_CONFIG_LOCATION}').strip() else: config_file_location = home + "/dev/DKCloudCommand/DKCloudCommand/DKCloudCommandConfig.json" else: config_file_location = config_path_param if not os.path.isfile(config_file_location): raise click.ClickException("Config file '%s' not found" % config_file_location) cfg = DKCloudCommandConfig() if not cfg.init_from_file(config_file_location): s = "Unable to load configuration from '%s'" % config_file_location raise click.ClickException(s) self.dki = DKCloudAPI(cfg) if self.dki is None: s = 'Unable to create and/or connect to backend object.' raise click.ClickException(s) token = self.dki.login() if token is None: s = 'login failed' raise click.ClickException(s) @staticmethod def get_kitchen_name_soft(given_kitchen=None): """ Get the kitchen name if it is available. :return: kitchen name or None """ if given_kitchen is not None: return given_kitchen else: in_kitchen = DKCloudCommandRunner.which_kitchen_name() return in_kitchen @staticmethod def check_in_kitchen_root_folder_and_get_name(): """ Ensures that the caller is in a kitchen folder. :return: kitchen name or None """ in_kitchen = DKCloudCommandRunner.which_kitchen_name() if in_kitchen is None: raise click.ClickException( "Please change directory to a kitchen folder.") else: return in_kitchen @staticmethod def get_kitchen_from_user(kitchen=None): in_kitchen = DKCloudCommandRunner.which_kitchen_name() if kitchen is None and in_kitchen is None: raise click.ClickException( "You must provide a kitchen name or be in a kitchen folder.") elif kitchen is not None and in_kitchen is not None: raise click.ClickException( "Please provide a kitchen parameter or change directory to a kitchen folder, not both.\nYou are in Kitchen '%s'" % in_kitchen) if in_kitchen is not None: use_kitchen = in_kitchen else: use_kitchen = kitchen return "ok", use_kitchen @staticmethod def get_recipe_name(recipe): in_recipe = DKRecipeDisk.find_recipe_name() if recipe is None and in_recipe is None: raise click.ClickException( "You must provide a recipe name or be in a recipe folder.") elif recipe is not None and in_recipe is not None: raise click.ClickException( "Please provide a recipe parameter or change directory to a recipe folder, not both.\nYou are in Recipe '%s'" % in_recipe) if in_recipe is not None: use_recipe = in_recipe else: use_recipe = recipe return "ok", use_recipe def set_short_commands(self, commands): short_commands = {} for long_command in commands: if long_command in alias_exceptions: short_commands[long_command] = alias_exceptions[long_command] continue parts = long_command.split('-') short_command = '' for part in parts: if part == 'orderrun': short_command += 'or' else: short_command += part[0] short_commands[long_command] = short_command self._short_commands = short_commands return self._short_commands def get_short_commands(self): return self._short_commands
class Backend(object): _short_commands = {} def __init__(self, config_path_param=None): if config_path_param is None: if os.environ.get('DKCLI_CONFIG_LOCATION') is not None: config_file_location = os.path.expandvars('${DKCLI_CONFIG_LOCATION}').strip() else: config_file_location = home + "/dev/DKCloudCommand/DKCloudCommand/DKCloudCommandConfig.json" else: config_file_location = config_path_param if not os.path.isfile(config_file_location): raise click.ClickException("Config file '%s' not found" % config_file_location) cfg = DKCloudCommandConfig() if not cfg.init_from_file(config_file_location): s = "Unable to load configuration from '%s'" % config_file_location raise click.ClickException(s) self.dki = DKCloudAPI(cfg) if self.dki is None: s = 'Unable to create and/or connect to backend object.' raise click.ClickException(s) token = self.dki.login() if token is None: s = 'login failed' raise click.ClickException(s) @staticmethod def get_kitchen_name_soft(given_kitchen=None): """ Get the kitchen name if it is available. :return: kitchen name or None """ if given_kitchen is not None: return given_kitchen else: in_kitchen = DKCloudCommandRunner.which_kitchen_name() return in_kitchen @staticmethod def check_in_kitchen_root_folder_and_get_name(): """ Ensures that the caller is in a kitchen folder. :return: kitchen name or None """ in_kitchen = DKCloudCommandRunner.which_kitchen_name() if in_kitchen is None: raise click.ClickException("Please change directory to a kitchen folder.") else: return in_kitchen @staticmethod def get_kitchen_from_user(kitchen=None): in_kitchen = DKCloudCommandRunner.which_kitchen_name() if kitchen is None and in_kitchen is None: raise click.ClickException("You must provide a kitchen name or be in a kitchen folder.") elif kitchen is not None and in_kitchen is not None: raise click.ClickException( "Please provide a kitchen parameter or change directory to a kitchen folder, not both.\nYou are in Kitchen '%s'" % in_kitchen) if in_kitchen is not None: use_kitchen = in_kitchen else: use_kitchen = kitchen return "ok", use_kitchen @staticmethod def get_recipe_name(recipe): in_recipe = DKRecipeDisk.find_recipe_name() if recipe is None and in_recipe is None: raise click.ClickException("You must provide a recipe name or be in a recipe folder.") elif recipe is not None and in_recipe is not None: raise click.ClickException( "Please provide a recipe parameter or change directory to a recipe folder, not both.\nYou are in Recipe '%s'" % in_recipe) if in_recipe is not None: use_recipe = in_recipe else: use_recipe = recipe return "ok", use_recipe def set_short_commands(self, commands): short_commands = {} for long_command in commands: if long_command in alias_exceptions: short_commands[long_command] = alias_exceptions[long_command] continue parts = long_command.split('-') short_command = '' for part in parts: if part == 'orderrun': short_command += 'or' else: short_command += part[0] short_commands[long_command] = short_command self._short_commands = short_commands return self._short_commands def get_short_commands(self): return self._short_commands