Skip to content

Commit 9572bec

Browse files
Merge pull request #83 from timvaillancourt/MCB_1.0-walk_packages
Mcb 1.0: use pkgutil.walk_packages to find submodules
2 parents b2849aa + 7a91235 commit 9572bec

File tree

3 files changed

+26
-26
lines changed

3 files changed

+26
-26
lines changed

mongodb_consistent_backup/Common/Config.py

Lines changed: 16 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import sys
22

33
from argparse import Action
4+
from pkgutil import walk_packages
45
from yconf import BaseConfiguration
56

67

@@ -52,11 +53,9 @@ def makeParser(self):
5253

5354
class Config(object):
5455
# noinspection PyUnusedLocal
55-
def __init__(self, cmdline=None, **args):
56-
if not self.cmdline:
57-
self.cmdline = sys.argv[1:]
56+
def __init__(self):
5857
self._config = ConfigParser()
59-
self.parse_submodules(args)
58+
self.parse_submodules()
6059
self.parse()
6160

6261
self.version = __version__
@@ -71,11 +70,19 @@ def _get(self, keys, data=None):
7170
else:
7271
return data[keys]
7372

74-
def parse_submodules(self, args):
75-
if 'submodules' in args:
76-
parser = self._config.parser
77-
for submodule in args['submodules']:
78-
submodule.config(parser)
73+
def parse_submodules(self):
74+
for _, modname, ispkg in walk_packages(path="."):
75+
if ispkg:
76+
try:
77+
components = modname.split('.')
78+
mod = __import__(components[0])
79+
for comp in components[1:]:
80+
mod = getattr(mod, comp)
81+
mod.config(self._config.parser)
82+
except AttributeError, e:
83+
continue
84+
except Exception, e:
85+
raise e
7986

8087
def check_required(self):
8188
required = [

mongodb_consistent_backup/Upload/S3/S3Session.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import logging
22

3-
from boto import config
4-
from boto.s3.connection import S3Connection
3+
import boto
4+
import boto.s3
55

66

77
class S3Session:
@@ -13,12 +13,12 @@ def __init__(self, access_key, secret_key, s3_host='s3.amazonaws.com', secure=Tr
1313
self.num_retries = num_retries
1414
self.socket_timeout = socket_timeout
1515

16-
for section in config.sections():
17-
config.remove_section(section)
18-
config.add_section('Boto')
19-
config.setbool('Boto', 'is_secure', self.secure)
20-
config.set('Boto', 'http_socket_timeout', str(self.socket_timeout))
21-
config.set('Boto', 'num_retries', str(self.num_retries))
16+
for section in boto.config.sections():
17+
boto.config.remove_section(section)
18+
boto.config.add_section('Boto')
19+
boto.config.setbool('Boto', 'is_secure', self.secure)
20+
boto.config.set('Boto', 'http_socket_timeout', str(self.socket_timeout))
21+
boto.config.set('Boto', 'num_retries', str(self.num_retries))
2222

2323
self._conn = None
2424
self.connect()
@@ -32,7 +32,7 @@ def connect(self):
3232
if not self._conn:
3333
try:
3434
logging.debug("Connecting to AWS S3 with Access Key: %s" % self.access_key)
35-
self._conn = S3Connection(
35+
self._conn = boto.s3.S3Connection(
3636
self.access_key,
3737
self.secret_key,
3838
host=self.s3_host,

mongodb_consistent_backup/__init__.py

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@
1212
# noinspection PyUnusedLocal
1313
def run():
1414
try:
15-
config = Config(submodules=[
16-
"Archive",
17-
"Backup",
18-
"Notify",
19-
"Oplog",
20-
"Replication",
21-
"Upload"
22-
])
15+
config = Config()
2316
except Exception, e:
2417
print "Error setting up configuration: '%s'!" % e
2518
sys.exit(1)

0 commit comments

Comments
 (0)