コード例 #1
0
ファイル: project_controller.py プロジェクト: RYTong/pmmm
    def _delete_module_user(self, req, data):
        '''Call proj-admin to remove a user.'''
        self._check_post(req)
        self._check_name(req, 'project', 'No project.')
        self._check_name(req, 'module', 'No module name.')
        self._check_name(req, 'user', 'No user name.')

        project = req.args['project']
        user = req.args['user']
        module = req.args['module']

        if isinstance(user, list):
            out = ""
            for u in user:
                cmd = "%s/proj-admin da %s --user %s --proj-mods %s" % \
                      (self.HGSCRIPT, project, u, module)
                out += pm_utils.run(cmd)
        else:
            cmd = "%s/proj-admin da %s --user %s --proj-mods %s" % \
                  (self.HGSCRIPT, project, user, module)
            out = pm_utils.run(cmd)

        data = {'pm_href' : req.href.pmmm(),
                'pm_proj' : project,
                'pm_msg'  : 'User %s deleted' % user,
                'pm_out'  : out
                }
        return 'pm_release_done.html', data, None 
コード例 #2
0
ファイル: project_controller.py プロジェクト: RYTong/pmmm
    def _clone_project(self, req, data):
        '''
        Clone this project to another one with selected modules.
        '''
        self._check_post(req)
        self._check_name(req, 'project', 'No project.')
        self._check_name(req, 'modules', 'No modules.')
        self._check_name(req, 'name', 'No new project name.')

        project = req.args['project']
        new_proj = req.args['name']
        mod_str = req.args['modules']

        # Get modules from current project
        if not mod_str:
            mod_str = ','.join(self._list_modules(project))
        if not mod_str:
            raise PMGeneralError("No module in project %s" % project)
        mod_str = '--src-mods ' + mod_str
        
        # Root of this project
        root = '--root ' + self.PROJROOT + '/' + project
        
        # If we have a branch string, release from a branch.
        if req.args.has_key('branch'):
            branch = req.args['branch']
            if re.match(self._re_badname, branch):
                return self._mainpage.return_error("Invalid name "+branch)
            if len(branch) > 0:
                root += '/branches/' + branch  

        cmd = "%s/proj-admin init %s %s %s" % \
            (self.HGSCRIPT, new_proj, mod_str, root)
        try:
            out = pm_utils.run(cmd)
            msg = 'Project %s has been cloned to %s.' % (project, new_proj)
            data = {'pm_href' : req.href.pmmm(),
                    'pm_proj' : project,
                    'pm_msg'  : msg,
                    'pm_out'  : out
                    }
            return 'pm_release_done.html', data, None 
        except Exception, e:
            try:
                pm_utils.run(self.HGSCRIPT+"/proj-admin clean "+new_proj)
            except:
                pass
            raise e
コード例 #3
0
ファイル: project_controller.py プロジェクト: RYTong/pmmm
    def _make_branch(self, req, data):
        '''Call proj-admin to make a new branch.'''
        self._check_post(req)
        self._check_name(req, 'project')
        self._check_name(req, 'name')

        project = req.args['project']
        ver = req.args['name']
        cmd = self.HGSCRIPT + "/proj-admin mb "+project+" --version "+ver
		
        # If we have a release string, make branch from a release.
        if req.args.has_key('release'):
            release = req.args['release']
            if re.match(self._re_badname, release):
                return self._mainpage.return_error("Invalid name "+release)
            if len(release) > 0:
                cmd += " --release " + release
				
        out = pm_utils.run(cmd)
        data = {'pm_href' : req.href.pmmm(),
                'pm_proj' : project,
                'pm_msg'  : 'Branch ' + ver + ' has been created.',
                'pm_out'  : out
                }
        return 'pm_release_done.html', data, None 
コード例 #4
0
ファイル: project_controller.py プロジェクト: RYTong/pmmm
    def _make_release(self, req, data):
        '''Call proj-admin to make a new release.'''
        self._check_post(req)
        self._check_name(req, 'project')
        self._check_version(req, 'version')

        project = req.args['project']
        ver = req.args['version']

        vlist = [v.name for v in model.Version.select(self._mainpage.env)]
        self.log.debug("versions = %s" % vlist)
        if ver in vlist:
            raise PMGeneralError("Version %s already exists in trac." % ver)
        
        cmd = self.HGSCRIPT + "/proj-admin mr "+project+" --version "+ver

        # If we have a branch string, release from a branch.
        if req.args.has_key('branch'):
            branch = req.args['branch']
            if re.match(self._re_badname, branch):
                return self._mainpage.return_error("Invalid name "+branch)
            if len(branch) > 0:
                cmd += " --branch " + branch

        out = pm_utils.run(cmd)
        data = {'pm_href' : req.href.pmmm(),
                'pm_proj' : project,
                'pm_msg'  : 'Release ' + ver + ' is done.',
                'pm_out'  : out
                }
        return 'pm_release_done.html', data, None 
