Skip to content

Commit c2ece38

Browse files
committed
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.
1 parent c3e835d commit c2ece38

File tree

7 files changed

+67
-119
lines changed

7 files changed

+67
-119
lines changed

CHANGES.txt

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,8 +54,12 @@ Fixed:
5454
lmsteffan in irc)
5555
- removed run_tests.py. Newer pytest doesn't support generating
5656
stand alone testing bundles. Python 3.9 generates errors running
57-
the current run_tests.py.
57+
the current run_tests.py. (reported by lmsteffan in irc)
5858
- issue2551104 - fix issue with markdown autolink next to punctuation (ced)
59+
- removed support for old style trackers that use dbinit.py and
60+
config.py. Also remove all uses of depricated imp module. (John Rouillard)
61+
- removed support for setting database type using
62+
<database>/backend_name. (John Rouillard)
5963

6064
Features:
6165
- issue2550522 - Add 'filter' command to command-line

roundup/configuration.py

Lines changed: 1 addition & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
# used here instead of try/except.
1010
import sys
1111
import getopt
12-
import imp
1312
import logging, logging.config
1413
import os
1514
import re
@@ -264,13 +263,6 @@ def load_ini(self, config):
264263
if config.has_option(self.section, self.setting):
265264
self.set(config.get(self.section, self.setting))
266265

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-
274266

275267
class BooleanOption(Option):
276268

@@ -1850,7 +1842,7 @@ def load(self, home_dir):
18501842
if os.path.isfile(os.path.join(home_dir, self.INI_FILE)):
18511843
self.load_ini(home_dir)
18521844
else:
1853-
self.load_pyconfig(home_dir)
1845+
raise NoConfigError(home_dir)
18541846
self.init_logging()
18551847
self.ext = UserConfig(os.path.join(home_dir, "extensions"))
18561848
self.detectors = UserConfig(os.path.join(home_dir, "detectors"))
@@ -1862,34 +1854,6 @@ def load_ini(self, home_dir, defaults=None):
18621854
config_defaults.update(defaults)
18631855
Config.load_ini(self, home_dir, config_defaults)
18641856

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-
18931857
# in this config, HOME is also known as TRACKER_HOME
18941858
def __getitem__(self, name):
18951859
if name == "TRACKER_HOME":

roundup/instance.py

Lines changed: 8 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -83,23 +83,13 @@ def __init__(self, tracker_home, optimize=0):
8383
# TODO: Remove in v1.7
8484
# Provide some backwards compatability for existing Roundup instances
8585
# that still define the backend type in 'db/backend_name' and warn the
86-
# users they need to update their config.ini
86+
# users they need to update their config.ini. Note that a missing
87+
# rdbms backend causes the config to throw an error, so this may
88+
# not be possible.
8789
if rdbms_backend == '':
88-
filename = os.path.join(self.config.DATABASE, 'backend_name')
89-
msg = """\n
90-
The 'backend_name' file is no longer used to configure the database backend
91-
used for the tracker. Please read 'doc/upgrading.txt' to find out how to
92-
update your config.ini
93-
"""
94-
try:
95-
with open(filename) as backend_file:
96-
rdbms_backend = backend_file.readline().strip()
97-
98-
with warnings.catch_warnings():
99-
warnings.simplefilter("once", DeprecationWarning)
100-
warnings.warn(msg, DeprecationWarning, stacklevel=2)
101-
except IOError:
102-
pass
90+
raise TrackerError("database backend not found in config.ini.\n"
91+
"Old style `backend_name` in db directory not supported\n"
92+
"See doc/upgrading.txt for required steps.")
10393

10494
self.backend = backends.get_backend(rdbms_backend)
10595

@@ -276,71 +266,11 @@ class TrackerError(RoundupException):
276266
pass
277267

278268

