Example #1
0
    def create(self, environ, projectname):
        """Create a new project review
        URLS : 
            /p/{projectname}/r/createrevw?form=request&formname=createrev
            /p/{projectname}/r/createrevw?form=submit&formname=createrev
        """
        from zeta.config.environment import projcomp, userscomp, vcscomp, vfcomp

        cfok = lambda cf : ( cf['mime_type'] != 'text/directory' ) and \
                           ( cf['changetype'] != 'deleted' )

        c.rclose = h.ZResp()

        # Handle forms
        def errhandler(errmsg):
            c.errmsg = errmsg

        vfcomp.process(request,
                       c,
                       defer=True,
                       errhandler=h.hitchfn(errhandler),
                       formnames=['createrev'],
                       user=c.authuser)

        # Setup context for page generation
        c.projsummary = c.project.summary
        c.projusers = self.projusers(c.project)
        c.usernames = sorted(userscomp.usernames)
        c.rsets = [[rs.id, rs.name] for rs in c.project.reviewsets]
        c.forsrc = request.params.getall('rurl')
        c.forversion = request.params.get('ver', None)
        c.forversion = int(c.forversion) if c.forversion != None else None
        vcsid = request.params.get('vcsid', None)
        c.vcs = vcsid and vcscomp.get_vcs(int(vcsid))
        c.vrep = c.vcs and va.open_repository(c.vcs)
        c.title = 'CreateReview'
        if c.vrep:
            c.changedfiles = c.vrep.changedfiles(c.vcs.rooturl,
                                                 revstart=c.forversion - 1,
                                                 revend=c.forversion)
            c.forsrc = [
                join(c.vcs.rooturl, cf['repos_path'].lstrip('/'))
                for cf in c.changedfiles if cfok(cf)
            ]

        # HTML page generation
        if c.errmsg:
            html = self.returnerrmsg(environ)

        elif c.form == 'submit' and c.formname == 'createrev':
            # Skip breadcrumbing, if it is a form submit
            c.title = '-Skip-'
            h.redirect_url(h.url_revwcreate)

        else:
            html = render('/derived/projects/reviewcreate.html')

        c.rclose.append(html)
        return c.rclose
Example #2
0
    def replogprocess( self, environ ) :
        r"""
        ==== Process repository logs

        Fetch repository logs, interpret the log message and update the
        database.

        > [<PRE paster request <.ini file> /pasteradmin/replogprocess \
                [ id=<repid> ] [ project=<projectname> ] [ name=<rep-name> ] >]

        where,
        : id      :: VCS id.
        : project :: Optional projectname
        : name    :: Optional repository name, which will be confirmed with
                     //id//
        """
        from zeta.config.environment import vcscomp, syscomp

        args    = cmd_parse_request()
        vcsid   = args.get( 'id', None )
        project = args.get( 'project', None )
        name    = args.get( 'name', None )

        vcs     = vcsid and vcscomp.get_vcs( int(vcsid) )
        namechk = name and vcs.name == name or True

        # Fetch the revision number from which messages had to be processed
        d_offs  = syscomp.get_sysentry( 'replogs', None )
        d_offs  = {} if d_offs == None else eval(d_offs)
        replogs = []

        if vcs and namechk :
            print "Processing repository logs for %s" % vcs.name
            print "---------------------------------"
            print "vcs-id   : %s" % vcs.id
            print "vcs-name : %s" % vcs.name
            print "vcs-type : %s" % vcs.type.vcs_typename
            print "project  : %s" % vcs.project.projectname
            fromrev = d_offs.get( vcs.id, 1 )
            vrep    = va.open_repository( vcs )
            replogs = vrep.logs( vcs.rooturl, revstart=fromrev )
        for r in replogs :
            ctxt = parse( r[0] )
            if isinstance( ctxt, Context ) :
                ctxt.commit( config, u'admin' )
                print "%s," % r[1]
        if replogs :
            d_offs[ vcs.id ] = replogs[-1][1]
            print "\nProcessed from %s to %s\n" % (replogs[0][1], replogs[-1][1])
