Mercurial > p > roundup > code
comparison roundup/configuration.py @ 6300:778a9f455067
Remove old code import imp, old style trackers db/backend_name
Module imp is depricated. Removing that means rewriting old style
trackers that used imp to load schema and config files. So removed
code supporting old style trackers that have been depricated since
2008.
Added test to verify that existence of dbinit.py triggers alert that
tracker is old style and not supported.
Also remove support for depricated db/backend_name file for specifying
backend. It is now specified in config.ini's [rdbms] backend.
It looks like not specifying an [rdbms] backend key in config.ini
throws a config error. However I left in a check and throw an
exception with details if there is an empty backend value. But I don't
think it will ever be triggered.
Removed unused import of imp in a number of test files.
| author | John Rouillard <rouilj@ieee.org> |
|---|---|
| date | Sun, 20 Dec 2020 15:43:07 -0500 |
| parents | 957a0fc20021 |
| children | 6a6b4651be1f |
comparison
equal
deleted
inserted
replaced
| 6299:fd0bdcbc68e4 | 6300:778a9f455067 |
|---|---|
| 7 # Roundup if used with Python 2 because it generates unicode objects | 7 # Roundup if used with Python 2 because it generates unicode objects |
| 8 # where not expected by the Python code. Thus, a version check is | 8 # where not expected by the Python code. Thus, a version check is |
| 9 # used here instead of try/except. | 9 # used here instead of try/except. |
| 10 import sys | 10 import sys |
| 11 import getopt | 11 import getopt |
| 12 import imp | |
| 13 import logging, logging.config | 12 import logging, logging.config |
| 14 import os | 13 import os |
| 15 import re | 14 import re |
| 16 import time | 15 import time |
| 17 import smtplib | 16 import smtplib |
| 261 | 260 |
| 262 def load_ini(self, config): | 261 def load_ini(self, config): |
| 263 """Load value from ConfigParser object""" | 262 """Load value from ConfigParser object""" |
| 264 if config.has_option(self.section, self.setting): | 263 if config.has_option(self.section, self.setting): |
| 265 self.set(config.get(self.section, self.setting)) | 264 self.set(config.get(self.section, self.setting)) |
| 266 | |
| 267 def load_pyconfig(self, config): | |
| 268 """Load value from old-style config (python module)""" | |
| 269 for _name in self.aliases: | |
| 270 if hasattr(config, _name): | |
| 271 self.set(getattr(config, _name)) | |
| 272 break | |
| 273 | 265 |
| 274 | 266 |
| 275 class BooleanOption(Option): | 267 class BooleanOption(Option): |
| 276 | 268 |
| 277 """Boolean option: yes or no""" | 269 """Boolean option: yes or no""" |
| 1848 def load(self, home_dir): | 1840 def load(self, home_dir): |
| 1849 """Load configuration from path designated by home_dir argument""" | 1841 """Load configuration from path designated by home_dir argument""" |
| 1850 if os.path.isfile(os.path.join(home_dir, self.INI_FILE)): | 1842 if os.path.isfile(os.path.join(home_dir, self.INI_FILE)): |
| 1851 self.load_ini(home_dir) | 1843 self.load_ini(home_dir) |
| 1852 else: | 1844 else: |
| 1853 self.load_pyconfig(home_dir) | 1845 raise NoConfigError(home_dir) |
| 1854 self.init_logging() | 1846 self.init_logging() |
| 1855 self.ext = UserConfig(os.path.join(home_dir, "extensions")) | 1847 self.ext = UserConfig(os.path.join(home_dir, "extensions")) |
| 1856 self.detectors = UserConfig(os.path.join(home_dir, "detectors")) | 1848 self.detectors = UserConfig(os.path.join(home_dir, "detectors")) |
| 1857 | 1849 |
| 1858 def load_ini(self, home_dir, defaults=None): | 1850 def load_ini(self, home_dir, defaults=None): |
| 1860 config_defaults = {"TRACKER_HOME": home_dir} | 1852 config_defaults = {"TRACKER_HOME": home_dir} |
| 1861 if defaults: | 1853 if defaults: |
| 1862 config_defaults.update(defaults) | 1854 config_defaults.update(defaults) |
| 1863 Config.load_ini(self, home_dir, config_defaults) | 1855 Config.load_ini(self, home_dir, config_defaults) |
| 1864 | 1856 |
| 1865 def load_pyconfig(self, home_dir): | |
| 1866 """Set options from config.py file in given home_dir directory""" | |
| 1867 # try to locate and import the module | |
| 1868 _mod_fp = None | |
| 1869 try: | |
| 1870 try: | |
| 1871 _module = imp.find_module(self.PYCONFIG, [home_dir]) | |
| 1872 _mod_fp = _module[0] | |
| 1873 _config = imp.load_module(self.PYCONFIG, *_module) | |
| 1874 except ImportError: | |
| 1875 raise NoConfigError(home_dir) | |
| 1876 finally: | |
| 1877 if _mod_fp is not None: | |
| 1878 _mod_fp.close() | |
| 1879 # module loaded ok. set the options, starting from HOME | |
| 1880 self.reset() | |
| 1881 self.HOME = home_dir | |
| 1882 for _option in self.items(): | |
| 1883 _option.load_pyconfig(_config) | |
| 1884 # backward compatibility: | |
| 1885 # SMTP login parameters were specified as a tuple in old style configs | |
| 1886 # convert them to new plain string options | |
| 1887 _mailuser = getattr(_config, "MAILUSER", ()) | |
| 1888 if len(_mailuser) > 0: | |
| 1889 self.MAIL_USERNAME = _mailuser[0] | |
| 1890 if len(_mailuser) > 1: | |
| 1891 self.MAIL_PASSWORD = _mailuser[1] | |
| 1892 | |
| 1893 # in this config, HOME is also known as TRACKER_HOME | 1857 # in this config, HOME is also known as TRACKER_HOME |
| 1894 def __getitem__(self, name): | 1858 def __getitem__(self, name): |
| 1895 if name == "TRACKER_HOME": | 1859 if name == "TRACKER_HOME": |
| 1896 return self.HOME | 1860 return self.HOME |
| 1897 else: | 1861 else: |
