Mercurial > p > roundup > code
comparison roundup/configuration.py @ 5246:c5dd7b151ec2
Make an import work with either Python 2 or 3.
| author | Eric S. Raymond <esr@thyrsus.com> |
|---|---|
| date | Thu, 24 Aug 2017 17:41:38 -0400 |
| parents | 8743b7226dc7 |
| children | 32f95ec6bd8e |
comparison
equal
deleted
inserted
replaced
| 5245:bc16d91b7a50 | 5246:c5dd7b151ec2 |
|---|---|
| 1 # Roundup Issue Tracker configuration support | 1 # Roundup Issue Tracker configuration support |
| 2 # | 2 # |
| 3 __docformat__ = "restructuredtext" | 3 __docformat__ = "restructuredtext" |
| 4 | 4 |
| 5 import ConfigParser | 5 try: |
| 6 import configparser # Python 3 | |
| 7 except ImportError: | |
| 8 import ConfigParser as configparser # Python 2 | |
| 9 | |
| 6 import getopt | 10 import getopt |
| 7 import imp | 11 import imp |
| 8 import logging, logging.config | 12 import logging, logging.config |
| 9 import os | 13 import os |
| 10 import re | 14 import re |
| 1371 home_dir = os.path.dirname(config_path) | 1375 home_dir = os.path.dirname(config_path) |
| 1372 # parse the file | 1376 # parse the file |
| 1373 config_defaults = {"HOME": home_dir} | 1377 config_defaults = {"HOME": home_dir} |
| 1374 if defaults: | 1378 if defaults: |
| 1375 config_defaults.update(defaults) | 1379 config_defaults.update(defaults) |
| 1376 config = ConfigParser.ConfigParser(config_defaults) | 1380 config = configparser.ConfigParser(config_defaults) |
| 1377 config.read([config_path]) | 1381 config.read([config_path]) |
| 1378 # .ini file loaded ok. | 1382 # .ini file loaded ok. |
| 1379 self.HOME = home_dir | 1383 self.HOME = home_dir |
| 1380 self.filepath = config_path | 1384 self.filepath = config_path |
| 1381 self._adjust_options(config) | 1385 self._adjust_options(config) |
