def create_zoo_config(physical_path, config: dict): """ Saves zoo app config to .zoo file :param physical_path: path to app :param config: zoo app config as dict """ logging.debug("physical_path='{0}', settings={1}".format( physical_path, config)) physical_path = os.path.join(physical_path, '.zoo') if "description" in config: config["description"] = Literal(config["description"]) if "find_installed_command" in config: config["find_installed_command"] = Literal( config["find_installed_command"]) if "install_command" in config: config["install_command"] = Literal(config["install_command"]) if "uninstall_command" in config: config["uninstall_command"] = Literal(config["uninstall_command"]) if "upgrade_command" in config: config["upgrade_command"] = Literal(config["upgrade_command"]) YamlHelper.save(config, physical_path)
def create_zoo_config(physical_path, config: dict): """ Saves zoo app config to .zoo file :param physical_path: path to app :param config: zoo app config as dict """ logging.debug("physical_path='{0}', settings={1}".format(physical_path, config)) physical_path = os.path.join(physical_path, '.zoo') YamlHelper.save(config, physical_path)
def make_build(args): """ пройтись рекурсивно по всем каталогам распарсить ямл найти ссылки на файлы скпоировать файлы подправить ссылки добавить в большой ямл """ output = [b"# zoo feed version 1.0\n"] # recursive walk in source folder for root, dirs, files in os.walk(args[0]): for f in files: # skip non-yaml files if not f.lower().endswith(".yaml"): continue # skip. files if f.lower().startswith("."): continue full_path = os.path.join(root, f) # load yaml data = parse_yaml(full_path) # process loaded yaml process_yaml(full_path, data, args[0], args[1]) # save processed yaml to string dumped_yaml = YamlHelper.dump_to_string(data) output.append(dumped_yaml) # save to result file result_path = os.path.join(args[1], "feed.yaml") write_all(result_path, b''.join(output))
def make_build(args): """ пройтись рекурсивно по всем каталогам распарсить ямл найти ссылки на файлы скпоировать файлы подправить ссылки добавить в большой ямл """ output = [] # recursive walk in source folder for root, dirs, files in os.walk(args.src): for f in files: # skip non-yaml files if not f.lower().endswith(".yaml"): continue # skip. files if f.lower().startswith("."): continue full_path = os.path.join(root, f) # load yaml data = parse_yaml(full_path) # process loaded yaml process_yaml(full_path, data, args.src, args.dest) # save processed yaml to string output.append(YamlHelper.dump_to_string(data)) # save to result file result_path = os.path.join(args.dest, "feed.yaml") write_all(result_path, ''.join(output))
def update_zoo_config(self, site_name, virt_path, new_config): """ Writes zoo app config to .zoo file if new_config is empty then just write empty .zoo file (parent app disabled) :param site_name: site name :param virt_path: virtual path :param new_config: zoo app config as dict """ root_path = self.map_path(site_name, virt_path) zoo_config_path = os.path.join(root_path, ".zoo") config = get_zoo_config(zoo_config_path) or {} app = config.get('application') # disabled ability if 'selected-engine' in new_config: new_engine = new_config.get('selected-engine') if 'parameters' in app: app['parameters']['selected-engine'] = new_engine else: app['parameters'] = OrderedDict() app['parameters']['selected-engine'] = new_engine if 'engines' in new_config: engines = new_config.get('engines') app['engines'] = engines if 'locations' in new_config: app['locations'] = new_config['locations'] if "description" in app: app["description"] = Literal(app["description"]) if "find_installed_command" in app: app["find_installed_command"] = Literal( app["find_installed_command"]) if "install_command" in app: app["install_command"] = Literal(app["install_command"]) if "uninstall_command" in app: app["uninstall_command"] = Literal(app["uninstall_command"]) if "upgrade_command" in app: app["upgrade_command"] = Literal(app["upgrade_command"]) # save .zoo YamlHelper.save(config, zoo_config_path)
def update_zoo_config(self, site_name, virt_path, new_config): """ Writes zoo app config to .zoo file if new_config is empty then just write empty .zoo file (parent app disabled) :param site_name: site name :param virt_path: virtual path :param new_config: zoo app config as dict """ root_path = self.map_path(site_name, virt_path) zoo_config_path = os.path.join(root_path, ".zoo") config = get_zoo_config(zoo_config_path) or {} app = config.get('application') # disabled ability if 'selected-engine' in new_config : new_engine = new_config.get('selected-engine') if 'parameters' in app: app['parameters']['selected-engine'] = new_engine else: app['parameters'] = OrderedDict() app['parameters']['selected-engine'] = new_engine if 'engines' in new_config: engines = new_config.get('engines') app['engines'] = engines if 'locations' in new_config: app['locations'] = new_config['locations'] if "description" in app: app["description"] = Literal(app["description"]) if "find_installed_command" in app: app["find_installed_command"] = Literal(app["find_installed_command"]) if "install_command" in app: app["install_command"] = Literal(app["install_command"]) if "uninstall_command" in app: app["uninstall_command"] = Literal(app["uninstall_command"]) if "upgrade_command" in app: app["upgrade_command"] = Literal(app["upgrade_command"]) # save .zoo YamlHelper.save(config, zoo_config_path)
def parse_install_request(self): decoded = YamlHelper.load_from_file(self.filename) result = OrderedDict() for item in decoded: if 'product' in item and 'parameters' in item and item['parameters']: product_name = item['product'] if product_name: product_name = product_name.lower() if not product_name in result: result[product_name] = OrderedDict() for param_name, param_value in item['parameters'].items(): result[product_name][param_name] = param_value return result
def parse_install_request(self): decoded = YamlHelper.load_from_file(self.filename) result = OrderedDict() for item in decoded: if 'product' in item and 'parameters' in item and item[ 'parameters']: product_name = item['product'] if product_name: product_name = product_name.lower() if not product_name in result: result[product_name] = OrderedDict() for param_name, param_value in item['parameters'].items(): result[product_name][param_name] = param_value return result
def update_zoo_config(self, site_name, virt_path, new_config): """ Writes zoo app config to .zoo file if new_config is empty then just write empty .zoo file (parent app disabled) :param site_name: site name :param virt_path: virtual path :param new_config: zoo app config as dict """ root_path = self.map_path(site_name, virt_path) zoo_config_path = os.path.join(root_path, ".zoo") config = get_zoo_config(zoo_config_path) or {} # check engine was updated orig_engine = config.get('engine') new_engine = new_config.get('engine') if orig_engine != new_engine: # update env variables from new engine # application in .zoo app = config.get('application') if app: # engines section engines = app['engines'] # search engine by name engine = search_dict_in_list_by_attr(engines, 'engine', new_engine) if engine: # engine envs new_engine_envs = engine.get('environment_variables') if new_engine_envs: if not 'environment_variables' in new_config: new_config['environment_variables'] = {} new_config['environment_variables'].update(new_engine_envs) # update .zoo with new config config.update(new_config) # save .zoo YamlHelper.save(config, zoo_config_path)
def create_zoo_config(physical_path, config: dict): """ Saves zoo app config to .zoo file :param physical_path: path to app :param config: zoo app config as dict """ logging.debug("physical_path='{0}', settings={1}".format(physical_path, config)) physical_path = os.path.join(physical_path, '.zoo') if "description" in config: config["description"] = Literal(config["description"]) if "find_installed_command" in config: config["find_installed_command"] = Literal(config["find_installed_command"]) if "install_command" in config: config["install_command"] = Literal(config["install_command"]) if "uninstall_command" in config: config["uninstall_command"] = Literal(config["uninstall_command"]) if "upgrade_command" in config: config["upgrade_command"] = Literal(config["upgrade_command"]) YamlHelper.save(config, physical_path)
def format(self): """ Форматирует настройки для вывода строкой как yaml. """ return YamlHelper.dump_to_string(self.get_state()).decode()
def save(self): """ Сохраняет настройки в файл. """ self.assert_exist(os.path.dirname(self.path)) YamlHelper.save(self.source, self.path)