Changeset View
Changeset View
Standalone View
Standalone View
tools/manager-file.py
Show All 19 Lines | |||||
20 | # Lesser General Public License for more details. | 20 | # Lesser General Public License for more details. | ||
21 | # | 21 | # | ||
22 | # You should have received a copy of the GNU Lesser General Public | 22 | # You should have received a copy of the GNU Lesser General Public | ||
23 | # License along with this library; if not, write to the Free Software | 23 | # License along with this library; if not, write to the Free Software | ||
24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | 24 | # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | ||
25 | 25 | | |||
26 | import re | 26 | import re | ||
27 | import sys | 27 | import sys | ||
28 | import os | ||||
28 | 29 | | |||
29 | _NOT_C_STR = re.compile(r'[^A-Za-z0-9_-]') | 30 | _NOT_C_STR = re.compile(r'[^A-Za-z0-9_-]') | ||
30 | 31 | | |||
31 | def c_string(x): | 32 | def c_string(x): | ||
32 | # whitelist-based brute force and ignorance - escape nearly all punctuation | 33 | # whitelist-based brute force and ignorance - escape nearly all punctuation | ||
33 | return '"' + _NOT_C_STR.sub(lambda c: r'\x%02x' % ord(c), x) + '"' | 34 | return '"' + _NOT_C_STR.sub(lambda c: r'\x%02x' % ord(c), x) + '"' | ||
34 | 35 | | |||
35 | def desktop_string(x): | 36 | def desktop_string(x): | ||
▲ Show 20 Lines • Show All 46 Lines • ▼ Show 20 Line(s) | 81 | gflags = { | |||
82 | 'register': 'TP_CONN_MGR_PARAM_FLAG_REGISTER', | 83 | 'register': 'TP_CONN_MGR_PARAM_FLAG_REGISTER', | ||
83 | 'required': 'TP_CONN_MGR_PARAM_FLAG_REQUIRED', | 84 | 'required': 'TP_CONN_MGR_PARAM_FLAG_REQUIRED', | ||
84 | 'secret': 'TP_CONN_MGR_PARAM_FLAG_SECRET', | 85 | 'secret': 'TP_CONN_MGR_PARAM_FLAG_SECRET', | ||
85 | 'dbus-property': 'TP_CONN_MGR_PARAM_FLAG_DBUS_PROPERTY', | 86 | 'dbus-property': 'TP_CONN_MGR_PARAM_FLAG_DBUS_PROPERTY', | ||
86 | } | 87 | } | ||
87 | 88 | | |||
88 | def write_manager(f, manager, protos): | 89 | def write_manager(f, manager, protos): | ||
89 | # pointless backwards compat section | 90 | # pointless backwards compat section | ||
90 | print >> f, '[ConnectionManager]' | 91 | print('[ConnectionManager]', file=f) | ||
91 | print >> f, 'BusName=org.freedesktop.Telepathy.ConnectionManager.' + manager | 92 | print('BusName=org.freedesktop.Telepathy.ConnectionManager.' + manager, file=f) | ||
92 | print >> f, 'ObjectPath=/org/freedesktop/Telepathy/ConnectionManager/' + manager | 93 | print('ObjectPath=/org/freedesktop/Telepathy/ConnectionManager/' + manager, file=f) | ||
93 | 94 | | |||
94 | # protocols | 95 | # protocols | ||
95 | for proto, params in protos.iteritems(): | 96 | for proto, params in protos.items(): | ||
96 | print >> f | 97 | print(file=f) | ||
97 | print >> f, '[Protocol %s]' % proto | 98 | print('[Protocol %s]' % proto, file=f) | ||
98 | 99 | | |||
99 | defaults = {} | 100 | defaults = {} | ||
100 | 101 | | |||
101 | for param, info in params.iteritems(): | 102 | for param, info in params.items(): | ||
102 | dtype = info['dtype'] | 103 | dtype = info['dtype'] | ||
103 | flags = info.get('flags', '').split() | 104 | flags = info.get('flags', '').split() | ||
104 | struct_field = info.get('struct_field', param.replace('-', '_')) | 105 | struct_field = info.get('struct_field', param.replace('-', '_')) | ||
105 | filter = info.get('filter', 'NULL') | 106 | filter = info.get('filter', 'NULL') | ||
106 | filter_data = info.get('filter_data', 'NULL') | 107 | filter_data = info.get('filter_data', 'NULL') | ||
107 | setter_data = 'NULL' | 108 | setter_data = 'NULL' | ||
108 | 109 | | |||
109 | if 'default' in info: | 110 | if 'default' in info: | ||
110 | default = fdefaultencoders[dtype](info['default']) | 111 | default = fdefaultencoders[dtype](info['default']) | ||
111 | defaults[param] = default | 112 | defaults[param] = default | ||
112 | 113 | | |||
113 | if flags: | 114 | if flags: | ||
114 | flags = ' ' + ' '.join(flags) | 115 | flags = ' ' + ' '.join(flags) | ||
115 | else: | 116 | else: | ||
116 | flags = '' | 117 | flags = '' | ||
117 | 118 | | |||
118 | print >> f, 'param-%s=%s%s' % (param, desktop_string(dtype), flags) | 119 | print('param-%s=%s%s' % (param, desktop_string(dtype), flags), file=f) | ||
119 | 120 | | |||
120 | for param, default in defaults.iteritems(): | 121 | for param, default in defaults.items(): | ||
121 | print >> f, 'default-%s=%s' % (param, default) | 122 | print('default-%s=%s' % (param, default), file=f) | ||
122 | 123 | | |||
123 | def write_c_params(f, manager, proto, struct, params): | 124 | def write_c_params(f, manager, proto, struct, params): | ||
124 | print >> f, "static const TpCMParamSpec %s_%s_params[] = {" % (manager, proto) | 125 | print("static const TpCMParamSpec %s_%s_params[] = {" % (manager, proto), file=f) | ||
125 | 126 | | |||
126 | for param, info in params.iteritems(): | 127 | for param, info in params.items(): | ||
127 | dtype = info['dtype'] | 128 | dtype = info['dtype'] | ||
128 | flags = info.get('flags', '').split() | 129 | flags = info.get('flags', '').split() | ||
129 | struct_field = info.get('struct_field', param.replace('-', '_')) | 130 | struct_field = info.get('struct_field', param.replace('-', '_')) | ||
130 | filter = info.get('filter', 'NULL') | 131 | filter = info.get('filter', 'NULL') | ||
131 | filter_data = info.get('filter_data', 'NULL') | 132 | filter_data = info.get('filter_data', 'NULL') | ||
132 | setter_data = 'NULL' | 133 | setter_data = 'NULL' | ||
133 | 134 | | |||
134 | if 'default' in info: | 135 | if 'default' in info: | ||
135 | default = gdefaultencoders[dtype](info['default']) | 136 | default = gdefaultencoders[dtype](info['default']) | ||
136 | else: | 137 | else: | ||
137 | default = gdefaultdefaults[dtype] | 138 | default = gdefaultdefaults[dtype] | ||
138 | 139 | | |||
139 | if flags: | 140 | if flags: | ||
140 | flags = ' | '.join([gflags[flag] for flag in flags]) | 141 | flags = ' | '.join([gflags[flag] for flag in flags]) | ||
141 | else: | 142 | else: | ||
142 | flags = '0' | 143 | flags = '0' | ||
143 | 144 | | |||
144 | if struct is None or struct_field is None: | 145 | if struct is None or struct_field is None: | ||
145 | struct_offset = '0' | 146 | struct_offset = '0' | ||
146 | else: | 147 | else: | ||
147 | struct_offset = 'G_STRUCT_OFFSET (%s, %s)' % (struct, struct_field) | 148 | struct_offset = 'G_STRUCT_OFFSET (%s, %s)' % (struct, struct_field) | ||
148 | 149 | | |||
149 | print >> f, (''' { %s, %s, %s, | 150 | print((''' { %s, %s, %s, | ||
150 | %s, | 151 | %s, | ||
151 | %s, /* default */ | 152 | %s, /* default */ | ||
152 | %s, /* struct offset */ | 153 | %s, /* struct offset */ | ||
153 | %s, /* filter */ | 154 | %s, /* filter */ | ||
154 | %s, /* filter data */ | 155 | %s, /* filter data */ | ||
155 | %s /* setter data */ },''' % | 156 | %s /* setter data */ },''' % | ||
156 | (c_string(param), c_string(dtype), gtypes[dtype], flags, | 157 | (c_string(param), c_string(dtype), gtypes[dtype], flags, | ||
157 | default, struct_offset, filter, filter_data, setter_data)) | 158 | default, struct_offset, filter, filter_data, setter_data)), file=f) | ||
158 | 159 | | |||
159 | print >> f, " { NULL }" | 160 | print(" { NULL }", file=f) | ||
160 | print >> f, "};" | 161 | print("};", file=f) | ||
161 | 162 | | |||
162 | if __name__ == '__main__': | 163 | if __name__ == '__main__': | ||
163 | environment = {} | 164 | environment = {} | ||
164 | execfile(sys.argv[1], environment) | 165 | exec(compile(open(sys.argv[1], "rb").read(), sys.argv[1], 'exec'), environment) | ||
165 | 166 | | |||
166 | f = open('%s/%s.manager' % (sys.argv[2], environment['MANAGER']), 'w') | 167 | filename = '%s/%s.manager' % (sys.argv[2], environment['MANAGER']) | ||
168 | try: | ||||
169 | os.remove(filename) | ||||
170 | except OSError: | ||||
171 | pass | ||||
172 | f = open(filename + '.tmp', 'w') | ||||
167 | write_manager(f, environment['MANAGER'], environment['PARAMS']) | 173 | write_manager(f, environment['MANAGER'], environment['PARAMS']) | ||
168 | f.close() | 174 | f.close() | ||
169 | 175 | os.rename(filename + '.tmp', filename) | |||
170 | f = open('%s/param-spec-struct.h' % sys.argv[2], 'w') | 176 | | ||
177 | filename = '%s/param-spec-struct.h' % sys.argv[2] | ||||
178 | try: | ||||
179 | os.remove(filename) | ||||
180 | except OSError: | ||||
181 | pass | ||||
182 | f = open(filename + '.tmp', 'w') | ||||
171 | for protocol in environment['PARAMS']: | 183 | for protocol in environment['PARAMS']: | ||
172 | write_c_params(f, environment['MANAGER'], protocol, | 184 | write_c_params(f, environment['MANAGER'], protocol, | ||
173 | environment['STRUCTS'][protocol], | 185 | environment['STRUCTS'][protocol], | ||
174 | environment['PARAMS'][protocol]) | 186 | environment['PARAMS'][protocol]) | ||
175 | f.close() | 187 | f.close() | ||
188 | os.rename(filename + '.tmp', filename) |