~ubuntu-branches/ubuntu/quantal/mysql-workbench/quantal

« back to all changes in this revision

Viewing changes to plugins/wb.admin/gen-opt/recat/parse-cats.py

  • Committer: Package Import Robot
  • Author(s): Dmitry Smirnov
  • Date: 2012-03-01 21:57:30 UTC
  • Revision ID: package-import@ubuntu.com-20120301215730-o7y8av8y38n162ro
Tags: upstream-5.2.38+dfsg
ImportĀ upstreamĀ versionĀ 5.2.38+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/python
 
2
 
 
3
f = open('cats.txt', 'r')
 
4
 
 
5
opts = {}
 
6
 
 
7
for line in f:
 
8
  line = eval('(' + line.strip('\r\n\t ') + ')')
 
9
  opt, section, group = line
 
10
  #print opt, section, group
 
11
  pair = ['','']
 
12
  if opt in opts:
 
13
    pair = opts[opt]
 
14
  else:
 
15
    opts[opt] = pair
 
16
 
 
17
  if section != '':
 
18
    pair[0] = section
 
19
 
 
20
  if group != '':
 
21
    pair[1] = group
 
22
 
 
23
f.close()
 
24
 
 
25
#print opts
 
26
 
 
27
f = open('../mysqld_new.xml', 'r')
 
28
lines = f.readlines()
 
29
f.close()
 
30
 
 
31
#-------------------------------------------------------------------------------
 
32
def move_option(name, section, group, linenr):
 
33
  end_line_nr = None
 
34
  i = linenr
 
35
  while end_line_nr is None:
 
36
    if lines[i].find('</mysqloption>') >= 0:
 
37
      end_line_nr = i + 1
 
38
      break
 
39
    i += 1
 
40
 
 
41
  ui = None
 
42
  for i in range(linenr,end_line_nr):
 
43
    line = lines[i]
 
44
    if line.find('<ui') >= 0:
 
45
      print "Found ui at line", line
 
46
      ui = i
 
47
      break
 
48
 
 
49
  if ui is not None:
 
50
    # Have ui section
 
51
    print "'" + name + "', '" + section + "', '" + group + "'"
 
52
    #print lines[linenr:end_line_nr]
 
53
    #print "======================================\n\n\n"
 
54
  else:
 
55
    # Add ui section
 
56
    insert_linenr = end_line_nr - 1
 
57
    uibody = []
 
58
    uibody.append('    <ui>\n')
 
59
    uibody.append('      <section class="mycnf" collection="' + section + '" group="' + group + '">\n')
 
60
    uibody.append('        <caption value="' + name + '"/>\n')
 
61
    uibody.append('        <description value="' + name + '"/>\n')
 
62
    uibody.append('      </section>\n')
 
63
    uibody.append('    </ui>\n')
 
64
 
 
65
    for uiline in uibody:
 
66
      lines.insert(insert_linenr, uiline)
 
67
      insert_linenr += 1
 
68
 
 
69
#-------------------------------------------------------------------------------
 
70
for name, (section, group) in opts.iteritems():
 
71
  for i, line in enumerate(lines):
 
72
    if line.find('<mysqloption') > 0:
 
73
      if line.find("\"" + name + "\"") > 0:
 
74
        move_option(name, section, group, i)
 
75
        break
 
76
 
 
77
f = open('new.xml', 'w')
 
78
for line in lines:
 
79
  f.write(line)
 
80
f.close()
 
81