Ejemplo n.º 1
0
    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."
Ejemplo n.º 2
0
    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."
Ejemplo n.º 3
0
 def _writeKey(cls, id, key):
     File.replaceLine(Config.get("phoenix", "authorized_keys"),
                      "--key-id %s" % id, cls._prepareKey(id, key))
Ejemplo n.º 4
0
 def _beforedestroy(cls, key, *a):
     File.replaceLine(Config.get("phoenix", "authorized_keys"), "--key-id %s" % key.id)
Ejemplo n.º 5
0
 def _get_pubkey(self):
     return File.extractKey(Config.get("phoenix", "authorized_keys"), self.id)