def init(self): if Config.get("phoenix", "initialized") == "True": raise AdminException("Already initialized.") logging.info("Defining variables for init ...") user = self.args.git_user base = path.join(self.args.base_dir, user) repo = path.join(base, self.args.repository_dir) tar = path.join(base, self.args.tarball_dir) ssh = path.join(base, ".ssh") auth_keys = path.join(ssh, "authorized_keys") admin_repo = self.args.admin_repo email = self.args.admin_email name = self.args.admin_name username = self.args.admin_username sql = self.args.sql_connect or "sqlite://%s" % path.join(base, "phoenix.db") logging.info("Checking for permission to write the config file ...") if not File.writePermission(Config.get("CONF_FILE")): raise AdminException("You don't have permission to write the config file `%s' ..." % Config.get("CONF_FILE")) if not SysUser.exists(self.args.git_user): logging.info("Creating user `%s' ... " % user) SysUser.create(user, base) Config.set("phoenix", "user", user) Config.set("phoenix", "base", base) else: raise AdminException("The user `%s' already exists." % user) logging.info("Saving SQL connection string `%s' ..." % sql) Config.set("phoenix", "sql_connect", sql) Config.set("phoenix", "initialized", True) Config.set("phoenix", "authorized_keys", auth_keys) __import__("os").setgid(__import__("pwd").getpwnam(user).pw_gid) __import__("os").setuid(__import__("pwd").getpwnam(user).pw_uid) logging.info("Checking for permission to write the config file as `%s' ..." % user) if not File.writePermission(Config.get("CONF_FILE")): raise AdminException("You don't have permission to write the config file `%s' ..." % Config.get("CONF_FILE")) from sqlobject import connectionForURI, sqlhub connection = connectionForURI(Config.get("phoenix", "sql_connect")) sqlhub.processConnection = connection self._sqlChanges() self._createDirectoryStructure(repo, tar, ssh) logging.info("Creating `%s' ..." % auth_keys) File.touch(auth_keys) logging.info("Saving admin user information `%s' and `%s' in database ..." % (name, email)) admin = Member(username=username, email=email, name=name) if admin_repo: logging.info("Initializing development repository at `%s/phoenix.git' ..." % repo) admin.addRepository("Phoenix Server Management", "phoenix.git") print "Done."
def _createDirectoryStructure(self, repo, tar, ssh): if not path.exists(repo): logging.info("Creating repository dir at `%s' ..." % repo) mkdir(repo) else: logging.warning("The folder `%s' already exists." % repo) Config.set("phoenix", "repository_dir", repo) if not path.exists(tar): logging.info("Creating tarball dir at `%s' ..." % tar) mkdir(tar) else: logging.warning("The folder `%s' already exists." % tar) Config.set("phoenix", "tarball_dir", tar) if not path.exists(ssh): logging.info("Creating ssh dir at `%s' ..." % ssh) mkdir(ssh, 0700) else: logging.warning("The folder `%s' already exists." % ssh) Config.set("phoenix", "ssh_dir", ssh)
def init(self): if Config.get("phoenix", "initialized") == "True": raise AdminException("Already initialized.") logging.info("Defining variables for init ...") user = self.args.git_user base = path.join(self.args.base_dir, user) repo = path.join(base, self.args.repository_dir) tar = path.join(base, self.args.tarball_dir) ssh = path.join(base, ".ssh") auth_keys = path.join(ssh, "authorized_keys") admin_repo = self.args.admin_repo email = self.args.admin_email name = self.args.admin_name username = self.args.admin_username sql = self.args.sql_connect or "sqlite://%s" % path.join( base, "phoenix.db") logging.info("Checking for permission to write the config file ...") if not File.writePermission(Config.get("CONF_FILE")): raise AdminException( "You don't have permission to write the config file `%s' ..." % Config.get("CONF_FILE")) if not SysUser.exists(self.args.git_user): logging.info("Creating user `%s' ... " % user) SysUser.create(user, base) Config.set("phoenix", "user", user) Config.set("phoenix", "base", base) else: raise AdminException("The user `%s' already exists." % user) logging.info("Saving SQL connection string `%s' ..." % sql) Config.set("phoenix", "sql_connect", sql) Config.set("phoenix", "initialized", True) Config.set("phoenix", "authorized_keys", auth_keys) __import__("os").setgid(__import__("pwd").getpwnam(user).pw_gid) __import__("os").setuid(__import__("pwd").getpwnam(user).pw_uid) logging.info( "Checking for permission to write the config file as `%s' ..." % user) if not File.writePermission(Config.get("CONF_FILE")): raise AdminException( "You don't have permission to write the config file `%s' ..." % Config.get("CONF_FILE")) from sqlobject import connectionForURI, sqlhub connection = connectionForURI(Config.get("phoenix", "sql_connect")) sqlhub.processConnection = connection self._sqlChanges() self._createDirectoryStructure(repo, tar, ssh) logging.info("Creating `%s' ..." % auth_keys) File.touch(auth_keys) logging.info( "Saving admin user information `%s' and `%s' in database ..." % (name, email)) admin = Member(username=username, email=email, name=name) if admin_repo: logging.info( "Initializing development repository at `%s/phoenix.git' ..." % repo) admin.addRepository("Phoenix Server Management", "phoenix.git") print "Done."