~mnordhoff/loggerhead/cheezum

« back to all changes in this revision

Viewing changes to loggerhead/config.py

  • Committer: Matt Nordhoff
  • Date: 2010-05-04 02:22:51 UTC
  • mfrom: (164.152.7 integration)
  • Revision ID: mnordhoff@mattnordhoff.com-20100504022251-ekbb12orq2slu4ah
Merge lp:~jameinel/loggerhead/integration.

Requires bzr-history-db now.

There were some conflicts, but I think I got 'em right. I chopped out the logging changes.

Show diffs side-by-side

added added

removed removed

Lines of Context:
32
32
            import errno
33
33
            if e.errno != errno.EEXIST:
34
34
                raise
 
35
        # XXX: Shouldn't this be registering an atexit hook to delete the
 
36
        #      directory? Otherwise we fill up /tmp with caches that we won't
 
37
        #      ever use again...
35
38
        _temporary_sql_dir = tempfile.mkdtemp(dir=parent,
36
39
            prefix='lc-')
37
40
    return _temporary_sql_dir
58
61
    parser.add_option("--protocol", dest="protocol",
59
62
                      help=("Protocol to use: http, scgi, fcgi, ajp"
60
63
                           "(defaults to http)."))
 
64
    parser.add_option("--log-level", default=None, action='callback',
 
65
                      callback=_optparse_level_to_int_level,
 
66
                      type="string",
 
67
                      help="Set the verbosity of logging. Can either"
 
68
                           " be set to a numeric or string"
 
69
                           " (eg, 10=debug, 30=warning)")
61
70
    parser.add_option("--memory-profile", action="store_true",
62
71
                      help="Profile the memory usage using Dozer.")
63
72
    parser.add_option("--prefix", dest="user_prefix",
78
87
                      help="The directory to place the SQL cache in")
79
88
    parser.add_option("--allow-writes", action="store_true",
80
89
                      help="Allow writing to the Bazaar server.")
 
90
    parser.add_option("--show-merge-points", action="store_true", default=True,
 
91
                      help="When showing a revision, show where it"
 
92
                           " was merged.")
 
93
    parser.add_option("--no-show-merge-points", action="store_false",
 
94
                      dest='show_merge_points',
 
95
                      help="Do not show where revisions are merged")
81
96
    return parser
82
97
 
83
98
 
 
99
_log_levels = {
 
100
    'debug': 10,
 
101
    'info': 20,
 
102
    'warning': 30,
 
103
    'error': 40,
 
104
    'critical': 50,
 
105
}
 
106
 
 
107
def _optparse_level_to_int_level(option, opt_str, value, parser):
 
108
    return _level_to_int_level(value)
 
109
 
 
110
 
 
111
def _level_to_int_level(value):
 
112
    """Convert a string level to an integer value."""
 
113
    if value is None:
 
114
        return None
 
115
    try:
 
116
        return int(value)
 
117
    except ValueError:
 
118
        pass
 
119
    return _log_levels[value.lower()]
 
120
 
 
121
 
84
122
class LoggerheadConfig(object):
85
123
    """A configuration object."""
86
124
 
101
139
        All loggerhead-specific settings start with 'http_'
102
140
        """
103
141
        global_config = config.GlobalConfig().get_user_option('http_'+option)
104
 
        cmd_config = getattr(self._options, option)
 
142
        cmd_config = getattr(self._options, option, None)
105
143
        if global_config is not None and (
106
144
            cmd_config is None or cmd_config is False):
107
145
            return global_config
108
146
        else:
109
147
            return cmd_config
110
148
 
 
149
    def get_log_level(self):
 
150
        opt = self.get_option('log_level')
 
151
        return _level_to_int_level(opt)
 
152
 
111
153
    def get_arg(self, index):
112
154
        """Get an arg from the arg list."""
113
155
        return self._args[index]