コード例 #1
0
 def test_parse_csv(self):
     """Testing the h.parse_csv() function"""
     log.info("Testng h.parser_csv ...")
     line = 'item1, item2, ,, item3, item4 ,,,'
     assert_equal(h.parse_csv(line), ['item1', 'item2', 'item3', 'item4'],
                  'Mismatch in parsed csv with sample data 1')
     line = ''
     assert_equal(h.parse_csv(line), [],
                  'Mismatch in parsed csv with sample data 2')
     line = ', ,  ,,'
     assert_equal(h.parse_csv(line), [],
                  'Mismatch in parsed csv with sample data 3')
コード例 #2
0
ファイル: system.py プロジェクト: prataprc/zeta
    def set_sysentry(self, entries, doclose=None, byuser=None):
        """`entries` is a dictionary of 'field': 'value' which should be populated
        into the database."""
        from zeta.config.environment import tlcomp

        msession = meta.Session()

        # Sometimes, the caller might log the fact that sys-table is being
        # updated, so skip them here.
        #skiplog  = [ 'projteamtypes', 'tickettypes', 'ticketstatus',
        #             'ticketseverity', 'reviewnatures', 'reviewactions',
        #             'wikitypes', 'vcstypes', 'specialtags' ]
        skiplog = []

        with msession.begin(subtransactions=True):
            dbentries = dict(
                map(lambda e: (e.field, e),
                    msession.query(System).all()))
            loglines = []
            for k, v in entries.iteritems():

                if not isinstance(entries[k], (str, unicode)):
                    continue

                e = dbentries.get(k, None)
                if e == None:
                    msession.add(System(k, v))
                    log = k not in skiplog

                elif k in csvfields and \
                  ( sorted(h.parse_csv(e.value)) != sorted(h.parse_csv(v)) ) :
                    dbentries[k].value = v
                    log = k not in skiplog

                elif (k not in csvfields) and (e.value != v):
                    dbentries[k].value = v
                    log = k not in skiplog
                else:
                    log = False
                loglines.append('%s : %s' % (k, v)) if log else None

        log = loglines and 'system configuration,\n%s' % '\n'.join(
            loglines) or ''

        # Post processing, optional deferred handling
        cache.invalidate(self._sysentries)

        def onclose(tlcomp, byuser, log):
            log and tlcomp.log(byuser, log)

        doclose(h.hitchfn(onclose, tlcomp, byuser, log))
        return None
コード例 #3
0
def upgrade_1_1( defenv, appenv ) :
    """Upgrade database version from 1.1 to 1.2"""
    import zeta.lib.helpers           as h
    from   zeta.config.environment import syscomp, wikicomp, vcscomp, attachcomp

    # Upgrade with SQL scripts
    upgradewithscripts( '1_1', defenv, appenv )

    # Set created_on value for static_wiki table for older entries
    swikis = syscomp.updatecreatedon( byuser=g_user )
    print "  Updated `created_on` field for %s guest wiki entries" % len(swikis)

    # Update guest wiki pages' type attribute
    print "  Updating guest wiki pages' type attribute"
    swtype = wikicomp.get_wikitype(syscomp.get_sysentry('def_wikitype'))
    [ syscomp.set_staticwiki(sw.path, sw.text, swtype=swtype, byuser=g_user)
      for sw in syscomp.get_staticwiki() ]

    # Add wiki types,
    wikitypes = syscomp.get_sysentry( 'wikitypes' )
    wikitypes = h.parse_csv( wikitypes )
    addtypes  = h.WIKITYPES
    addtypes  = [ wt for wt in addtypes if wt not in wikitypes ]
    if addtypes :
        print "  Adding `%s` wikitype to system table" % addtypes
        wikitypes = ', '.join( wikitypes + addtypes )
        syscomp.set_sysentry({ 'wikitypes' : wikitypes }, byuser=g_user )
        print "  Adding `%s` wikitypes to wiki_type table" % wikitypes
        wikicomp.create_wikitype( addtypes, byuser=g_user )

    # Move attachment contents from database to envpath
    print "  Moving attachment contents from database to disk files "
    atts = attachcomp.get_attach()
    [ attachcomp.db2file(a)  for a in atts ]

    # Update the size field in attachment table.
    print "  Updating attachment size field in db table "
    [ attachcomp.updatesize(a) for a in atts ]

    # Add `hg` vcs type.
    vcstypes = syscomp.get_sysentry( 'vcstypes' )
    vcstypes = h.parse_csv( vcstypes )
    if 'hg' not in vcstypes :
        print "  Adding `hg` vcstype to system table"
        vcstypes = ', '.join( vcstypes + [ 'hg' ] )
        syscomp.set_sysentry({ 'vcstypes' : vcstypes }, byuser=g_user )
        print "  Adding `hg` vcstype to vcs_type table"
        vcscomp.create_vcstype( ['hg'], byuser=g_user )
