Gentoo Archives: gentoo-commits

From: "André Erdmann" <dywi@×××××××.de>
To: gentoo-commits@l.g.o
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/config/
Date: Fri, 06 Jul 2012 22:19:23
Message-Id: 1341612624.415683e88e8dedcc7b84c3691213dfca2033b93f.dywi@gentoo
1 commit: 415683e88e8dedcc7b84c3691213dfca2033b93f
2 Author: André Erdmann <dywi <AT> mailerd <DOT> de>
3 AuthorDate: Fri Jul 6 22:10:24 2012 +0000
4 Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
5 CommitDate: Fri Jul 6 22:10:24 2012 +0000
6 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=415683e8
7
8 ConfigTree: fix merge_with (<dict>)
9
10 the config tree will now be merged recursively with the given dict
11
12 modified: roverlay/config/tree.py
13
14 ---
15 roverlay/config/tree.py | 31 +++++++++++++++++++++----------
16 1 files changed, 21 insertions(+), 10 deletions(-)
17
18 diff --git a/roverlay/config/tree.py b/roverlay/config/tree.py
19 index 426343e..dd14fb7 100644
20 --- a/roverlay/config/tree.py
21 +++ b/roverlay/config/tree.py
22 @@ -44,7 +44,19 @@ class ConfigTree ( object ):
23 return ConfigLoader ( self )
24 # --- end of get_loader (...) ---
25
26 - def merge_with ( self, _dict, allow_empty_value=False ):
27 + def merge_with ( self, _dict ):
28 + def merge_dict ( pos, dict_to_merge ):
29 + # this uses references where possible (no copy.[deep]copy,..)
30 + for key, val in dict_to_merge.items():
31 + if not key in pos:
32 + pos [key] = val
33 + elif isinstance ( pos [key], dict ):
34 + merge_dict ( pos [key], val )
35 + else:
36 + pos [key] = val
37 + # --- end of merge_dict (...) ---
38 +
39 +
40 # strategy = theirs
41 # unsafe operation (empty values,...)
42 if not _dict:
43 @@ -53,16 +65,15 @@ class ConfigTree ( object ):
44 elif not isinstance ( _dict, dict ):
45 raise Exception ( "bad usage" )
46
47 - elif allow_empty_value:
48 - self._config.update ( _dict )
49 -
50 - elif sys.version_info >= ( 2, 7 ):
51 - u = { k : v for ( k, v ) in _dict.items() if v or v == 0 }
52 - self._config.update ( u )
53 else:
54 - # FIXME remove < 2.7 statement, roverlay (probably) doesn't work
55 - # with python version prior to 2.7
56 - u = dict ( x for x in _dict.items() if x [1] or x [1] == 0 )
57 + if sys.version_info >= ( 2, 7 ):
58 + u = { k : v for ( k, v ) in _dict.items() if v or v == 0 }
59 + else:
60 + # FIXME remove < 2.7 statement, roverlay (probably) doesn't work
61 + # with python version prior to 2.7
62 + u = dict ( kv for kv in _dict.items() if kv [1] or kv [1] == 0 )
63 +
64 + merge_dict ( self._config, u )
65
66 # --- end of merge_with (...) ---