def get_path_node(self, site_name, virtual_path): """ Returns node of virtual path for server tree """ vdirs = self.get_subvirtualdirectories(site_name, virtual_path) for v in vdirs: if v.path == virtual_path: physical_path = os.path.abspath(v.physical_path) name = os.path.basename(physical_path) zoo_config_path = os.path.join(physical_path, ".zoo") node = { "name": name, "path": combine_virtual_path(site_name, virtual_path), "physical_path": physical_path, "type": "virtual directory", 'is_virtual': True, "config": get_zoo_config(zoo_config_path) } return node physical_path = os.path.abspath(self.map_path(site_name, virtual_path)) name = os.path.basename(physical_path) zoo_config_path = os.path.join(physical_path, ".zoo") node = { "name": name, "path": combine_virtual_path(site_name, virtual_path), "physical_path": physical_path, "type": "directory", "config": get_zoo_config(zoo_config_path) } return node
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 get_site_node(self, site_name): """ Returns site node as dict for server tree """ site = self.get_site(site_name) if site: physical_path = site.default_app["physicalPath"] zoo_config_path = os.path.join(physical_path, ".zoo") node = { "name": site_name, "path": combine_virtual_path(site_name, '/'), "physical_path": physical_path, "type": "site", "config": get_zoo_config(zoo_config_path), 'bindings': site.bindings, 'urls': site.urls } else: node = None return node
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 get_directories(self, site_name, virt_path): """ Returns list of dict with child physical directories of virtual path """ logging.debug("site_name='{0}' virt_path='{1}'".format(site_name, virt_path)) result = [] if site_name is None and virt_path is None: # return list of sites core = Core.get_instance() sites = core.api.os.web_server.get_list_of_sites() for site in sites: # physical_path = self.map_path(site.name, "/") # slow physical_path = site.default_app["physicalPath"] zoo_config_path = os.path.join(physical_path, ".zoo") result.append( { "name": site.name, "path": site.name + '/', "physical_path": physical_path, "type": "site", "config": get_zoo_config(zoo_config_path), "bindings": site.bindings, 'urls': site.urls } ) else: # check site exists test_site = self.get_site(site_name) if test_site: # site exists root_path = self.map_path(site_name, virt_path) sub_dirs = self.get_subdirectories(root_path) for d in sub_dirs: physical_path = os.path.abspath(d) name = os.path.basename(physical_path) zoo_config_path = os.path.join(physical_path, ".zoo") result.append( { "name": name, "path": combine_virtual_path(site_name, combine_virtual_path(virt_path, name)), "physical_path": physical_path, "type": "directory", "config": get_zoo_config(zoo_config_path) } ) vdirs = self.get_subvirtualdirectories(site_name, virt_path) for vdir in vdirs: physical_path = vdir.physical_path name = os.path.basename(vdir.path[:-1]) zoo_config_path = os.path.join(physical_path, ".zoo") self.remove_by_name(result, name) result.append( { "name": name, "path": combine_virtual_path(site_name, vdir.path), "physical_path": physical_path, "type": "virtual directory", 'is_virtual': True, "config": get_zoo_config(zoo_config_path) } ) else: # site not exists result = [] result = sorted(result, key=lambda d: d["name"].lower()) return result
def get_directories(self, site_name, virt_path): """ Returns list of dict with child physical directories of virtual path """ logging.debug("site_name='{0}' virt_path='{1}'".format( site_name, virt_path)) result = [] if site_name is None and virt_path is None: # return list of sites core = Core.get_instance() sites = core.api.os.web_server.get_list_of_sites() for site in sites: # physical_path = self.map_path(site.name, "/") # slow physical_path = site.default_app["physicalPath"] zoo_config_path = os.path.join(physical_path, ".zoo") result.append({ "name": site.name, "path": site.name + '/', "physical_path": physical_path, "type": "site", # "config": get_zoo_config(zoo_config_path), "bindings": site.bindings, 'urls': site.urls }) else: # check site exists test_site = self.get_site(site_name) if test_site: # site exists root_path = self.map_path(site_name, virt_path) sub_dirs = self.get_subdirectories(root_path) for d in sub_dirs: physical_path = os.path.abspath(d) name = os.path.basename(physical_path) zoo_config_path = os.path.join(physical_path, ".zoo") result.append({ "name": name, "path": combine_virtual_path( site_name, combine_virtual_path(virt_path, name)), "physical_path": physical_path, "type": "directory", "config": get_zoo_config(zoo_config_path) }) vdirs = self.get_subvirtualdirectories(site_name, virt_path) for vdir in vdirs: physical_path = vdir.physical_path name = os.path.basename(vdir.path[:-1]) zoo_config_path = os.path.join(physical_path, ".zoo") self.remove_by_name(result, name) result.append({ "name": name, "path": combine_virtual_path(site_name, vdir.path), "physical_path": physical_path, "type": "virtual directory", 'is_virtual': True, "config": get_zoo_config(zoo_config_path) }) else: # site not exists result = [] result = sorted(result, key=lambda d: d["name"].lower()) return result