コード例 #4
0
def upgrade_1_0( defenv, appenv ) :
    """Upgrade database version from 1.0 to 1.1"""
    import zeta.lib.helpers           as h
    from   zeta.config.environment    import syscomp, vcscomp, userscomp

    # Should we explicitly create a table ???, 
    # Create ticket_filter table
    print "  Creating table for `ticket_filters`, `reviewset`, `vcsmount`\n"
    meta.metadata.create_all( bind=meta.engine, checkfirst=True )

    # Update `googlemaps` field in system table
    print "  `googlemaps` should specify the generated key (No more boolean) ...\n"
    entry   = { u'googlemaps' : u'' }
    syscomp.set_sysentry( entry, byuser=g_user )

    # Rename ZETA_ADMIN permission name to SITE_ADMIN permission name
    print "  Changing permission name ZETA_ADMIN to SITE_ADMIN"
    userscomp.change_permname( 'ZETA_ADMIN', 'SITE_ADMIN', byuser=g_user )

    # Add `bzr` vcs type.
    vcstypes = syscomp.get_sysentry( 'vcstypes' )
    vcstypes = h.parse_csv( vcstypes )
    if 'bzr' not in vcstypes :
        print "  Adding `bzr` vcstype to system table"
        vcstypes = ', '.join( vcstypes + [ 'bzr' ] )
        syscomp.set_sysentry({ 'vcstypes' : vcstypes }, byuser=g_user )
        print "  Adding `bzr` vcstype to vcs_type table"
        vcscomp.create_vcstype( ['bzr'], byuser=g_user )
コード例 #5
0
ファイル: tag.py プロジェクト: prataprc/zeta
    def tagcloud( self, environ ) :
        """Tag cloud"""
        from zeta.config.environment    import syscomp, tagcomp

        c.rclose = h.ZResp()

        # Setup context for page generation
        c.specialtags = h.parse_csv( syscomp.get_sysentry( 'specialtags' ))
        c.tagpercentile = tagcomp.tagpercentile
        c.title = 'TagCloud'

        # Html page generation
        c.rclose.append(render( '/derived/tag/tagcloud.html' ))
        return c.rclose