Example #3
0
    def _json_dirlist(self):  # JSON
        """JSON : { id: 'dirlist',
                    label: 'dirlist',
                    items: [{ 'dirlist': '',
                              'dirs' : [ [ dirname, listurl, repos_path ], ... ],
                              'files': [ [ created_revision, mime_type, path,
                                           author, size, timestamp, repos_path,
                                           basename, url ],
                                         ... ]
                            }]"""
        c.vrep = va.open_repository(c.vcs)
        listing = {}
        fn = lambda f: listing.setdefault(f[1], []).append(f)
        map(fn, c.vrep.list(c.repopath, revno=c.revno))
        fn = lambda f: [
            basename(f[2]),
            self.url_vcsbrowse(c.project.projectname,
                               c.vcs.id,
                               repopath=f[2],
                               revno=c.revno,
                               jsonobj='dirlist',
                               view='js'), f[6][2:]
            if f[6][:2] == './' else f[6].lstrip('/')
        ]

        listing['text/directory'] = map(fn, listing.get('text/directory', []))
        fn = lambda f: f + [
            basename(f[2]),
            self.url_vcsbrowse(c.project.projectname,
                               c.vcs.id,
                               filepath=f[6].lstrip('/'),
                               revno=c.revno)
        ]
        listing['text/file'] = map(fn, listing.get('text/file', []))
        return h.todojoreadstore([{
            'dirlist': 0,
            'dirs': listing['text/directory'],
            'files': listing['text/file']
        }],
                                 lambda v: v,
                                 id='dirlist',
                                 label='dirlist')
Example #4
0
    def __before__(self, environ):
        """Called before calling any actions under this controller"""
        from zeta.config.environment import vcscomp

        # Generic, app-level before-controller handler
        self.beforecontrollers(environ=environ)
        self.dourls(environ, None)
        c.metanavs = metanav(environ)
        c.mainnavs = mainnav(c.projectname, c.controllername)

        # Collect the query values into 'context'
        c.revno = request.params.get('revno', None)
        c.rev1 = request.params.get('rev1', None)
        c.rev2 = request.params.get('rev2', None)
        c.repopath = request.params.get('repopath', None)
        c.wikifile = request.params.get('wikifile', None)
        c.cnttype = request.params.get('cnttype', MNT_TEXTCONTENT)
        c.vcseditable = None

        c.vcs = vcscomp.get_vcs(int(vcs_id), attrload=['type'
                                                       ]) if c.vcsid else None
        c.project = projcomp.get_project(c.projectname,
                                         attrload=['logofile'],
                                         attrload_all=['vcslist.type'])
        c.prjlogo = c.project and c.project.logofile and \
                    self.url_attach( c.project.logofile.id )

        # More specific initialisations.
        c.revno = int(c.revno) if c.revno else None
        c.rev1 = int(c.rev1) if c.rev1 else None
        c.rev2 = int(c.rev2) if c.rev2 else None
        fn = lambda v: [self.url_vcsbrowse(c.projectname, v.id), v.name]
        c.vcslist = map(fn, c.project.vcslist)
        c.vrep = None
        if c.vcs:
            c.vrep = va.open_repository(c.vcs)
            c.revno_l = c.vrep.linfo['l_revision']
            c.revno = c.revno_l if c.revno == None else c.revno
            strvno = c.vrep.client.start_revno
            c.revno_p = (c.revno - 1) if ((c.revno - 1) >= strvno) else None
            c.revno_n = (c.revno + 1) if ((c.revno + 1) <= c.revno_l) else None
