Merge lp:~verterok/ubuntuone-client/config-read-parsed-values into lp:ubuntuone-client

Proposed by Guillermo Gonzalez
Status: Merged
Approved by: Joshua Blount
Approved revision: 275
Merged at revision: not available
Proposed branch: lp:~verterok/ubuntuone-client/config-read-parsed-values
Merge into: lp:ubuntuone-client
Diff against target: 116 lines (+16/-30)
3 files modified
contrib/test (+2/-0)
tests/syncdaemon/test_config.py (+5/-21)
ubuntuone/syncdaemon/config.py (+9/-9)
To merge this branch: bzr merge lp:~verterok/ubuntuone-client/config-read-parsed-values
Reviewer Review Type Date Requested Status
Joshua Blount (community) Approve
Rick McBride (community) Approve
Review via email: mp+14562@code.launchpad.net

Commit message

Fix syncdaemon Config class to read parsed values, and write plain strings

To post a comment you must log in.
Revision history for this message
Guillermo Gonzalez (verterok) wrote :

Fix syncdaemon Config class to read parsed values, and write plain strings

Revision history for this message
Rick McBride (rmcbride) wrote :

Looks good!

review: Approve
Revision history for this message
Joshua Blount (jblount) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'contrib/test'
2--- contrib/test 2009-09-17 17:24:54 +0000
3+++ contrib/test 2009-11-06 19:40:22 +0000
4@@ -115,6 +115,8 @@
5 # setup a custom XDG_CACHE_HOME and create the logs directory
6 xdg_cache = os.path.join(os.getcwd(), "_trial_temp", "xdg_cache")
7 os.environ["XDG_CACHE_HOME"] = xdg_cache
8+ # setup the ROOT_DIR env var
9+ os.environ['ROOT_DIR'] = os.getcwd()
10 if not os.path.exists(xdg_cache):
11 os.makedirs(xdg_cache)
12 success = 0
13
14=== modified file 'tests/syncdaemon/test_config.py'
15--- tests/syncdaemon/test_config.py 2009-10-30 16:51:39 +0000
16+++ tests/syncdaemon/test_config.py 2009-11-06 19:40:22 +0000
17@@ -52,11 +52,15 @@
18 def setUp(self):
19 BaseTwistedTestCase.setUp(self)
20 self.test_root = self.mktemp()
21+ self.old_get_config_files = config.get_config_files
22+ config.get_config_files = lambda: [os.path.join(os.environ['ROOT_DIR'],
23+ 'data', 'syncdaemon.conf')]
24
25 def tearDown(self):
26 """cleanup everything, also the config module globals"""
27+ config._user_config = None
28+ config.get_config_files = self.old_get_config_files
29 BaseTwistedTestCase.tearDown(self)
30- config._user_config = None
31
32 def assertThrottlingSection(self, expected, current, on, read, write):
33 """Assert for equality two ConfigParser and against the on, read and
34@@ -79,16 +83,6 @@
35 conf_file = os.path.join(self.test_root, 'test_missing_config.conf')
36 # create the config object with an empty config file
37 conf = config._Config(conf_file)
38- # lie a bit and load the defaults, as we can't access the data
39- # dir to get the current config, and a test shouldn't depend on
40- # external data, just fake all the defaults
41- default_conf = os.path.join(self.test_root, 'defaults.conf')
42- with open(default_conf, 'w') as fp:
43- fp.write('[bandwidth_throttling]\n')
44- fp.write('on.default = False\n')
45- fp.write('read_limit.default = -1\n')
46- fp.write('write_limit.default = -1\n')
47- conf.default = config._Config._load_defaults([default_conf])
48 self.assertEquals(False, conf.get_throttling())
49 self.assertEquals(None, conf.get_throttling_read_limit())
50 self.assertEquals(None, conf.get_throttling_write_limit())
51@@ -236,16 +230,6 @@
52 fp.write('on = True\n')
53 fp.write('read_limit = 1\n')
54 conf = config._Config(conf_file)
55- # lie a bit and load the defaults, as we can't access the data
56- # dir to get the current config, and a test shouldn't depend on
57- # external data, just fake all the defaults
58- default_conf = os.path.join(self.test_root, 'defaults.conf')
59- with open(default_conf, 'w') as fp:
60- fp.write('[bandwidth_throttling]\n')
61- fp.write('on.default = False\n')
62- fp.write('read_limit.default = -1\n')
63- fp.write('write_limit.default = -1\n')
64- conf.default = config._Config._load_defaults([default_conf])
65 self.assertEquals(True, conf.get_throttling())
66 self.assertEquals(1, conf.get_throttling_read_limit())
67 self.assertEquals(None, conf.get_throttling_write_limit())
68
69=== modified file 'ubuntuone/syncdaemon/config.py'
70--- ubuntuone/syncdaemon/config.py 2009-11-03 13:23:57 +0000
71+++ ubuntuone/syncdaemon/config.py 2009-11-06 19:40:22 +0000
72@@ -108,7 +108,6 @@
73 # reverse the list as load_config_paths returns the user dir first
74 config_files.reverse()
75 # if we are running from a branch, get the config file from it too
76- #le = os.path.join(os.path.split(os.path.dirname(__file__))[0],
77 config_file = os.path.join('data', CONFIG_FILE)
78 if os.path.exists(config_file):
79 config_files.append(config_file)
80@@ -177,12 +176,15 @@
81 os.rename(self.config_file, self.config_file+'.old')
82 os.rename(self.config_file+'.new', self.config_file)
83
84- def get(self, section, option):
85+ def get_parsed(self, section, option):
86 """custom get that fallback to our custom defaults"""
87 try:
88- return super(_Config, self).get(section, option)
89+ value = super(_Config, self).get(section, option)
90+ # get the parser from the default config
91+ default = self.default.get(section, option)
92+ return default.parser(value)
93 except ConfigParser.NoOptionError, e:
94- return str(self.default.get(section, option).value)
95+ return self.default.get(section, option).value
96
97 # throttling section get/set
98 @requires_section(THROTTLING)
99@@ -199,15 +201,13 @@
100
101 @requires_section(THROTTLING)
102 def get_throttling(self):
103- return self.getboolean(THROTTLING, 'on')
104+ return self.get_parsed(THROTTLING, 'on')
105
106 @requires_section(THROTTLING)
107 def get_throttling_read_limit(self):
108- value = self.getint(THROTTLING, 'read_limit')
109- return throttling_limit_parser(value)
110+ return self.get_parsed(THROTTLING, 'read_limit')
111
112 @requires_section(THROTTLING)
113 def get_throttling_write_limit(self):
114- value = self.getint(THROTTLING, 'write_limit')
115- return throttling_limit_parser(value)
116+ return self.get_parsed(THROTTLING, 'write_limit')
117

Subscribers

People subscribed via source and target branches