コード例 #6
0
def parseconfig(config, global_conf, app_conf):
    """Configure the Pylons environment via the ``pylons.config`` object"""
    global tmplmoddir
    config.init_app(global_conf, app_conf, package='zeta', paths=paths)

    if config.has_key('zetaversion'):
        return

    # pylons configuration
    config['routes.map'] = make_map(config)
    config['pylons.app_globals'] = app_globals.Globals(config)
    config['pylons.h'] = h
    config['zeta.pkg_path'] = pkg_path
    config['zeta.envpath'] = envpath
    config['zeta.pageheader'] = config['zeta.pageheader'] == 'True'
    # config['pylons.strict_tmpl_context'] = False

    # Parse fields that will be persisted in system table.
    config['zeta.siteadmin'] = unicode(config['zeta.siteadmin'])
    config['pylons.package'] = unicode(config['pylons.package'])
    config['zeta.timezone'] = unicode(config['zeta.timezone'])
    config['zeta.unicode_encoding'] = unicode(config['zeta.unicode_encoding'])
    config['zeta.sitename'] = unicode(config['zeta.sitename'])
    config['zeta.envpath'] = unicode(config['zeta.envpath'])
    config['zeta.welcomestring'] = unicode(config['zeta.welcomestring'])
    config['zeta.userrel_types'] = map(
        lambda x: unicode(x), h.parse_csv(config['zeta.userrel_types']))
    config['zeta.projteamtypes'] = map(
        lambda x: unicode(x), h.parse_csv(config['zeta.projteamtypes']))
    config['zeta.ticketstatus'] = map(lambda x: unicode(x),
                                      h.parse_csv(config['zeta.ticketstatus']))
    config['zeta.tickettypes'] = map(lambda x: unicode(x),
                                     h.parse_csv(config['zeta.tickettypes']))
    config['zeta.ticketseverity'] = map(
        lambda x: unicode(x), h.parse_csv(config['zeta.ticketseverity']))
    config['zeta.reviewnatures'] = map(
        lambda x: unicode(x), h.parse_csv(config['zeta.reviewnatures']))
    config['zeta.reviewactions'] = map(
        lambda x: unicode(x), h.parse_csv(config['zeta.reviewactions']))
    config['zeta.wikitypes'] = map(lambda x: unicode(x),
                                   h.parse_csv(config['zeta.wikitypes']))
    config['zeta.vcstypes'] = map(lambda x: unicode(x),
                                  h.parse_csv(config['zeta.vcstypes']))
    config['zeta.ticketresolv'] = map(lambda x: unicode(x),
                                      h.parse_csv(config['zeta.ticketresolv']))
    config['zeta.specialtags'] = map(lambda x: unicode(x),
                                     h.parse_csv(config['zeta.specialtags']))
    config['zeta.def_wikitype'] = unicode(config['zeta.def_wikitype'])
    config['zeta.userpanes'] = map(lambda x: unicode(x),
                                   h.parse_csv(config['zeta.userpanes']))

    # Fields for run-time.
    config['dbversion'] = dbversion
    config['zetaversion'] = zetaversion
    if not config['zeta.mstnccodes']:
        config['zeta.mstnccodes'] = join(envpath, 'public', 'mstnccodes.json')
    if not config['zeta.tckccodes']:
        config['zeta.tckccodes'] = join(envpath, 'public', 'tckccodes.json')
    if not config.get('zeta.tckfilters', None):
        config['zeta.tckfilters'] = join(envpath, 'public', 'tckfilters.pyd')

    # Create the Mako TemplateLookup, with the default auto-escaping
    tmplmoddir = join(app_conf['cache_dir'], 'templates')
    config['pylons.app_globals'].mako_lookup = \
        TemplateLookup(
            directories=paths['templates'],
            error_handler=handle_mako_error,
            module_directory=tmplmoddir,
            input_encoding='utf-8',
            output_encoding=config['zeta.unicode_encoding'],
            #filesystem_checks=config['mako.filesystem_checks']
            imports=['from webhelpers.html import escape'],
            default_filters=['escape']
        )

    # Setup cache object.
    #from zeta.lib.upgradeenv import cleardata
    #cleardata( envpath )
    config['cachemgr'] = cachemanager(envpath)

    return config