Example #5
0
    def test_G_guess_revwsource(self):
        """Testing api, guess_revwsource()"""
        log.info("Testing api, guess_revwsource()")
        c = ContextObject()
        config['c'] = c
        c.authuser = g_byuser

        projects = filter(lambda p: p.vcslist, projcomp.get_project())
        p = choice(projects)
        projusers = [projcomp.projusernames(p) + [p.admin.username]]
        author = choice(projusers)
        moderator = choice(projusers)

        # Review for vcs file
        urls = gen_reviewurls(p, types=['vcsfile'])
        url = choice(urls)
        revdetail = (None, unicode(url[0]), url[1] == url[2] and url[1]
                     or randint(url[1], url[2]), author, moderator)
        r = revcomp.create_review(p, revdetail, byuser=g_byuser)
        filelines, _difflno = revcomp.guess_revwsource(r)
        vcs = [
            vcs for vcs in vcscomp.get_vcs()
            if commonprefix([r.resource_url, vcs.rooturl]) == vcs.rooturl
        ][0]
        vrep = va.open_repository(vcs)
        vfile = vrep.file(r.resource_url, revno=r.version)
        reflines = vfile.cat(revno=r.version)
        assert_equal([l[1] for l in reflines], filelines,
                     'Mismatch in guessing the review source - vcs file')

        # Review for vcs web url
        urls = gen_reviewurls(p, types=['vcsweburl'])
        url = choice(urls)
        revdetail = (None, unicode(url[0]), url[1] == url[2] and url[1]
                     or randint(url[1], url[2]), author, moderator)
        r = revcomp.create_review(p, revdetail, byuser=g_byuser)
        filelines, _difflno = revcomp.guess_revwsource(r)
        routes_map = config['routes.map']
        d, robj = routes_map.routematch(url[0])
        id = d.get('vcsid', '')
        filepath = d.get('filepath', '')
        vcs = vcscomp.get_vcs(int(id))
        vrep = va.open_repository(vcs)
        vfile = vrep.file(vcs.rooturl + '/' + filepath.lstrip('/'),
                          revno=r.version)
        reflines = vfile.cat(revno=r.version)
        assert_equal([l[1] for l in reflines], filelines,
                     'Mismatch in guessing the review source - vcsweburl')

        # Review for wiki
        urls = gen_reviewurls(p, types=['wiki'])
        url = choice(urls)
        revdetail = (None, unicode(url[0]), url[1] == url[2] and url[1]
                     or 1, author, moderator)
        r = revcomp.create_review(p, revdetail, byuser=g_byuser)
        filelines, _difflno = revcomp.guess_revwsource(r)
        w = wikicomp.get_wiki(r.resource_url)
        wcnt = wikicomp.get_content(w, version=r.version)
        reflines = wcnt.text.splitlines()
        assert_equal(reflines, filelines,
                     'Mismatch in guessing the review source - wiki')
Example #6
0
    def mount(self, environ, projectname, mid, murl=''):
        """Repository mount point
        URLS :
            /p/<projectname>/mnt/<mid>/*(murl)
        """
        from zeta.config.environment import projcomp, vcscomp

        c.rclose = h.ZResp()

        # Setup context for page generation
        c.repospath = murl.lstrip('/')
        c.projsummary = c.project.summary
        c.mnt = vcscomp.get_mount(int(mid), attrload=['vcs']) if mid else None
        c.id = mid
        c.title = 'mount:%s' % getattr(c.mnt, 'name', '')

        try:
            cprefix = commonprefix([c.repospath, c.mnt.vcs.rooturl])
            c.vrep = va.open_repository(getattr(c.mnt, 'vcs', None))
            c.repurl = c.repospath and \
                       ( c.repospath if cprefix == c.mnt.vcs.rooturl
                                   else join( c.mnt.vcs.rooturl, c.repospath ) ) \
                       or c.mnt.vcs.rooturl
            c.vfile = c.vrep.file(c.repurl)
        except:
            c.vfile = None

        if c.vfile == None:
            c.content = '<b>Error in reading path</b>'
            c.rendertype = c.mnt.content if c.mnt else h.MNT_TEXTCONTENT

        elif c.vfile.mimetype == 'text/directory':
            listing = {}
            dlist = c.vrep.list(c.repurl)
            [listing.setdefault(f[1], []).append(f) for f in dlist]
            fn = lambda f: [
                self.url_mount(projectname, mid, f[6]),
                basename(f[2]),
            ]
            dirs = map(fn, listing.get('text/directory', []))
            files = map(fn, listing.get('text/file', []))
            c.content = [ '<li><a href="%s">%s</a></li>' % tuple(d)
                          for d in dirs ] + \
                        [ '<li><a href="%s">%s</a></li>' % tuple(f)
                          for f in files ]
            c.content = '\n'.join(c.content)
            c.rendertype = 'dir'
        else:
            c.content = '\n'.join([l[1] for l in c.vfile.cat()])
            c.rendertype = c.mnt.content
            try:
                o = h.Preview()
                setattr(o, 'text', c.content)
                o.translate = h.hitch(o,
                                      h.Preview,
                                      h.translate,
                                      cacheattr='text')
                c.content = o.translate(wtype=h.CNTTYPE2WIKITYPE[c.rendertype])
            except:
                c.content = u''

        try:
            c.content = unicode(c.content)
        except:
            c.content = u'Unicoded file content'

        c.rclose.append(render('/derived/projects/projmount.html'))
        return c.rclose
