Skip to content

Commit

Permalink
FIX conf bug
Browse files Browse the repository at this point in the history
  • Loading branch information
mythmgn committed Mar 21, 2016
1 parent 7b6ab6b commit 5765ac0
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 17 deletions.
1 change: 1 addition & 0 deletions cup/ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ Version: 1.5.1
* [New] cup.log - add xxx_if
* [New] cup.thirdp - replace MySQLdb with pymysql.
Use can still use "from cup.thirdp import MySQLdb"
* [Bug] HdfsXmlConf bug. Configure2Dict disorder bug

Version: 1.5.0
* [New] cup.jenkinslib - add jenkins lib with which you can operate on jenkins jobs
Expand Down
48 changes: 31 additions & 17 deletions cup/util/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -625,8 +625,10 @@ def _handle_group_keys(
conf_layer_stack.append(conf_dict_now[groupkey])
return comments

# GLOBAL level 1 [groupA] level 2 [.@groupB] level 3
# [..@groupC] level 4
# GLOBAL level 1
# [groupA] level 2
# [.@groupB] level 3
# [..@groupC] level 4
# pylint: disable=R0912, R0915
def get_dict(self):
"""
Expand All @@ -637,6 +639,7 @@ def get_dict(self):
conf_layer_stack = [self._dict]
num = 0
length = len(self._lines)
last_list_key = None
while num < length:
line = self._lines[num]
if self._handle_comments(comments, line):
Expand All @@ -646,7 +649,7 @@ def get_dict(self):
while isinstance(conf_dict_now, list): # [], find the working dict
conf_dict_now = conf_dict_now[-1]
# line with (key : value)
# line with (@key : value)
# or line with (@key : value)
if isinstance(line, tuple): # key value
num, comments = self._handle_key_value_tuple(
num, conf_dict_now, comments
Expand All @@ -659,8 +662,9 @@ def get_dict(self):
# GLOBAL is the 1st level
level = 1
conf_layer_stack = [self._dict]
# if sth below level cannot be computed as len(line) - len(key)

# [Group1.SubGroup1] sub-key: Value
# if sth below level cannot be computed as len(line) - len(key)
elif '.' in key: # conf_layer_stack back to [self._dict]
conf_layer_stack = [self._dict]
comments = self._handle_group_keys(
Expand All @@ -685,20 +689,24 @@ def get_dict(self):
while isinstance(conf_dict_now, list):
conf_dict_now = conf_dict_now[-1]
if key[0] == '@':
key = key[1:]
if key in conf_dict_now: # the same group
tmpkey = key[1:]
if tmpkey in conf_dict_now: # the same group
# pylint: disable=E1101
# conf_dict_now[tmpkey] = ConfDict()
if tmpkey != last_list_key:
conf_layer_stack[-1] = conf_dict_now[tmpkey]
conf_layer_stack[-1].append_ex(
ConfDict(), comments
)
comments = []
else: # different group
conflist = ConfList()
conflist.append(ConfDict())
conf_dict_now.set_ex(key, conflist, comments)
# conf_dict_now.set_ex(key, conflist, [])
conf_dict_now.set_ex(tmpkey, conflist, comments)
# conf_dict_now.set_ex(tmpkey, conflist, [])
comments = []
conf_layer_stack[-1] = conf_dict_now[key]
conf_layer_stack[-1] = conf_dict_now[tmpkey]
last_list_key = tmpkey
else:
conf_dict_now.set_ex(key, ConfDict(), comments)
comments = []
Expand All @@ -708,15 +716,16 @@ def get_dict(self):
while isinstance(conf_dict_now, list):
conf_dict_now = conf_dict_now[-1]
if key[0] == '@':
key = key[1:]
if key in conf_dict_now: # the same group
conf_layer_stack[level - 1].append(ConfDict())
tmpkey = key[1:]
if tmpkey in conf_dict_now: # the same group
tmpdict = ConfDict()
conf_layer_stack[level - 1].append(tmpdict)
else: # different group
# comments
conflist = ConfList()
conflist.append(ConfDict())
conf_dict_now.set_ex(key, conflist, [])
conf_layer_stack[level - 1] = conf_dict_now[key]
conf_dict_now.set_ex(tmpkey, conflist, [])
conf_layer_stack[level - 1] = conf_dict_now[tmpkey]
else:
conf_dict_now.set_ex(key, ConfDict(), comments)
comments = []
Expand Down Expand Up @@ -1118,12 +1127,17 @@ def _write_to_conf(self, new_confdict):
name = pro.getElementsByTagName('name')[0].childNodes[0].nodeValue
valuenode = pro.getElementsByTagName('value')[0]
if name in tmpdict:
need_modify = False
if valuenode.firstChild is None:
if tmpdict[name]['value'] is not None:
valuenode.appendChild(dom.createTextNode(''))
valuenode.firstChild.replaceWholeText(
tmpdict[name]['value']
)
need_modify = True
else:
need_modify = True
if need_modify:
valuenode.firstChild.replaceWholeText(
tmpdict[name]['value']
)
del tmpdict[name]
else:
parent = pro.parentNode
Expand Down

0 comments on commit 5765ac0

Please sign in to comment.