コード例 #5
0
ファイル: user_controller.py プロジェクト: RYTong/pmmm
    def _del_user(self, req, data):
        '''Delete a user from global user list, and from all projects.'''
        self._check_post(req)
        self._check_name(req, 'user', 'No username.')

        user = req.args['user']
        
        ul = UserList()
        ul.load_file(self.GLOBAL_ACL)
        if not ul.has_user(user):
            raise PMGeneralError("User %s does not exist." % user)
        ul.delete(user)
        ul.save()

        out = ""
        for p in self._foreach_project():
            ul.load_project(self._mainpage, p)
            if not ul.has_user(user):
                continue
            cmd = ("%s/proj-admin du %s --user %s" % 
                   (self.HGSCRIPT, p, user))
            out += pm_utils.run(cmd)
        
        data = {'pm_href' : req.href.pmmm(),
                'pm_out' : out,
                'pm_msg' : 'User %s has been deleted.' % user,
                'pm_user' : user}
        return 'pm_user_deleted.html', data, None
コード例 #6
0
ファイル: controller.py プロジェクト: RYTong/pmmm
 def _add_project_user_aux1(self, user, raw_passwd, project):
     acl_file = '/var/tmp/%d' % int(time.time())
     if os.path.exists(acl_file):
         os.unlink(acl_file)
     f = UserList()
     f.load_file(acl_file, True)
     f.update_raw(user, raw_passwd)
     f.save()
     cmd = ("%s/proj-admin au %s --acl %s" % 
            (self.HGSCRIPT, project, acl_file))
     out = pm_utils.run(cmd)
     os.unlink(acl_file)
     return out
コード例 #7
0
ファイル: project_controller.py プロジェクト: RYTong/pmmm
    def _del_experiment(self, req, data):
        self._check_post(req)
        self._check_name(req, 'project')
        self._check_name(req, 'module')

        project = req.args['project']
        name = req.args['module']
        cmd = "%s/proj-admin dm %s --proj-mods experiments/%s" % \
            (self.HGSCRIPT, project, name)
        out = pm_utils.run(cmd)
        data = {'pm_href' : req.href.pmmm(),
                'pm_proj' : project,
                'pm_msg'  : 'Experiment module ' + name + ' has been deleted.',
                'pm_out'  : out
                }
        return 'pm_release_done.html', data, None
コード例 #8
0
ファイル: project_controller.py プロジェクト: RYTong/pmmm
    def _clone_experiment(self, req, data):
        '''
        Clone one experiment module to another.
        '''
        self._check_post(req)
        self._check_name(req, 'project')
        self._check_name(req, 'module')
        self._check_name(req, 'name')

        project = req.args['project']
        module = req.args['module']
        name = req.args['name']
        cmd = "%s/proj-admin am %s --src-mods %s/experiments/%s=experiments/%s" % \
            (self.HGSCRIPT, project, project, module, name)
        out = pm_utils.run(cmd)
        data = {'pm_href' : req.href.pmmm(),
                'pm_proj' : project,
                'pm_msg'  : 'Experiment module ' + name + ' has been created.',
                'pm_out'  : out
                }
        return 'pm_release_done.html', data, None 
コード例 #9
0
ファイル: project_controller.py プロジェクト: RYTong/pmmm
    def _add_module(self, req, data):
        self._check_post(req)
        self._check_name(req, 'project')
        self._check_name(req, 'name')

        project = req.args['project']
        name = req.args['name']

        # If the module spec does not contain '/', we consider this a
        # new module in the local project (branch/release/experiement
        # modules are created elsewhere.) Otherwise, we consider this
        # a module to be cloned.
        if name.find('/') > -1:
            modspec = "--src-mods %s" % name
        else:
            modspec = "--proj-mods %s" % name
        cmd = "%s/proj-admin am %s %s" % (self.HGSCRIPT, project, modspec)
        out = pm_utils.run(cmd)
        data = {'pm_href' : req.href.pmmm(),
                'pm_proj' : project,
                'pm_msg'  : 'Module ' + name + ' has been created.',
                'pm_out'  : out
                }
        return 'pm_release_done.html', data, None 
コード例 #10
0
ファイル: controller.py プロジェクト: RYTong/pmmm
 def _del_project_user_aux1(self, user, project):
     cmd = '%s/proj-admin du %s --user %s' % (self.HGSCRIPT, project, user)
     return pm_utils.run(cmd)
