コード例 #1
0
    def removeuser(self):
        logging.info("Defining email and username ...")
        email = self.args.email
        username = self.args.username

        member = self._getMemberByUsernameOrEmail(username, email, True)

        logging.info("Removing the user from the database ...")
        member.destroySelf()

        print "Done."
コード例 #2
0
 def removeuser(self):
     logging.info("Defining email and username ...")
     email = self.args.email
     username = self.args.username
     
     member = self._getMemberByUsernameOrEmail(username, email, True)
     
     logging.info("Removing the user from the database ...")
     member.destroySelf()
     
     print "Done."
コード例 #3
0
 def adduser(self):
     logging.info("Defining username, name and email ...")
     username = self.args.username
     name = self.args.name
     email = self.args.email
     
     dummy = self._getMemberByUsernameOrEmail(username, email)
     
     logging.info("Creating and saving the new user ...")
     Member(username=username, email=email, name=name)
     
     print "Done."
コード例 #4
0
    def adduser(self):
        logging.info("Defining username, name and email ...")
        username = self.args.username
        name = self.args.name
        email = self.args.email

        dummy = self._getMemberByUsernameOrEmail(username, email)

        logging.info("Creating and saving the new user ...")
        Member(username=username, email=email, name=name)

        print "Done."
コード例 #5
0
 def _getRepositoryByNameOrPath(self, member, name, path, must=False):
     repo = None
     logging.info("Trying to find a repository by name or path ...")
     if name:
         repo = member.repositoryByName(name)
     if path:
         repo = member.repositoryByPath(path)
         
     if must and not repo:
         raise AdminException("Repository with name `%s' or path `%s' can not be found." % (name, path))
     elif not must and repo:
         raise AdminException("The repository `%s' already exists." % repo.name)
         
     return repo
コード例 #6
0
    def removerepo(self):
        logging.info("Defining repository name, email and username ...")
        email = self.args.email
        username = self.args.username
        name = self.args.repository_name
        path = self.args.repository_path

        member = self._getMemberByUsernameOrEmail(username, email, True)
        repo = self._getRepositoryByNameOrPath(member, name, path, True)

        logging.info("Removing the repository ...")
        repo.destroySelf()

        print "Done."
コード例 #7
0
    def removerepo(self):
        logging.info("Defining repository name, email and username ...")
        email = self.args.email
        username = self.args.username
        name = self.args.repository_name
        path = self.args.repository_path

        member = self._getMemberByUsernameOrEmail(username, email, True)
        repo = self._getRepositoryByNameOrPath(member, name, path, True)
        
        logging.info("Removing the repository ...")
        repo.destroySelf()
        
        print "Done."
コード例 #8
0
 def _getMemberByUsernameOrEmail(self, username, email, must=False):        
     logging.info("Trying to find the user by username or email ...")
     member = None
     try:
         if username:
             member = Member.selectBy(username=username)[0]
         if email:
             member = Member.selectBy(email=email)[0]
     except IndexError:
         if must and not member:
             raise AdminException("The user can not be found (username: `%s', email: `%s')" % (username, email))
     if not must and member:
         raise AdminException("The user `%s' with email `%s' already exists." % (member.username, member.email))
     
     return member
コード例 #9
0
 def addhook(self):
     logging.info("Defining username, email, repository name, hook and command ...")
     username = self.args.username
     email = self.args.email
     name = self.args.repository_name
     path = self.args.repository_path
     hook = self.args.hook
     command = self.args.command
     
     member = self._getMemberByUsernameOrEmail(username, email, True)
     repo = self._getRepositoryByNameOrPath(member, name, path, True)
     
     logging.info("Save new hook in database ...")
     repo.addHook(hook, command)
     
     print "Done."
コード例 #10
0
    def _getRepositoryByNameOrPath(self, member, name, path, must=False):
        repo = None
        logging.info("Trying to find a repository by name or path ...")
        if name:
            repo = member.repositoryByName(name)
        if path:
            repo = member.repositoryByPath(path)

        if must and not repo:
            raise AdminException(
                "Repository with name `%s' or path `%s' can not be found." %
                (name, path))
        elif not must and repo:
            raise AdminException("The repository `%s' already exists." %
                                 repo.name)

        return repo
コード例 #11
0
    def addhook(self):
        logging.info(
            "Defining username, email, repository name, hook and command ...")
        username = self.args.username
        email = self.args.email
        name = self.args.repository_name
        path = self.args.repository_path
        hook = self.args.hook
        command = self.args.command

        member = self._getMemberByUsernameOrEmail(username, email, True)
        repo = self._getRepositoryByNameOrPath(member, name, path, True)

        logging.info("Save new hook in database ...")
        repo.addHook(hook, command)

        print "Done."
コード例 #12
0
    def _getMemberByUsernameOrEmail(self, username, email, must=False):
        logging.info("Trying to find the user by username or email ...")
        member = None
        try:
            if username:
                member = Member.selectBy(username=username)[0]
            if email:
                member = Member.selectBy(email=email)[0]
        except IndexError:
            if must and not member:
                raise AdminException(
                    "The user can not be found (username: `%s', email: `%s')" %
                    (username, email))
        if not must and member:
            raise AdminException(
                "The user `%s' with email `%s' already exists." %
                (member.username, member.email))

        return member
