def list_sites(self): from pysite.ansi import color, error, warn, bright from glob import glob sites_dir = self._rc.g('sites_dir') print("Sites dir:", bright(sites_dir)) dirs = [it for it in glob(os.path.join(sites_dir, '*')) if os.path.isdir(it)] yamls = glob(os.path.join(sites_dir, '*.yaml')) err = [] for y in yamls: if y[:-5] not in dirs: err.append(y) if err: print(error("YAML files with missing site dir:")) for e in err: print("-", e) for sitename in dirs: info = sitemanager.check_site(sites_dir, sitename) print("\nSite " + bright(sitename) + ":") if info['rc'] is not None: print("Settings:") self._print(info['rc']) if info['manager']['rolename'] is not None: print("Manager: " + bright(info['manager']['rolename'])) if info['manager']['principals'] is not None: self._print(info['manager']['principals']) for w in info['warnings']: print(warn(w)) for e in info['errors']: print(error(e))
def create_site(self): from pysite.ansi import color, error, warn, bright from glob import glob if self._args.data == 'help': print(sitemanager.create_site.__doc__) return data = self._parse(self._args.data) sites_dir = self._rc.g('sites_dir') inp = input("Proceed to create a site in {0} (yes/NO)? ".format( bright(sites_dir))) if inp != "yes": print(warn("Aborted")) return info = sitemanager.create_site(pysite.authmgr.const.ROOT_UID, sites_dir, data) for m in info['msgs']: print(m) for w in info['warnings']: print(warn(w)) for e in info['errors']: print(error(e)) if len(info['errors']): raise Exception("Errors occurred. Rolling back database. " + bright("Created files you must remove manually."))