configwizard: remove parsing of config from legacy code (
bug 1277406); r=glob
We don't need this in the new implementation because the config is
already parsed and loaded by Mercurial.
MozReview-Commit-ID: 7UJb2GqGGvp
--- a/hgext/configwizard/hgsetup/config.py
+++ b/hgext/configwizard/hgsetup/config.py
@@ -1,87 +1,24 @@
# This Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this,
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
from __future__ import unicode_literals
-from configobj import ConfigObj
-import codecs
-import re
-import os
-
-
HOST_FINGERPRINTS = {
'bitbucket.org': '3f:d3:c5:17:23:3c:cd:f5:2d:17:76:06:93:7e:ee:97:42:21:14:aa',
'bugzilla.mozilla.org': '7c:7a:c4:6c:91:3b:6b:89:cf:f2:8c:13:b8:02:c4:25:bd:1e:25:17',
'hg.mozilla.org': 'af:27:b9:34:47:4e:e5:98:01:f6:83:2b:51:c9:aa:d8:df:fb:1a:27',
}
-def config_file(files):
- """Select the most appropriate config file from a list."""
- if not files:
- return None
-
- if len(files) > 1:
- picky = [(os.path.getsize(f), f) for f in files if os.path.isfile(f)]
- if picky:
- return max(picky)[1]
-
- return files[0]
-
-
-class ParseException(Exception):
- def __init__(self, line, msg):
- self.line = line
- super(Exception, self).__init__(msg)
-
-
class MercurialConfig(object):
"""Interface for manipulating a Mercurial config file."""
- def __init__(self, path=None):
- """Create a new instance, optionally from an existing hgrc file."""
-
- self.config_path = path
-
- # Mercurial configuration files allow an %include directive to include
- # other files, this is not supported by ConfigObj, so throw a useful
- # error saying this.
- if os.path.exists(path):
- with codecs.open(path, 'r', encoding='utf-8') as f:
- for i, line in enumerate(f):
- if line.startswith('%include'):
- raise ParseException(i + 1,
- '%include directive is not supported by MercurialConfig')
- if line.startswith(';'):
- raise ParseException(i + 1,
- 'semicolon (;) comments are not supported; '
- 'use # instead')
-
- # write_empty_values is necessary to prevent built-in extensions (which
- # have no value) from being dropped on write.
- # list_values aren't needed by Mercurial and disabling them prevents
- # quotes from being added.
- self._c = ConfigObj(infile=path, encoding='utf-8',
- write_empty_values=True, list_values=False)
-
- @property
- def config(self):
- return self._c
-
- @property
- def extensions(self):
- """Returns the set of currently enabled extensions (by name)."""
- return set(self._c.get('extensions', {}).keys())
-
- def write(self, fh):
- return self._c.write(fh)
-
def have_valid_username(self):
if 'ui' not in self._c:
return False
if 'username' not in self._c['ui']:
return False
# TODO perform actual validation here.
--- a/hgext/configwizard/hgsetup/wizard.py
+++ b/hgext/configwizard/hgsetup/wizard.py
@@ -250,30 +250,16 @@ class MercurialSetupWizard(object):
os.makedirs(self.ext_dir)
except OSError as e:
if e.errno != errno.EEXIST:
raise
hg = get_hg_path()
config_path = config_file(config_paths)
- try:
- c = MercurialConfig(config_path)
- except ConfigObjError as e:
- print('Error importing existing Mercurial config: %s\n' % config_path)
- for error in e.errors:
- print(error.message)
-
- return 1
- except ParseException as e:
- print('Error importing existing Mercurial config: %s\n' % config_path)
- print('Line %d: %s' % (e.line, e.message))
-
- return 1
-
self.updater.update_all()
hg_version = get_hg_version(hg)
if not c.have_valid_username():
print(MISSING_USERNAME)
print('')