コード例 #7
0
ファイル: projticket.py プロジェクト: prataprc/zeta
    def ticket(self, environ, projectname, tckid):
        """Each ticket
        URLS : 
            /p/{projectname}/t/{tckid}
            /p/{projectname}/t/{tckid}?jsonobj=tckattachs&view=js
            /p/{projectname}/t/{tckid}?jsonobj=tcktags&view=js
            /p/{projectname}/t/{tckid}?jsonobj=tckcomments&view=js
            /p/{projectname}/t/{tckid}?jsonobj=tckrcomments&view=js
            /p/{projectname}/t/{tckid}?form=submit&formname=createtstat&view=js
            /p/{projectname}/t/{tckid}?form=submit&formname=addtckattachs&view=js
            /p/{projectname}/t/{tckid}?form=submit&formname=deltckattachs&view=js
            /p/{projectname}/t/{tckid}?form=submit&formname=addtcktags&view=js
            /p/{projectname}/t/{tckid}?form=submit&formname=deltcktags&view=js
            /p/{projectname}/t/{tckid}?form=submit&formname=createtcmt&view=js
            /p/{projectname}/t/{tckid}?form=submit&formname=updatetcmt&view=js
            /p/{projectname}/t/{tckid}?form=submit&formname=replytcmt&view=js
            /p/{projectname}/t/{tckid}?form=submit&formname=tckfav&view=js
            /p/{projectname}/t/{tckid}?form=submit&formname=votetck&view=js
        """
        from zeta.config.environment import vfcomp, projcomp, tckcomp, votcomp

        c.rclose = h.ZResp()

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

        if self.formpermission():
            c.errmsg = 'Do not have %s permission !!' % tckperm[c.formname]
        else:
            vfcomp.process(request,
                           c,
                           defer=True,
                           errhandler=h.hitchfn(errhandler),
                           formnames=[
                               'createtstat', 'addtckattachs', 'deltckattachs',
                               'addtcktags', 'deltcktags', 'createtcmt',
                               'updatetcmt', 'replytcmt', 'tckfav', 'votetck'
                           ],
                           user=c.authuser)

        # Setup context for page generation
        c.projsummary = c.project.summary
        if not c.jsonobj:
            c.tckeditable = c.att_editable = c.tag_editable = h.authorized(
                h.HasPermname('TICKET_CREATE'))
            c.seltickets = self._seltickets()
            c.tckccodes = h.tckccodes
            c.tck_typenames = tckcomp.tcktypenames
            c.tck_statusnames = tckcomp.tckstatusnames
            c.tck_severitynames = tckcomp.tckseveritynames
            c.pcomponents, c.pmilestones, c.pversions, c.projusers = \
                              tckcomp.projdetails( c.project )
            c.pmilestones = [m[:2] for m in c.pmilestones if not any(m[2:])]
            c.pcomponents = [(tup[1], tup[0]) for tup in c.pcomponents]
            c.pmilestones = [(tup[1], tup[0]) for tup in c.pmilestones]
            c.pversions = [(tup[1], tup[0]) for tup in c.pversions]
            c.items_tckcomments = self._json_tckcomments()
            c.attachs = self._ticketattachs(c.ticket)
            c.tags = self._tickettags(c.ticket)
            c.isuserfavorite = tckcomp.isfavorite(c.authuser.id, c.ticket.id)
            c.ticketdetail = tckcomp.ticketdetails(c.ticket)
            c.ticketstatus = tckcomp.ticketstatus(c.ticket)
            c.blockers = tckcomp.blockersof(c.ticket)
            c.blocking = tckcomp.blockingfor(c.ticket)
            c.children = tckcomp.childrenfor(c.ticket)
            c.ticketresolv = h.parse_csv(c.sysentries.get('ticketresolv', ''))
            c.title = 'Ticket:%s' % tckid

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

        elif c.view == 'js' and c.formname in ['addtckattachs']:
            html = IFRAME_RET

        elif c.jsonobj and c.view == 'js':
            html = self.handlejson(environ)

        elif c.textobj and c.view == 'text':
            html = self.handletext(environ)

        elif c.view != 'js':
            uservote = votcomp.get_ticketvote(c.authuser, c.ticket)
            votes = tckcomp.countvotes(ticket=c.ticket)
            c.upvotes = votes.get('up', 0)
            c.downvotes = votes.get('down', 0)
            c.currvote = uservote and uservote.votedas or ''
            html = render('/derived/projects/ticket.html')
        else:
            html = ''

        c.rclose.append(html)
        return c.rclose
