Mercurial > public > mercurial-scm > hg
comparison mercurial/ui.py @ 19195:9311cd5c09ed
ui: use util.sizetoint in configbytes
author | Bryan O'Sullivan <bryano@fb.com> |
---|---|
date | Tue, 14 May 2013 15:16:44 -0700 |
parents | be207d9b7e4b |
children | c58b6ab4c26f |
comparison
equal
deleted
inserted
replaced
19194:1d08df65cd3c | 19195:9311cd5c09ed |
---|---|
4 # | 4 # |
5 # This software may be used and distributed according to the terms of the | 5 # This software may be used and distributed according to the terms of the |
6 # GNU General Public License version 2 or any later version. | 6 # GNU General Public License version 2 or any later version. |
7 | 7 |
8 from i18n import _ | 8 from i18n import _ |
9 import errno, getpass, os, re, socket, sys, tempfile, traceback | 9 import errno, getpass, os, socket, sys, tempfile, traceback |
10 import config, scmutil, util, error, formatter | 10 import config, scmutil, util, error, formatter |
11 | 11 |
12 class ui(object): | 12 class ui(object): |
13 def __init__(self, src=None): | 13 def __init__(self, src=None): |
14 self._buffers = [] | 14 self._buffers = [] |
282 Traceback (most recent call last): | 282 Traceback (most recent call last): |
283 ... | 283 ... |
284 ConfigError: foo.invalid is not a byte quantity ('somevalue') | 284 ConfigError: foo.invalid is not a byte quantity ('somevalue') |
285 """ | 285 """ |
286 | 286 |
287 orig = string = self.config(section, name) | 287 value = self.config(section, name) |
288 if orig is None: | 288 if value is None: |
289 if not isinstance(default, str): | 289 if not isinstance(default, str): |
290 return default | 290 return default |
291 orig = string = default | 291 value = default |
292 multiple = 1 | |
293 m = re.match(r'([^kmbg]+?)\s*([kmg]?)b?$', string, re.I) | |
294 if m: | |
295 string, key = m.groups() | |
296 key = key.lower() | |
297 multiple = dict(k=1024, m=1048576, g=1073741824).get(key, 1) | |
298 try: | 292 try: |
299 return int(float(string) * multiple) | 293 return util.sizetoint(value) |
300 except ValueError: | 294 except error.ParseError: |
301 raise error.ConfigError(_("%s.%s is not a byte quantity ('%s')") | 295 raise error.ConfigError(_("%s.%s is not a byte quantity ('%s')") |
302 % (section, name, orig)) | 296 % (section, name, value)) |
303 | 297 |
304 def configlist(self, section, name, default=None, untrusted=False): | 298 def configlist(self, section, name, default=None, untrusted=False): |
305 """parse a configuration element as a list of comma/space separated | 299 """parse a configuration element as a list of comma/space separated |
306 strings | 300 strings |
307 | 301 |