Merge lp:~rockstar/loggerhead/config-cleanup into lp:loggerhead
- config-cleanup
- Merge into trunk-rich
Proposed by
Paul Hummer
Status: | Merged |
---|---|
Merged at revision: | not available |
Proposed branch: | lp:~rockstar/loggerhead/config-cleanup |
Merge into: | lp:loggerhead |
Diff against target: | None lines |
To merge this branch: | bzr merge lp:~rockstar/loggerhead/config-cleanup |
Related bugs: |
Reviewer | Review Type | Date Requested | Status |
---|---|---|---|
Michael Hudson-Doyle | Pending | ||
Review via email:
|
Commit message
Description of the change
To post a comment you must log in.
Revision history for this message
![](/+icing/build/overlay/assets/skins/sam/images/close.gif)
Paul Hummer (rockstar) wrote : | # |
- 319. By Paul Hummer
-
Responded to mwhudson's review
- 320. By Paul Hummer
-
Fixed an issue where I seemed to have poo for brains at the time, and created memory profile logs ALL the time.
Preview Diff
[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1 | === modified file 'loggerhead/apps/filesystem.py' | |||
2 | --- loggerhead/apps/filesystem.py 2009-02-19 18:04:11 +0000 | |||
3 | +++ loggerhead/apps/filesystem.py 2009-03-31 19:31:45 +0000 | |||
4 | @@ -1,7 +1,6 @@ | |||
5 | 1 | """Serve branches at urls that mimic the file system layout.""" | 1 | """Serve branches at urls that mimic the file system layout.""" |
6 | 2 | 2 | ||
7 | 3 | import os | 3 | import os |
8 | 4 | import tempfile | ||
9 | 5 | 4 | ||
10 | 6 | from bzrlib import branch, errors, lru_cache | 5 | from bzrlib import branch, errors, lru_cache |
11 | 7 | 6 | ||
12 | @@ -11,10 +10,9 @@ | |||
13 | 11 | 10 | ||
14 | 12 | from loggerhead.apps.branch import BranchWSGIApp | 11 | from loggerhead.apps.branch import BranchWSGIApp |
15 | 13 | from loggerhead.apps import favicon_app, static_app | 12 | from loggerhead.apps import favicon_app, static_app |
16 | 13 | from loggerhead.config import LoggerheadConfig | ||
17 | 14 | from loggerhead.controllers.directory_ui import DirectoryUI | 14 | from loggerhead.controllers.directory_ui import DirectoryUI |
18 | 15 | 15 | ||
19 | 16 | sql_dir = tempfile.mkdtemp(prefix='loggerhead-cache-') | ||
20 | 17 | |||
21 | 18 | 16 | ||
22 | 19 | class BranchesFromFileSystemServer(object): | 17 | class BranchesFromFileSystemServer(object): |
23 | 20 | 18 | ||
24 | @@ -22,6 +20,7 @@ | |||
25 | 22 | self.path = path | 20 | self.path = path |
26 | 23 | self.root = root | 21 | self.root = root |
27 | 24 | self.name = name | 22 | self.name = name |
28 | 23 | self._config = LoggerheadConfig() | ||
29 | 25 | 24 | ||
30 | 26 | def app_for_branch(self, branch): | 25 | def app_for_branch(self, branch): |
31 | 27 | if not self.name: | 26 | if not self.name: |
32 | @@ -31,8 +30,9 @@ | |||
33 | 31 | name = self.name | 30 | name = self.name |
34 | 32 | is_root = False | 31 | is_root = False |
35 | 33 | branch_app = BranchWSGIApp( | 32 | branch_app = BranchWSGIApp( |
38 | 34 | branch, name, {'cachepath': sql_dir}, self.root.graph_cache, | 33 | branch, name, |
39 | 35 | is_root=is_root) | 34 | {'cachepath': self._config.SQL_DIR}, |
40 | 35 | self.root.graph_cache, is_root=is_root) | ||
41 | 36 | return branch_app.app | 36 | return branch_app.app |
42 | 37 | 37 | ||
43 | 38 | def app_for_non_branch(self, environ): | 38 | def app_for_non_branch(self, environ): |
44 | 39 | 39 | ||
45 | === added file 'loggerhead/config.py' | |||
46 | --- loggerhead/config.py 1970-01-01 00:00:00 +0000 | |||
47 | +++ loggerhead/config.py 2009-03-31 19:31:45 +0000 | |||
48 | @@ -0,0 +1,66 @@ | |||
49 | 1 | '''Configuration tools for Loggerhead.''' | ||
50 | 2 | from optparse import OptionParser | ||
51 | 3 | import sys | ||
52 | 4 | import tempfile | ||
53 | 5 | |||
54 | 6 | |||
55 | 7 | def command_line_parser(): | ||
56 | 8 | parser = OptionParser("%prog [options] <path>") | ||
57 | 9 | parser.set_defaults( | ||
58 | 10 | user_dirs=False, | ||
59 | 11 | show_version=False, | ||
60 | 12 | log_folder=None, | ||
61 | 13 | ) | ||
62 | 14 | parser.add_option("--user-dirs", action="store_true", dest="user_dirs", | ||
63 | 15 | help="Serve user directories as ~user.") | ||
64 | 16 | parser.add_option("--trunk-dir", metavar="DIR", | ||
65 | 17 | help="The directory that contains the trunk branches.") | ||
66 | 18 | parser.add_option("--port", dest="user_port", | ||
67 | 19 | help=("Port Loggerhead should listen on " | ||
68 | 20 | "(defaults to 8080).")) | ||
69 | 21 | parser.add_option("--host", dest="user_host", | ||
70 | 22 | help="Host Loggerhead should listen on.") | ||
71 | 23 | parser.add_option('--memory-profile', action='store_true', | ||
72 | 24 | dest='memory_profile', | ||
73 | 25 | help='Profile the memory usage using heapy.') | ||
74 | 26 | parser.add_option("--prefix", dest="user_prefix", | ||
75 | 27 | help="Specify host prefix.") | ||
76 | 28 | parser.add_option("--profile", action="store_true", dest="profile", | ||
77 | 29 | help="Generate callgrind profile data to " | ||
78 | 30 | "%d-stats.callgrind on each request.") | ||
79 | 31 | parser.add_option("--reload", action="store_true", dest="reload", | ||
80 | 32 | help="Restarts the application when changing python" | ||
81 | 33 | " files. Only used for development purposes.") | ||
82 | 34 | parser.add_option('--log-folder', dest="log_folder", | ||
83 | 35 | type=str, help="The directory to place log files in.") | ||
84 | 36 | parser.add_option("--version", action="store_true", dest="show_version", | ||
85 | 37 | help="Print the software version and exit") | ||
86 | 38 | return parser | ||
87 | 39 | |||
88 | 40 | |||
89 | 41 | class LoggerheadConfig: | ||
90 | 42 | '''A configuration object.''' | ||
91 | 43 | |||
92 | 44 | def __init__(self): | ||
93 | 45 | self._parser = command_line_parser() | ||
94 | 46 | self._options, self._args = self._parser.parse_args(sys.argv[1:]) | ||
95 | 47 | |||
96 | 48 | self.SQL_DIR = tempfile.mkdtemp(prefix='loggerhead-cache-') | ||
97 | 49 | |||
98 | 50 | def get_option(self, option): | ||
99 | 51 | '''Get an option from the options dict.''' | ||
100 | 52 | return self._options.__dict__[option] | ||
101 | 53 | |||
102 | 54 | def get_arg(self, index): | ||
103 | 55 | '''Get an arg from the arg list.''' | ||
104 | 56 | return self._args(index) | ||
105 | 57 | |||
106 | 58 | def print_help(self): | ||
107 | 59 | '''Wrapper around OptionParser.print_help.''' | ||
108 | 60 | return self._parser.print_help() | ||
109 | 61 | |||
110 | 62 | @property | ||
111 | 63 | def arg_count(self): | ||
112 | 64 | '''Return the number of args from the option parser.''' | ||
113 | 65 | return len(self._args) | ||
114 | 66 | |||
115 | 0 | 67 | ||
116 | === modified file 'serve-branches' | |||
117 | --- serve-branches 2009-03-30 22:11:06 +0000 | |||
118 | +++ serve-branches 2009-03-31 19:31:45 +0000 | |||
119 | @@ -19,8 +19,6 @@ | |||
120 | 19 | import os | 19 | import os |
121 | 20 | import sys | 20 | import sys |
122 | 21 | 21 | ||
123 | 22 | from optparse import OptionParser | ||
124 | 23 | |||
125 | 24 | from bzrlib.plugin import load_plugins | 22 | from bzrlib.plugin import load_plugins |
126 | 25 | 23 | ||
127 | 26 | from paste import httpserver | 24 | from paste import httpserver |
128 | @@ -30,56 +28,22 @@ | |||
129 | 30 | from loggerhead import __version__ | 28 | from loggerhead import __version__ |
130 | 31 | from loggerhead.apps.filesystem import ( | 29 | from loggerhead.apps.filesystem import ( |
131 | 32 | BranchesFromFileSystemRoot, UserBranchesFromFileSystemRoot) | 30 | BranchesFromFileSystemRoot, UserBranchesFromFileSystemRoot) |
132 | 31 | from loggerhead.config import LoggerheadConfig | ||
133 | 33 | from loggerhead.util import Reloader | 32 | from loggerhead.util import Reloader |
134 | 34 | from loggerhead.apps.error import ErrorHandlerApp | 33 | from loggerhead.apps.error import ErrorHandlerApp |
135 | 35 | 34 | ||
136 | 36 | 35 | ||
137 | 37 | def command_line_parser(): | ||
138 | 38 | parser = OptionParser("%prog [options] <path>") | ||
139 | 39 | parser.set_defaults( | ||
140 | 40 | user_dirs=False, | ||
141 | 41 | show_version=False, | ||
142 | 42 | log_folder=None, | ||
143 | 43 | ) | ||
144 | 44 | parser.add_option("--user-dirs", action="store_true", dest="user_dirs", | ||
145 | 45 | help="Serve user directories as ~user.") | ||
146 | 46 | parser.add_option("--trunk-dir", metavar="DIR", | ||
147 | 47 | help="The directory that contains the trunk branches.") | ||
148 | 48 | parser.add_option("--port", dest="user_port", | ||
149 | 49 | help=("Port Loggerhead should listen on " | ||
150 | 50 | "(defaults to 8080).")) | ||
151 | 51 | parser.add_option("--host", dest="user_host", | ||
152 | 52 | help="Host Loggerhead should listen on.") | ||
153 | 53 | parser.add_option('--memory-profile', action='store_true', | ||
154 | 54 | dest='memory_profile', | ||
155 | 55 | help='Profile the memory usage using heapy.') | ||
156 | 56 | parser.add_option("--prefix", dest="user_prefix", | ||
157 | 57 | help="Specify host prefix.") | ||
158 | 58 | parser.add_option("--profile", action="store_true", dest="profile", | ||
159 | 59 | help="Generate callgrind profile data to " | ||
160 | 60 | "%d-stats.callgrind on each request.") | ||
161 | 61 | parser.add_option("--reload", action="store_true", dest="reload", | ||
162 | 62 | help="Restarts the application when changing python" | ||
163 | 63 | " files. Only used for development purposes.") | ||
164 | 64 | parser.add_option('--log-folder', dest="log_folder", | ||
165 | 65 | type=str, help="The directory to place log files in.") | ||
166 | 66 | parser.add_option("--version", action="store_true", dest="show_version", | ||
167 | 67 | help="Print the software version and exit") | ||
168 | 68 | return parser | ||
169 | 69 | |||
170 | 70 | |||
171 | 71 | def main(args): | 36 | def main(args): |
174 | 72 | parser = command_line_parser() | 37 | config = LoggerheadConfig() |
173 | 73 | (options, args) = parser.parse_args(sys.argv[1:]) | ||
175 | 74 | 38 | ||
177 | 75 | if options.show_version: | 39 | if config.get_option('show_version'): |
178 | 76 | print "loggerhead %s" % __version__ | 40 | print "loggerhead %s" % __version__ |
179 | 77 | sys.exit(0) | 41 | sys.exit(0) |
180 | 78 | 42 | ||
183 | 79 | if len(args) > 1: | 43 | if config.arg_count > 1: |
184 | 80 | parser.print_help() | 44 | config.print_help() |
185 | 81 | sys.exit(1) | 45 | sys.exit(1) |
187 | 82 | elif len(args) == 1: | 46 | elif config.arg_count == 1: |
188 | 83 | [path] = args | 47 | [path] = args |
189 | 84 | else: | 48 | else: |
190 | 85 | path = '.' | 49 | path = '.' |
191 | @@ -88,21 +52,22 @@ | |||
192 | 88 | print "%s is not a directory" % path | 52 | print "%s is not a directory" % path |
193 | 89 | sys.exit(1) | 53 | sys.exit(1) |
194 | 90 | 54 | ||
196 | 91 | if options.trunk_dir and not options.user_dirs: | 55 | if config.get_option('trunk_dir') and not config.get_option('user_dirs'): |
197 | 92 | print "--trunk-dir is only valid with --user-dirs" | 56 | print "--trunk-dir is only valid with --user-dirs" |
198 | 93 | sys.exit(1) | 57 | sys.exit(1) |
199 | 94 | 58 | ||
201 | 95 | if options.reload: | 59 | if config.get_option('reload'): |
202 | 96 | if Reloader.is_installed(): | 60 | if Reloader.is_installed(): |
203 | 97 | Reloader.install() | 61 | Reloader.install() |
204 | 98 | else: | 62 | else: |
205 | 99 | return Reloader.restart_with_reloader() | 63 | return Reloader.restart_with_reloader() |
206 | 100 | 64 | ||
209 | 101 | if options.user_dirs: | 65 | if config.get_option('user_dirs'): |
210 | 102 | if not options.trunk_dir: | 66 | if not config.get_option['trunk_dir']: |
211 | 103 | print "You didn't specify a directory for the trunk directories." | 67 | print "You didn't specify a directory for the trunk directories." |
212 | 104 | sys.exit(1) | 68 | sys.exit(1) |
214 | 105 | app = UserBranchesFromFileSystemRoot(path, options.trunk_dir) | 69 | app = UserBranchesFromFileSystemRoot( |
215 | 70 | path, config.get_option('trunk_dir')) | ||
216 | 106 | else: | 71 | else: |
217 | 107 | app = BranchesFromFileSystemRoot(path) | 72 | app = BranchesFromFileSystemRoot(path) |
218 | 108 | 73 | ||
219 | @@ -110,8 +75,9 @@ | |||
220 | 110 | logging.basicConfig() | 75 | logging.basicConfig() |
221 | 111 | logging.getLogger('').setLevel(logging.DEBUG) | 76 | logging.getLogger('').setLevel(logging.DEBUG) |
222 | 112 | logger = getattr(app, 'log', logging.getLogger('loggerhead')) | 77 | logger = getattr(app, 'log', logging.getLogger('loggerhead')) |
225 | 113 | if options.log_folder: | 78 | if config.get_option('log_folder'): |
226 | 114 | logfile_path = os.path.join(options.log_folder, 'serve-branches.log') | 79 | logfile_path = os.path.join( |
227 | 80 | config.get_option['log_folder'], 'serve-branches.log') | ||
228 | 115 | else: | 81 | else: |
229 | 116 | logfile_path = 'serve-branches.log' | 82 | logfile_path = 'serve-branches.log' |
230 | 117 | logfile = logging.FileHandler(logfile_path, 'a') | 83 | logfile = logging.FileHandler(logfile_path, 'a') |
231 | @@ -128,17 +94,17 @@ | |||
232 | 128 | # setup_logging() #end | 94 | # setup_logging() #end |
233 | 129 | 95 | ||
234 | 130 | app = TransLogger(app, logger=logger) | 96 | app = TransLogger(app, logger=logger) |
236 | 131 | if options.profile: | 97 | if config.get_option('profile'): |
237 | 132 | from loggerhead.middleware.profile import LSProfMiddleware | 98 | from loggerhead.middleware.profile import LSProfMiddleware |
238 | 133 | app = LSProfMiddleware(app) | 99 | app = LSProfMiddleware(app) |
240 | 134 | if options.memory_profile: | 100 | if config.get_option('memory_profile'): |
241 | 135 | from loggerhead.middleware.profile import MemoryProfileMiddleware | 101 | from loggerhead.middleware.profile import MemoryProfileMiddleware |
242 | 136 | app = MemoryProfileMiddleware(app) | 102 | app = MemoryProfileMiddleware(app) |
243 | 137 | 103 | ||
245 | 138 | if not options.user_prefix: | 104 | if not config.get_option('user_prefix'): |
246 | 139 | prefix = '/' | 105 | prefix = '/' |
247 | 140 | else: | 106 | else: |
249 | 141 | prefix = options.user_prefix | 107 | prefix = config.get_option('user_prefix') |
250 | 142 | if not prefix.startswith('/'): | 108 | if not prefix.startswith('/'): |
251 | 143 | prefix = '/' + prefix | 109 | prefix = '/' + prefix |
252 | 144 | 110 | ||
253 | @@ -163,15 +129,15 @@ | |||
254 | 163 | app = HTTPExceptionHandler(app) | 129 | app = HTTPExceptionHandler(app) |
255 | 164 | app = ErrorHandlerApp(app) | 130 | app = ErrorHandlerApp(app) |
256 | 165 | 131 | ||
258 | 166 | if not options.user_port: | 132 | if not config.get_option('user_port'): |
259 | 167 | port = '8080' | 133 | port = '8080' |
260 | 168 | else: | 134 | else: |
262 | 169 | port = options.user_port | 135 | port = config.get_option('user_port') |
263 | 170 | 136 | ||
265 | 171 | if not options.user_host: | 137 | if not config.get_option('user_host'): |
266 | 172 | host = '0.0.0.0' | 138 | host = '0.0.0.0' |
267 | 173 | else: | 139 | else: |
269 | 174 | host = options.user_host | 140 | host = config.get_option('user_host') |
270 | 175 | 141 | ||
271 | 176 | load_plugins() | 142 | load_plugins() |
272 | 177 | 143 |
This branch cleans up (a bit) the configuration stuff for Loggerhead, and
merges command line and options with (some) configuration options. I think
this really needs a lot of cleaning up, but I'm still not sure how to do this
without it being really messy.
reviewer mwhudson