~loggerhead-team/loggerhead/trunk-rich

« back to all changes in this revision

Viewing changes to loggerhead/controllers/__init__.py

  • Committer: Robey Pointer
  • Date: 2007-03-26 06:08:50 UTC
  • Revision ID: robey@lag.net-20070326060850-69b3yu2i6udttzjq
include more stuff in the manifest

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
import turbogears
27
27
from turbogears import controllers
28
 
from cherrypy import NotFound
 
28
from cherrypy import HTTPRedirect, NotFound
29
29
from configobj import ConfigObj
30
30
 
31
31
from loggerhead import util
52
52
        
53
53
        self._views = []
54
54
        for view_name in config.sections:
55
 
            log.debug('Configuring (project %s) branch %s...', name, view_name)
 
55
            log.debug('Configuring (project %r) branch %r...', name, view_name)
56
56
            self._add_view(view_name, config[view_name], config[view_name].get('folder'))
57
57
        
58
 
        self._auto_folder = config.get('auto_publish_folder', None)
59
 
        self._auto_list = []
60
 
        if self._auto_folder is not None:
61
 
            self._recheck_auto_folders()
 
58
        auto_folder = config.get('auto_publish_folder', None)
 
59
        if auto_folder is not None:
 
60
            auto_list = []
 
61
            # scan a folder for bazaar branches, and add them automatically
 
62
            for path, folders, filenames in os.walk(auto_folder):
 
63
                for folder in folders:
 
64
                    folder = os.path.join(path, folder)
 
65
                    if is_branch(folder):
 
66
                        auto_list.append(folder)
 
67
            auto_list.sort()
 
68
            for folder in auto_list:
 
69
                view_name = os.path.basename(folder)
 
70
                log.debug('Auto-configuring (project %r) branch %r...', name, view_name)
 
71
                self._add_view(view_name, ConfigObj(), folder)
62
72
    
63
 
    def _recheck_auto_folders(self):
64
 
        log.debug('recheck...')
65
 
        if self._auto_folder is None:
66
 
            return
67
 
        auto_list = []
68
 
        # scan a folder for bazaar branches, and add them automatically
69
 
        for path, folders, filenames in os.walk(self._auto_folder):
70
 
            for folder in folders:
71
 
                folder = os.path.join(path, folder)
72
 
                if is_branch(folder):
73
 
                    auto_list.append(folder)
74
 
        auto_list.sort()
75
 
        if auto_list == self._auto_list:
76
 
            # nothing has changed; do nothing.
77
 
            log.debug('ok')
78
 
            return
79
 
 
80
 
        # rebuild views:
81
 
        log.debug('Rescanning auto-folder for project %s ...', self.name)
82
 
        self._views = []
83
 
        for folder in auto_list:
84
 
            view_name = os.path.basename(folder)
85
 
            log.debug('Auto-configuring (project %s) branch %s...', self.name, view_name)
86
 
            self._add_view(view_name, ConfigObj(), folder)
87
 
        self._auto_list = auto_list
88
 
        
89
73
    def _add_view(self, view_name, view_config, folder):
90
74
        c_view_name = cherrypy_friendly(view_name)
91
75
        view = BranchView(self.name, c_view_name, view_name, folder, view_config, self._config)
96
80
 
97
81
 
98
82
class Root (controllers.RootController):
99
 
    def __init__(self, config):
 
83
    def __init__(self):
100
84
        self._projects = []
101
 
        self._config = config
102
 
        for project_name in self._config.sections:
 
85
        for project_name in sys._loggerhead_config.sections:
103
86
            c_project_name = cherrypy_friendly(project_name)
104
 
            project = Project(c_project_name, self._config[project_name])
 
87
            project = Project(c_project_name, sys._loggerhead_config[project_name])
105
88
            self._projects.append(project)
106
89
            setattr(self, c_project_name, project)
107
90
        
108
91
    @turbogears.expose(template='loggerhead.templates.browse')
109
92
    def index(self):
110
 
        for p in self._projects:
111
 
            p._recheck_auto_folders()
112
 
        log.debug('%r' % {
 
93
        return {
113
94
            'projects': self._projects,
114
95
            'util': util,
115
 
            'title': self._config.get('title', ''),
116
 
        })
117
 
        return {}
 
96
            'title': sys._loggerhead_config.get('title', ''),
 
97
        }
118
98
 
119
99
    def _check_rebuild(self):
120
100
        for p in self._projects:
122
102
                v.check_rebuild()
123
103
 
124
104
 
 
105
# singleton:
 
106
Root = Root()
 
107
 
125
108
 
126
109
# for use in profiling the very-slow get_change() method:
127
110
#h = Root.bazaar.bzr_dev.get_history()