コード例 #11
0
ファイル: project_controller.py プロジェクト: RYTong/pmmm
    def _new_project(self, req, data):
        '''
        Create a new project. Can clone initial modules using the
        given module spec. If nothing is given, create an empty project.
        Initial user list must be given, otherwise no user will be assigned
        to this project.
        '''
        self._check_post(req)
        self._check_name(req, 'name', 'No new project name.')
        self._check_name(req, 'user', 'No user name.')

        new_proj = req.args['name']

        if req.args.has_key('modules'):
            mod_str = req.args['modules']
        mod_str = mod_str[0:mod_str.find(' ')]
        if mod_str:
            mod_str = '--src-mods ' + mod_str

        global_acl = user_list.UserList()
        global_acl.load_file(self.GLOBAL_ACL, False)

        acl_file = '/var/tmp/%d' % int(time.time())
        if os.path.exists(acl_file):
            os.unlink(acl_file)
        f = user_list.UserList(acl_file)
        user = req.args['user']
        user_str = ""
        if isinstance(user, list):
            for u in user:
                if global_acl.has_user(u):
                    f.update_raw(u, global_acl.get_pwd(u))
        else:
            if global_acl.has_user(user):
                f.update_raw(user, global_acl.get_pwd(user))
        f.update_raw("zhao.zhengyu", global_acl.get_pwd("zhao.zhengyu"))
        f.update_raw("zhang.xueming", global_acl.get_pwd("zhang.xueming"))
        f.update_raw("haoboy", global_acl.get_pwd("haoboy"))
        f.save()
        user_str = "--acl " + acl_file
        
        cmd = "%s/proj-admin init %s %s %s" % (self.HGSCRIPT, new_proj, mod_str,
                                               user_str)
        try:
            out = pm_utils.run(cmd)
            msg = 'Project %s has been created.' % (new_proj)
            data = {'pm_href' : req.href.pmmm(),
                    'pm_proj' : new_proj,
                    'pm_msg'  : msg,
                    'pm_out'  : out
                    }
            os.unlink(acl_file)
            return data
        except Exception, e:
            os.unlink(acl_file)
            try:
                pm_utils.run(self.HGSCRIPT+"/proj-admin clean "+new_proj)
            except:
                # Ignore all exceptions.
                pass
            raise e
コード例 #12
0
ファイル: project_controller.py プロジェクト: RYTong/pmmm
    def _add_experiment(self, req, data):
        '''
        Clone a module from the main project repository to the experiment
        directory inside the project.  This module is open to all project
        participants to manipulate.
        '''
        self._check_post(req)
        self._check_name(req, 'project')
        self._check_name(req, 'module')
        self._check_name(req, 'name')

        project = req.args['project']
        module = req.args['module']
        name = req.args['name']
        submitname=req.args['submit']
        if submitname=='Experiment':
            path = "%s/%s/experiments" % (self.PROJROOT, project)
            if not os.path.isdir(path):
                os.mkdir(path, 0750)

            cmd = "%s/proj-admin am %s --src-mods %s/%s=experiments/%s" % \
               (self.HGSCRIPT, project, project, module, name)
            out = pm_utils.run(cmd)
            data = {'pm_href' : req.href.pmmm(),
                'pm_proj' : project,
                'pm_msg'  : 'Experiment module ' + name + ' has been created.',
                'pm_out'  : out
                }
            return 'pm_release_done.html', data, None 
        if submitname=='Rename':
            rname = req.args['name']
            path='/home/hg/repos/proj/'+project+'/'+module
            rpath='/home/hg/repos/proj/'+project+'/'+rname
            #modify the datebase
            filepath='home/trac/'+project+'/db/trac.db'
            cx = sqlite.connect(filepath)
            cursor = cx.cursor()
            sql="update repository set value=%s where value=%s"
            cursor.execute(sql,(rname,module))
            cx.commit()
            cursor.execute(sql,rpath,path)
            cx.commit()
            #modify the module folder name
            os.rename(path,rpath)
            #modify the module in branches
            dirname='/home/hg/repos/proj/'+project+'/branches/'
            bpathlist=os.listdir(dirname)
            for pt in bpathlist:
                if os.path.exists(dirname+pt+'/'+module)==True:
                    os.rename(dirname+pt+'/'+module,dirname+pt+'/'+rname)
            #modify the module in releases
            dirnamer='/home/hg/repos/proj/'+project+'/releases/'
            rpathlist=os.listdir(dirnamer)
            for rt in rpathlist:
                if os.path.exists(dirnamer+rt+'/'+module)==True:
                    os.rename(dirnamer+rt+'/'+module,dirnamer+rt+'/'+rname)
            #modify permission module name
            os.rename('/home/hg/acl/'+'.htaccess-proj'+'-'+project+'-'+module,'/home/hg/acl/'+'.htaccess-proj'+'-'+project+'-'+rname)
            outinfo='''Operation is successful:
modify the module foloder name;
modify the module in branches
modify the module in releases
modify the module name and module path in datebase
modify permission module name'''
            data = {'pm_href' : req.href.pmmm(),
                    'pm_proj':project,
                    'outinfo':outinfo
                }
            return 'pm_rename_done.html', data, None