コード例 #8
0
ファイル: projticket.py プロジェクト: prataprc/zeta
    def ticketindex(self, environ, projectname):
        """Project tickets
        URLS :
            /p/{projectname}/t
            /p/{projectname}/t?stdfilter=<stdfilter>&savfilter=<savfilter>
            /p/{projectname}/t?jsonobj=ticketlist&view=js
            /p/{projectname}/t?form=submit&formname=configtck&view=js
            /p/{projectname}/t?form=submit&formname=configtstat&view=js
            /p/{projectname}/t?form=submit&formname=addtckfilter&view=js
            /p/{projectname}/t?form=submit&formname=deltckfilter&view=js
        """
        from zeta.config.environment import vfcomp, projcomp, tckcomp

        c.rclose = h.ZResp()

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

        if self.formpermission():
            c.errmsg = 'Do not have %s permission !!' % tckperm[c.formname]
        else:
            vfcomp.process(request,
                           c,
                           defer=True,
                           errhandler=h.hitchfn(errhandler),
                           formnames=[
                               'configtck', 'configtstat', 'addtckfilter',
                               'deltckfilter'
                           ],
                           user=c.authuser)

        # Setup context for both html page and AJAX request.
        c.projsummary = c.project.summary
        c.tckfilters = h.compile_tckfilters(tckfilters)
        c.title = '-Skip-'

        # HTML page generation
        if c.errmsg:
            html = self.returnerrmsg(environ)
        elif c.view == 'js' and c.jsonobj:
            html = self.handlejson(environ)

        elif c.view != 'js' and not (c.stdfilter
                                     or c.savfilter) and c.tckfilters:
            url = self.url_tcklist(projectname, stdfilter=c.tckfilters[0][0])
            h.redirect_url(url)

        elif c.view != 'js':
            # Setup context for html page
            c.tck_typenames = tckcomp.tcktypenames
            c.tck_statusnames = tckcomp.tckstatusnames
            c.tck_severitynames = tckcomp.tckseveritynames
            c.seltickets = self._seltickets()

            c.pcomponents, c.pmilestones, c.pversions, c.projusers = \
                              tckcomp.projdetails( c.project )
            c.projusers = self.projusers(c.project)
            c.pmilestones = [m[:2] for m in c.pmilestones if not any(m[2:])]
            c.mstnnames = sorted([m[0] for m in c.pmilestones])
            c.pcompnames = sorted([comp[0] for comp in c.pcomponents])
            c.vernames = sorted([ver[0] for ver in c.pversions])
            c.tckeditable = h.authorized(h.HasPermname('TICKET_CREATE'))
            c.tckccodes = h.tckccodes
            c.tstat_resolv = h.parse_csv(c.sysentries.get(u'ticketresolv', ''))
            userfilters = tckcomp.get_ticketfilter(user=c.authuser)
            fn = lambda tf: (tf.id, [tf.name, tf.filterbyjson])
            c.savfilterlist = dict(map(fn, userfilters))
            c.savfilterval = c.savfilterlist.get(c.savfilter, ['', ''])
            c.savfiltername = c.savfilterval[0]
            fn = lambda k, v: [
                self.url_tcklist(c.projectname, savfilter=k), v[0]
            ]
            c.savfilterlist = map(fn, c.savfilterlist.iteritems())
            c.title = 'Ticket:list'
            html = render('/derived/projects/ticketindex.html')

        c.rclose.append(html)
        return c.rclose