コード例 #13
0
 def runhook(self):   
     logging.disable(logging.INFO)     
     logging.info("Defining hook, repo and arguments ...")
     repo = Repository.get(self.args.repository_id)
     arguments = " " + self.args.arguments if self.args.arguments else ""
     
     logging.info("Looking up all hooks for repository `%s' and hook `%s' ..." % (repo.id, self.args.hook))
     for hook in repo.getHooksByName(self.args.hook):
         logging.info("Running command `%s' ..." % hook.command + arguments)
         Popen(split(str(hook.command + arguments)))
コード例 #14
0
ファイル: Client.py プロジェクト: tstachl/Phoenix
    def runhook(self):
        logging.disable(logging.INFO)
        logging.info("Defining hook, repo and arguments ...")
        repo = Repository.get(self.args.repository_id)
        arguments = " " + self.args.arguments if self.args.arguments else ""

        logging.info(
            "Looking up all hooks for repository `%s' and hook `%s' ..." %
            (repo.id, self.args.hook))
        for hook in repo.getHooksByName(self.args.hook):
            logging.info("Running command `%s' ..." % hook.command + arguments)
            Popen(split(str(hook.command + arguments)))
コード例 #15
0
    def removehook(self):
        logging.info("Defining hook id ...")
        id = self.args.hook_id

        logging.info("Checking if hook exists ...")
        hook = Hook.get(id)

        if not hook:
            raise Exception("The hook with the id `%s' does not exist." % id)

        logging.info("Removing the hook from the database ...")
        hook.destroySelf()

        print "Done."
コード例 #16
0
    def removekey(self):
        logging.info("Defining key id ...")
        id = self.args.key_id

        logging.info("Checking if the key exists ...")
        key = Key.get(id)

        if not key:
            raise Exception("The key with the id `%s' does not exits." % id)

        logging.info("Removing the key from the database ...")
        key.destroySelf()

        print "Done."
コード例 #17
0
 def removehook(self):
     logging.info("Defining hook id ...")
     id = self.args.hook_id
     
     logging.info("Checking if hook exists ...")
     hook = Hook.get(id)
     
     if not hook:
         raise Exception("The hook with the id `%s' does not exist." % id)
     
     logging.info("Removing the hook from the database ...")
     hook.destroySelf()
     
     print "Done."
コード例 #18
0
 def removekey(self):
     logging.info("Defining key id ...")
     id = self.args.key_id
     
     logging.info("Checking if the key exists ...")
     key = Key.get(id)
     
     if not key:
         raise Exception("The key with the id `%s' does not exits." % id)
             
     logging.info("Removing the key from the database ...")
     key.destroySelf()
     
     print "Done."
コード例 #19
0
    def addkey(self):
        logging.info("Read the key ...")
        key = __import__("sys").stdin.readline().strip()
        if key == "":
            raise Exception("Key can not be empty.")

        logging.info("Define username, email and repository ...")
        email = self.args.email
        username = self.args.username

        member = self._getMemberByUsernameOrEmail(username, email, True)

        logging.info("Save new key in database ...")
        member.addKey(key)

        print "Done."
コード例 #20
0
 def addkey(self):
     logging.info("Read the key ...")
     key = __import__("sys").stdin.readline().strip()
     if key == "":
         raise Exception("Key can not be empty.")
     
     logging.info("Define username, email and repository ...")
     email = self.args.email
     username = self.args.username
     
     member = self._getMemberByUsernameOrEmail(username, email, True)
     
     logging.info("Save new key in database ...")
     member.addKey(key)
     
     print "Done."
コード例 #21
0
    def addrepo(self):
        logging.info("Defining username, email and repository name ...")
        username = self.args.username
        email = self.args.email
        name = self.args.repository_name
        path = self.args.repository_path
        
        member = self._getMemberByUsernameOrEmail(username, email, True)
        dummy = self._getRepositoryByNameOrPath(member, name, path)

        logging.info("Changing to the git user ...")
        __import__("os").setgid(__import__("pwd").getpwnam(Config.get("phoenix", "user")).pw_gid)
        __import__("os").setuid(__import__("pwd").getpwnam(Config.get("phoenix", "user")).pw_uid)
        
        logging.info("Creating and saving the new repository ...")
        member.addRepository(name, path)
        
        print "Done."
コード例 #22
0
    def addrepo(self):
        logging.info("Defining username, email and repository name ...")
        username = self.args.username
        email = self.args.email
        name = self.args.repository_name
        path = self.args.repository_path

        member = self._getMemberByUsernameOrEmail(username, email, True)
        dummy = self._getRepositoryByNameOrPath(member, name, path)

        logging.info("Changing to the git user ...")
        __import__("os").setgid(
            __import__("pwd").getpwnam(Config.get("phoenix", "user")).pw_gid)
        __import__("os").setuid(
            __import__("pwd").getpwnam(Config.get("phoenix", "user")).pw_uid)

        logging.info("Creating and saving the new repository ...")
        member.addRepository(name, path)

        print "Done."
コード例 #23
0
    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)
コード例 #24
0
 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)
コード例 #25
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."
コード例 #26
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."