279-
class OldStyleTrackers:
280-
def __init__(self):
281-
self.number = 0
282-
self.trackers = {}
283-
284-
def open(self, tracker_home, optimize=0):
285-
"""Open the tracker.
286-
287-
Parameters:
288-
tracker_home:
289-
tracker home directory
290-
optimize:
291-
if set, precompile html templates
292-
293-
Raise ValueError if the tracker home doesn't exist.
294-
295-
"""
296-
import imp
297-
# sanity check existence of tracker home
298-
if not os.path.exists(tracker_home):
299-
raise ValueError('no such directory: "%s"' % tracker_home)
300-
301-
# sanity check tracker home contents
302-
for reqd in 'config dbinit select_db interfaces'.split():
303-
if not os.path.exists(os.path.join(tracker_home, '%s.py' % reqd)):
304-
raise TrackerError('File "%s.py" missing from tracker '
305-
'home "%s"' % (reqd, tracker_home))
306-
307-
if tracker_home in self.trackers:
308-
return imp.load_package(self.trackers[tracker_home],
309-
tracker_home)
310-
# register all available backend modules
311-
backends.list_backends()
312-
self.number = self.number + 1
313-
modname = '_roundup_tracker_%s' % self.number
314-
self.trackers[tracker_home] = modname
315-
316-
# load the tracker
317-
tracker = imp.load_package(modname, tracker_home)
318-
319-
# ensure the tracker has all the required bits
320-
for required in 'open init Client MailGW'.split():
321-
if not hasattr(tracker, required):
322-
raise TrackerError('Required tracker attribute "%s" missing' %
323-
required)
324-
325-
# load and apply the config
326-
tracker.config = configuration.CoreConfig(tracker_home)
327-
tracker.dbinit.config = tracker.config
328-
329-
tracker.optimize = optimize
330-
tracker.templates = templating.get_loader(tracker.config["TEMPLATES"])
331-
if optimize:
332-
tracker.templates.precompile()
333-
334-
return tracker
335-
336-
337-
OldStyleTrackers = OldStyleTrackers()
338-
339-
340269
def open(tracker_home, optimize=0):
341270
if os.path.exists(os.path.join(tracker_home, 'dbinit.py')):
342271
# user should upgrade...
343-
return OldStyleTrackers.open(tracker_home, optimize=optimize)
272+
raise TrackerError("Old style trackers using dbinit.py "
273+
"are not supported after release 2.0")
344274

345275
return Tracker(tracker_home, optimize=optimize)
346276

test/db_test_base.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717

1818
from __future__ import print_function
19-
import unittest, os, shutil, errno, imp, sys, time, pprint, os.path
19+
import unittest, os, shutil, errno, sys, time, pprint, os.path
2020

2121
try:
2222
from base64 import encodebytes as base64_encode # python3 only

test/test_instance.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
#
2+
# Copyright (C) 2020 John Rouillard
3+
# All rights reserved.
4+
# For license terms see the file COPYING.txt.
5+
#
6+
7+
from __future__ import print_function
8+
import unittest, os, shutil, errno, sys, difflib
9+
10+
from roundup import instance
11+
from roundup.instance import TrackerError
12+
13+
try:
14+
# python2
15+
import pathlib2 as pathlib
16+
except ImportError:
17+
# python3
18+
import pathlib
19+
20+
from . import db_test_base
21+
22+
class InstanceTest(unittest.TestCase):
23+
24+
backend = 'anydbm'
25+
26+
def setUp(self):
27+
self.dirname = '_test_instance'
28+
# set up and open a tracker
29+
self.instance = db_test_base.setupTracker(self.dirname, self.backend)
30+
31+
# open the database
32+
self.db = self.instance.open('admin')
33+
34+
self.db.commit()
35+
self.db.close()
36+
37+
def tearDown(self):
38+
if self.db:
39+
self.db.close()
40+
try:
41+
shutil.rmtree(self.dirname)
42+
except OSError as error:
43+
if error.errno not in (errno.ENOENT, errno.ESRCH): raise
44+
45+
46+
def testOpenOldStyle(self):
47+
pathlib.Path(os.path.join(self.dirname, "dbinit.py")).touch()
48+
# no longer support old style tracker configs
49+
self.assertRaises(TrackerError, instance.open, self.dirname)
50+

test/test_mailgw.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

1414
import email
1515
from . import gpgmelib
16-
import unittest, tempfile, os, shutil, errno, imp, sys, difflib, time, io
16+
import unittest, tempfile, os, shutil, errno, sys, difflib, time, io
1717

1818
import pytest
1919

test/test_mysql.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717

18-
import unittest, os, shutil, time, imp
18+
import unittest, os, shutil, time
1919

2020
import pytest
2121
from roundup.hyperdb import DatabaseError

0 commit comments

Comments
 (0)