コード例 #9
0
ファイル: pasteradmin.py プロジェクト: prataprc/zeta
    def analytics( self, environ ) :
        r"""
        ==== Analytics

        Project analysis, site analysis and repository analysis

        > [<PRE paster request <.ini file> /pasteradmin/analytics [anal=anals] >]

        where,
        :anals ::
            comma separated list of one or more of the following values, \\ 
            [<PRE tags attachs users license projects tickets reviews wiki timeline >]
            If left empty will compute all analytics
        """
        import zeta.lib.analytics as ca

        allanal = [ 'tags',  'attachs', 'staticwiki', 'users', 'license',
                    'projects', 'tickets', 'reviews', 'wiki', 'timeline' ]
        args    = cmd_parse_request()
        anals   = args.get( 'anal', None )
        anals   = h.parse_csv( anals )
        if ('all' in anals) or (anals == []) :
            anals = allanal

        if 'tags' in anals :
            print "Computing analytics for tags ..."
            ta = ca.get_analyticobj( 'tags' )
            ta.analyse()
            ta.cacheme()

        if 'attachs' in anals :
            print "Computing analytics for attachments ..."
            aa = ca.get_analyticobj( 'attachs' )
            aa.analyse()
            aa.cacheme()

        if 'staticwiki' in anals :
            print "Computing analytics for static-wiki ..."
            swa = ca.get_analyticobj( 'staticwiki' )
            swa.analyse()
            swa.cacheme()

        if 'users' in anals :
            print "Computing analytics for users ..."
            aa = ca.get_analyticobj( 'users' )
            aa.analyse()
            aa.cacheme()

        if 'license' in anals :
            print "Computing analytics for license ..."
            la = ca.get_analyticobj( 'license' )
            la.analyse()
            la.cacheme()

        if 'projects' in anals :
            print "Computing analytics for project ..."
            pa = ca.get_analyticobj( 'projects' )
            pa.analyse()
            pa.cacheme()

        if 'tickets' in anals :
            print "Computing analytics for tickets ..."
            ta = ca.get_analyticobj( 'tickets' )
            ta.analyse()
            ta.cacheme()

        if 'reviews' in anals :
            print "Computing analytics for reviews ..."
            ra = ca.get_analyticobj( 'reviews' )
            ra.analyse()
            ra.cacheme()

        if 'wiki' in anals :
            print "Computing analytics for wiki ..."
            wa = ca.get_analyticobj( 'wiki' )
            wa.analyse()
            wa.cacheme()

        if 'timeline' in anals :
            print "Computing analytics for timeline ..."
            tla = ca.get_analyticobj( 'timeline' )
            tla.analyse()
            tla.cacheme()
コード例 #10
0
ファイル: pasteradmin.py プロジェクト: prataprc/zeta
    def genwikidoc( self, environ ) :
        r"""
        ==== Generate application documentation

        Generate documentation from source code.

        > [<PRE paster request <.ini file> /pasteradmin/genwikidoc [docs=docs] >]

        where,
        :docs ::
            comma separated list of one or more of the following values, \\ 
              [<PRE schema vim zwhtml zwmacros zwextensions xmlrpc pasteradmin pygments >]
            If left empty will generate documentation for all the above
            components.
        """
        from zeta.model  import meta

        alldocs = [ 'schema', 'zwhtml', 'zwmacros', 'zwextensions', 'xmlrpc',
                    'pasteradmin', 'pygments', 'vim' ]
        args    = cmd_parse_request()
        docs    = args.get( 'docs', None )
        docs    = h.parse_csv( docs )
        if ('all' in docs) or (docs == []) :
            docs = alldocs

        helpdocsdir = pjoin( abspath( os.curdir ), 'defenv/staticfiles/help' )
        zwikdocsdir = pjoin( abspath( os.curdir ), 'defenv/staticfiles/help/zwiki' )
        if not isdir( helpdocsdir ) :
            print "Please run the command from root of source tree !!"
            return

        srcdocsdir  = pjoin( abspath( os.curdir ), 'docs' )
        if not isdir( srcdocsdir ) :
            print "Please run the command from root of source tree !!"
            return

        if 'schema' in docs :
            print "Generating schema doc ..."
            tables  = [ t for t in meta.metadata.sorted_tables ]
            genwikidoc.schemadoc( srcdocsdir, tables )

        if 'zwhtml' in docs :
            print "Generating doc for ZWiki HTML Templated Tags ..."
            genwikidoc.zwhtml( zwikdocsdir )

        if 'zwmacros' in docs :
            print "Generating doc for ZWiki macros ..."
            genwikidoc.zwmacros( zwikdocsdir )

        if 'zwextensions' in docs :
            print "Generating doc for ZWiki extensions..."
            genwikidoc.zwextensions( zwikdocsdir )

        if 'xmlrpc' in docs :
            print "Generating XMLRPC doc ..."
            genwikidoc.xmlrpc( helpdocsdir )

        if 'pasteradmin' in docs :
            print "Generating PasterAdmin doc ..."
            genwikidoc.pasteradmin( helpdocsdir )

        if 'pygments' in docs :
            print "Generating Pygments doc ..."
            genwikidoc.pygments( helpdocsdir )

        if 'vim' in docs :
            print "Generating vim doc ..."
            genwikidoc.vimdoc( helpdocsdir )