Example #7
0
    def test_1_open_repository(self):
        """Testing open_repository()"""
        log.info("Testing open_repository()")

        vcsentries = vcscomp.get_vcs()
        v = choice(vcsentries)
        vrep = va.open_repository(v)

        # Test for apis in the repository module
        apis = ['init', 'info', 'list', 'cat', 'diff', 'logs', 'changedfiles']
        [
            assert_true(api in vrep.vcsmod.__dict__.keys(),
                        'Mismatch VcsAdaptor api (%s) is not present' % api)
            for api in apis
        ]

        # Test for vrep attributes
        attrs = ['vcs', 'vcsmod', 'client']
        [
            assert_true(
                attr in dir(vrep),
                'Mismatch, VcsRepository() attr(%s) is not present' % attr)
            for attr in attrs
        ]

        # Test for vrep methods
        info = vrep.info(vrep.vcs.rooturl)
        [
            assert_true(k in info.keys(),
                        'Mismatch, vrep.info method returns %s' % info)
            for k in [
                'l_revision', 'l_author', 'l_date', 'mime_type', 'size',
                'repos_path'
            ]
        ]

        listing = vrep.list(vrep.vcs.rooturl)
        assert_equal(len(listing[0]), 7,
                     'Mismatch in the number of items in a list entry')

        listing = vrep.logs(vrep.vcs.rooturl)
        assert_equal(len(listing[0]), 4,
                     'Mismatch in the number of items in a log entry')

        re = vrep.linfo['l_revision']
        rs = re - 1
        vfiles = vrep.changedfiles(vrep.vcs.rooturl, revstart=rs, revend=re)
        [
            assert_true(isinstance(f['vfile'], va.VcsFile),
                        'Mismatch in the file instance from changedfiles')
            for f in vfiles
        ]
        # Testing changedfile attributes
        attrs = ['repos_path', 'changetype', 'mime_type', 'vfile']
        [
            assert_true(attr in vfiles[0].keys(),
                        'Mismatch, VcsFile() attr(%s) is not present' % attr)
            for attr in attrs
        ]
        # Testing vfile attributes
        attrs = ['vcs', 'vcsmod', 'client', 'url', 'revno', 'repopath', 'vrep']
        [
            assert_true(attr in dir(vfiles[0]['vfile']),
                        'Mismatch, VcsFile() attr(%s) is not present' % attr)
            for attr in attrs
        ]

        vfile = vfiles[0]['vfile']

        info = vfile.info()
        [
            assert_true(k in info.keys(),
                        'Mismatch, vfile.info method returns %s' % info)
            for k in [
                'l_revision', 'l_author', 'l_date', 'mime_type', 'size',
                'repos_path'
            ]
        ]

        content = vfile.cat()
        assert_equal(
            len(content[0]), 5,
            'Mismatch in the number of items in unannotated file content')
        assert_equal(
            content[0][2:], (None, None, None),
            'Mismatch, fields in unannotated file content are not None')
        content = vfile.cat(annotate=True)
        assert_equal(
            len(content[0]), 5,
            'Mismatch in the number of items in unannotated file content')
        [
            assert_true(
                field,
                'Mismatch, fields in unannotated file content are not None')
            for field in content[0][2:]
        ]