Ejemplo n.º 1
0
def send_search_index(environ, start_response, parent_dir=None,
                       env_paths=None, authname='anonymous'):

    req = Request(environ, start_response)
    req.authname = authname;

    loadpaths = []
    if req.environ.get('trac.env_index_template'):
        tmpl_path, template = os.path.split(req.environ['trac.env_index_template'])
        loadpaths.insert(0, tmpl_path)
    else:
        template = 'index.html'
    req.hdf = HDFWrapper(loadpaths)

    tmpl_vars = {}
    if req.environ.get('trac.template_vars'):
        for pair in req.environ['trac.template_vars'].split(','):
            key, val = pair.split('=')
            req.hdf[key] = val

    if parent_dir and not env_paths:
        env_paths = dict([(filename, os.path.join(parent_dir, filename))
                          for filename in os.listdir(parent_dir)])

    chrome = prepare_request(req, environ)

    config = get_allenv(environ, req).config
    need_auth = config.get('tram', 'check_auth') == 'true'
    auth_perm = config.get('tram', 'permission') or 'PROJECT_ACCESS'
    parent_href = get_parent_href(req)
    projects = get_project_list(environ, parent_href, authname=req.authname, require_auth=need_auth, permission=auth_perm)

    data = {}
    data['projects'] = projects
    data["chrome.nav.mainnav.search.active"] = 1
    data["base_url"] = urlsplit(parent_href())[2] + "/"

    # Default to the standard Tram clearsilver first
    templateFileName = "search_index.html"
    fullTemplatePath = os.path.dirname( __file__ ) + "/templates/" + templateFileName

    # Now override, if user has defined a custom one in their environment's templates dir
    customTemplateFile = get_allenv(environ, req).get_templates_dir() + "/" + templateFileName
    if os.path.isfile(customTemplateFile):
        fullTemplatePath = customTemplateFile

    chrome.populate_data(req, data)
    output = chrome.render_template(req, fullTemplatePath, data)
    req.session.save()
    req.send(output, 'text/html')
Ejemplo n.º 2
0
Archivo: main.py Proyecto: jun66j5/TraM
    def dispatch(self, environ, start_response, env_parent_dir, env_paths, req):
        path_info = environ.get('PATH_INFO', '').lstrip('/').split('/')
        env_name = path_info.pop(0)

        #req = Request(environ, start_response)
        req.authname = LoginModule(self.compmgr).authenticate(req);
        # I don't know why this function is called twice.
        req.authname = LoginModule(self.compmgr).authenticate(req);

        # prepare_request function is not working collectly.
        chrome = prepare_request(req, environ)

        config = get_allenv(environ, req).config
        need_auth = config.get('tram', 'check_auth') == 'true'
        auth_perm = config.get('tram', 'permission') or 'PROJECT_ACCESS'
        old_style_index = config.get('tram', 'old_style_index') or 'false'
        if old_style_index == 'false':
            if not env_name:
                env_name = 'all'

        projects = get_project_list(environ, get_parent_href(req), authname=req.authname, require_auth=need_auth, permission=auth_perm)

        try:
            if env_name == '':
                send_project_index_old_style(environ, start_response, env_parent_dir, env_paths, req.authname)
            elif len(path_info) == 0 or (len(path_info) == 1 and path_info[0] == ''):
                #/all/ requested, show project index
                send_project_index(environ, start_response, env_parent_dir, env_paths, req.authname)
            elif path_info[0] == 'query':
                QueryModule().process_request(req, chrome, projects)
            elif path_info[0] == 'browser':
                BrowserModule().process_request(req, chrome, projects)
            elif path_info[0] == 'roadmap':
                RoadmapModule().process_request(req, chrome, projects)
            elif path_info[0] == 'timeline':
                TimelineModule(self.compmgr).process_request(req, chrome, projects)
            elif path_info[0] == 'search':
                send_search_index(environ, start_response, env_parent_dir, env_paths, req.authname)
        finally:
            if req.session:
                req.session.save()
Ejemplo n.º 3
0
def send_project_index(environ, start_response, parent_dir=None,
                       env_paths=None, authname='anonymous'):

    req = Request(environ, start_response)
    req.authname = authname;
    if not req.authname:
        req.authname = "anonymous"

    loadpaths = []
    if req.environ.get('trac.env_index_template'):
        tmpl_path, template = os.path.split(req.environ['trac.env_index_template'])
        loadpaths.insert(0, tmpl_path)
    else:
        template = 'index.html'
    req.hdf = HDFWrapper(loadpaths)

    tmpl_vars = {}
    if req.environ.get('trac.template_vars'):
        for pair in req.environ['trac.template_vars'].split(','):
            key, val = pair.split('=')
            req.hdf[key] = val

    if parent_dir and not env_paths:
        env_paths = dict([(filename, os.path.join(parent_dir, filename))
                          for filename in os.listdir(parent_dir)])

    chrome = prepare_request(req, environ)

    config = get_allenv(environ, req).config
    need_auth = config.get('tram', 'check_auth') == 'true'
    auth_perm = config.get('tram', 'permission') or 'PROJECT_ACCESS'
    bar_color = config.get('tram', 'bar_color') or '#0b0'
    expand = config.get('tram', 'expand') or 'true'
    show_tickets_in_project_list = config.get('tram', 'show_tickets_in_project_list') or 'false'
    projects = get_project_list(environ, get_parent_href(req), authname=req.authname, require_auth=need_auth, permission=auth_perm)


    # Very simple method for calculating project activity
    # needs to be more advanced, tickets closed etc and per month not overall
    stop = time.time()
    t = time.localtime()
    start = time.mktime((t[0], t[1] - 1, t[2], t[3], t[4], t[5], t[6], t[7], t[8]))
    stop2 = int(stop)
    start2 = int(start)
    start = datetime(t[0], t[1], t[2], t[3], t[4], t[5], t[6], tzinfo=utc) - timedelta(30)
    stop  = datetime(t[0], t[1], t[2], t[3], t[4], t[5], t[6], tzinfo=utc)

    changes = 0
    changes_month = 0
    max_ticket = 0
    max_ticket_closed = 0
    max_ticket_month = 0
    max_ticket_closed_month = 0
    for project in projects:
        if not project.has_key('env'):
            continue;

        env = project['env']
        revisions = 0
        try:
            repos = env.get_repository(req.authname)
            #change_list = repos.get_changesets(start, stop)

            try:
              for chgset in repos.get_changesets(start, stop):
              #while change_list.next():
                  try:
                    revisions += 1
                  except Exception, e:
                    debug(to_unicode(e))
            except Exception, e:
              debug(to_unicode(e))

            changes_month = max(changes_month, revisions)

            try:
                total_revisions = int(repos.get_youngest_rev())
            except TypeError:
                total_revisions = 0
            changes = max(changes, total_revisions)
        except TracError ,e:
            total_revisions = 0