コード例 #11
0
ファイル: pasteradmin.py プロジェクト: prataprc/zeta
    def search( self, environ ) :
        r"""
        ==== Xapian search indexing

        Build search index table for database content.

        > [<PRE paster request <.ini file> /pasteradmin/search <do> [doctypes] [replace=1] [querystring] [xid] >]

        where,
        :do :: 
          can be, \\ 
          //index//, to index all documents from tables mentioned in [doctypes] \\ 
          //queryterms//, convert the <querystring> and display the query terms \\ 
          //query//, results for <querystring> \\ 
          //clear//, remove the document identified by //xid//
        :doctypes ::
          Documents for which to build search index, can be a comma separated
          value of,
          [<PRE user, attach, license, staticwiki, project, ticket, review, wiki. >]
          If not specified, index will be built for all documents
        :replace ::
          Overwrite the existing index with new one. If not specified, replace
          will be False
        :querystring ::
          simple query string
        :xid ::
          document id, only for administrators who know what they are doing.
        """
        from zeta.config.environment    import srchcomp

        if environ['paste.command_request'] :
            args     = cmd_parse_request()
            do       = args.get( 'do', None )
            replace  = args.get( 'replace', None )
            doctypes = args.get( 'doctypes', '' )
            q        = args.get( 'q', None )
            xid      = args.get( 'xid', None )

            doctypes = h.parse_csv( doctypes )

        if do == 'index' and not doctypes :
            print "Indexing Users ...."
            srchcomp.indexuser( replace=replace, flush=False )
            print "Indexing Attachments ...."
            srchcomp.indexattach( replace=replace, flush=False )
            print "Indexing Licenses ...."
            srchcomp.indexlicense( replace=replace, flush=False )
            print "Indexing StaticWikis ...."
            srchcomp.indexstaticwiki( replace=replace, flush=False )
            print "Indexing Projects ...."
            srchcomp.indexproject( replace=replace, flush=False )
            print "Indexing Tickets ...."
            srchcomp.indexticket( replace=replace, flush=False )
            print "Indexing Reviews ...."
            srchcomp.indexreview( replace=replace, flush=False )
            print "Indexing Wikis ...."
            srchcomp.indexwiki( replace=replace, flush=False )
            srchcomp.close()

        elif do == 'index' :
            'user'       in doctypes and srchcomp.indexuser( replace=replace, flush=False)
            'attach'     in doctypes and srchcomp.indexattach( replace=replace, flush=False )
            'license'    in doctypes and srchcomp.indexlicense( replace=replace, flush=False )
            'staticwiki' in doctypes and srchcomp.indexstaticwiki( replace=replace, flush=False )
            'project'    in doctypes and srchcomp.indexproject( replace=replace, flush=False )
            'ticket'     in doctypes and srchcomp.indexticket( replace=replace, flush=False )
            'review'     in doctypes and srchcomp.indexreview( replace=replace, flush=False )
            'wiki'       in doctypes and srchcomp.indexwiki( replace=replace, flush=False)
            srchcomp.close()

        elif do == 'queryterms' and q :
            print srchcomp.queryterms(q)

        elif do == 'query' and q :
            matches = srchcomp.query( q )
            for m in matches :
                print "--------------------------"
                print "Percent : %s  Rank : %s  Weight : %s " % \
                      ( m.percent, m.rank, m.weight )
                print m.document.get_data()[:100]

        elif do == 'clear' and xid :
            srchcomp.clear( xid )
コード例 #12
0
ファイル: userpage.py プロジェクト: prataprc/zeta
    def tickets( self, environ, username ) :
        """List tickets belonging to user (attributed as owner and/or
        promptuser
        URLS :
            /u/{username}/t
            /u/{username}/t?stdfilter=<name>
            /u/{username}/t?savfilter=<name>
            /u/{username}/t?form=submit&formname=addtckfilter&view=js
            /u/{username}/t?form=submit&formname=deltckfilter&view=js
        """
        from zeta.config.environment    import projcomp, tckcomp, vfcomp

        c.rclose = h.ZResp()

        # Setting up urls to be stuffed into the page
        kwargs = { 'username' : username }
        c.stdfilter and kwargs.update({ 'stdfilter' : c.stdfilter })
        c.savfilter and kwargs.update({ 'savfilter' : c.savfilter })
        h.url_ticketlist = self.url_usrtcks( **kwargs )

        # Handle forms
        def errhandler(errmsg) :
            c.errmsg = errmsg
        if c.form in [ 'request', 'submit' ] and \
           c.formname in [ 'addtckfilter', 'deltckfilter' ] and \
           h.authorized( h.UserIn([ username ]) ) :
            vfcomp.process(
                request, c, defer=True, errhandler=h.hitchfn(errhandler),
                formnames=[ 'addtckfilter', 'deltckfilter' ], user=c.authuser
            )

        # Setup context for both html page and AJAX request.
        c.tckfilters = h.compile_tckfilters( tckfilters )
        c.title = '%s:tickets' % c.authuser.username

        # HTML page generation
        if c.jsonobj and c.view == 'js' :
            html = self.handlejson(environ)

        elif c.view != 'js' and not (c.stdfilter or c.savfilter) and c.tckfilters :
            kw = { 'username' : username, 'stdfilter' : c.tckfilters[0][0] }
            h.redirect_url( self.url_usrtcks( **kw ))

        elif c.view != 'js' :
            # Setup context for html page
            c.tckeditable = False
            c.tckccodes = h.tckccodes
            c.tstat_resolv = h.parse_csv( c.sysentries.get( u'ticketresolv', '' ))

            c.tck_typenames = tckcomp.tcktypenames
            c.tck_statusnames = tckcomp.tckstatusnames
            c.tck_severitynames = tckcomp.tckseveritynames
            c.projectnames = projcomp.projectnames

            userfilters     = tckcomp.get_ticketfilter( user=c.authuser )
            fn = lambda tf : ( tf.id, [ tf.name, tf.filterbyjson ] )
            c.savfilterlist = dict( map( fn, userfilters ))
            c.savfilterval = c.savfilterlist.get( c.savfilter, ['', ''] )
            c.savfiltername = c.savfilterval[0]
            fn = lambda k, v = [ self.url_usrtcks(**{'username' : username, 'savfilter' : k })
                                 v[0] ]
            c.savfilterlist = map( fn, c.savfilterlist.iteritems() )
            html = render( '/derived/userpage/ticket.html' )

        else :
            html =''

        c.rclose.append(html)
        return c.rclose