Changeset 765
- Timestamp:
- 06/02/07 13:00:08 (6 years ago)
- Location:
- trunk
- Files:
-
- 7 modified
-
setup.py (modified) (1 diff)
-
umitCore/NmapCommand.py (modified) (2 diffs)
-
umitCore/NmapParser.py (modified) (31 diffs)
-
umitCore/UmitConf.py (modified) (4 diffs)
-
umitGUI/OptionBuilder.py (modified) (4 diffs)
-
umitGUI/ProfileEditor.py (modified) (7 diffs)
-
umitGUI/Wizard.py (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/setup.py
r649 r765 226 226 parser.set(sec, "config_file", config_file) 227 227 parser.set(sec, "config_dir", install_config_dir) 228 parser.set(sec, "docs_dir", os.path.join( install_config_dir, docs_dir))228 parser.set(sec, "docs_dir", os.path.join(self.install_data, docs_dir)) 229 229 parser.set(sec, "pixmaps_dir", os.path.join(self.install_data, pixmaps_dir)) 230 230 parser.set(sec, "icons_dir", os.path.join(self.install_data, icons_dir)) -
trunk/umitCore/NmapCommand.py
r668 r765 263 263 264 264 class CommandConstructor: 265 def __init__(self, profile=None): 265 def __init__(self, options = {}): 266 self.options = {} 266 267 self.option_profile = NmapOptions(option_xml) 267 self.options = {} 268 for k, v in options.items(): 269 self.add_option(k, v, False) # TODO: check this place further 268 270 269 271 def add_option(self, option_name, args=[], level=False): 270 option = self.option_profile.get_option(option_name) 271 272 if type(args) in StringTypes: 273 args = [args] 274 275 if level: 276 self.options[option_name] = (option['option']+' ')*level 277 elif args: 278 args = tuple (args) 279 self.options[option_name] = option['option'] % args[0] 280 else: 281 self.options[option_name] = option['option'] 272 self.options[option_name] = (args, level) 273 282 274 283 275 def remove_option(self, option_name): … … 287 279 def get_command(self, target): 288 280 splited = ['%s' % nmap_command_path] 289 for option in self.options.values(): 290 splited.append(option) 291 281 282 for option_name in self.options: 283 option = self.option_profile.get_option(option_name) 284 args, level = self.options[option_name] 285 286 if type(args) in StringTypes: 287 args = [args] 288 289 if level: 290 splited.append((option['option']+' ')*level) 291 elif args: 292 args = tuple (args) 293 splited.append(option['option'] % args[0]) 294 else: 295 splited.append(option['option']) 296 292 297 splited.append(target) 293 298 return ' '.join(splited) 294 299 295 def __remove_double_space(self, command): 296 while re.findall('( )', command): 297 command = command.replace(' ', ' ') 298 return command 299 300 def get_options(self): 301 return dict([(k, v[0]) for k, v in self.options.items()]) 302 300 303 class CommandThread(threading.Thread): 301 304 def __init__(self, command): -
trunk/umitCore/NmapParser.py
r449 r765 355 355 break 356 356 else: 357 raise Exception("Comment could not be saved! Host not found at NmapParser!") 357 raise Exception("Comment could not be saved! Host not \ 358 found at NmapParser!") 358 359 359 360 def get_host_comment(self, host_id): … … 362 363 return host.comment 363 364 else: 364 raise Exception("Comment could not be saved! Host not found at NmapParser!") 365 raise Exception("Comment could not be saved! Host not \ 366 found at NmapParser!") 365 367 366 368 def get_profile(self): … … 404 406 if (type(options) == type([])) or (type(options) in StringTypes): 405 407 self.nmap['nmaprun']['options'] = options 408 elif type(options) == type({}): 409 self.nmap['nmaprun']['options'] = options.keys() 406 410 else: 407 411 raise Exception("Profile option error: wrong argument format! \ … … 498 502 self.nmap['nmaprun']['start'] = date 499 503 else: 500 raise Exception("Wrong date format. Date should be saved in epoch format!") 504 raise Exception("Wrong date format. Date should be saved \ 505 in epoch format!") 501 506 502 507 def get_openned_ports(self): … … 526 531 def get_formated_date(self): 527 532 date = self.get_date() 528 return "%s %s, %s - %s:%s" % (months[date[1]], str(date[2]), str(date[0]), 529 str(date[3]).zfill(2), str(date[4]).zfill(2)) 533 return "%s %s, %s - %s:%s" % (months[date[1]], 534 str(date[2]), 535 str(date[0]), 536 str(date[3]).zfill(2), 537 str(date[4]).zfill(2)) 530 538 531 539 def get_scanner (self): … … 630 638 631 639 def get_finish_time (self): 632 return time.localtime(int(self.nmap['runstats'].get('finished_time', '0'))) 640 return time.localtime(int(self.nmap['runstats'].get('finished_time', 641 '0'))) 633 642 634 643 def set_finish_time(self, finish): … … 649 658 def get_formated_finish_date(self): 650 659 date = self.get_finish_time() 651 return "%s %s, %s - %s:%s" % (months[date[1]], str(date[2]), str(date[0]), 652 str(date[3]).zfill(2), str(date[4]).zfill(2)) 660 return "%s %s, %s - %s:%s" % (months[date[1]], 661 str(date[2]), 662 str(date[0]), 663 str(date[3]).zfill(2), 664 str(date[4]).zfill(2)) 653 665 654 666 def _verify_output_options (self, command): … … 669 681 profile = property(get_profile, set_profile) 670 682 profile_name = property(get_profile_name, set_profile_name) 671 profile_description = property(get_profile_description, set_profile_description) 683 profile_description = property(get_profile_description, 684 set_profile_description) 672 685 profile_hint = property(get_profile_hint, set_profile_hint) 673 profile_annotation = property(get_profile_annotation, set_profile_annotation) 686 profile_annotation = property(get_profile_annotation, 687 set_profile_annotation) 674 688 profile_options = property(get_profile_options, set_profile_options) 675 689 target = property(get_target, set_target) … … 759 773 self.nmap[run_tag]["scanner"] = attrs.get("scanner", "") 760 774 self.nmap[run_tag]["version"] = attrs.get("version", "") 761 self.nmap[run_tag]["xmloutputversion"] = attrs.get("xmloutputversion", "") 775 self.nmap[run_tag]["xmloutputversion"] = attrs.get("xmloutputversion", 776 "") 762 777 self.nmap["scan_name"] = attrs.get("scan_name", "") 763 778 … … 818 833 819 834 def _parse_host_port(self, attrs): 820 self.dic_port = {"protocol":attrs.get("protocol", ""), "portid":attrs.get("portid", "")} 835 self.dic_port = {"protocol":attrs.get("protocol", ""), 836 "portid":attrs.get("portid", "")} 821 837 822 838 def _parse_host_port_state(self, attrs): … … 835 851 836 852 def _parse_host_portused(self, attrs): 837 self.list_portused.append(self._parsing(attrs, ['state','proto','portid'])) 853 self.list_portused.append(self._parsing(attrs, 854 ['state','proto','portid'])) 838 855 839 856 def _parse_host_osclass(self, attrs): 840 self.list_osclass.append(self._parsing(attrs, ['type','vendor', 'osfamily', 841 'osgen', 'accuracy'])) 857 self.list_osclass.append(self._parsing(attrs, ['type', 858 'vendor', 859 'osfamily', 860 'osgen', 861 'accuracy'])) 842 862 843 863 def _parsing(self, attrs, attrs_list): 844 # Returns a dict with the attributes of a given tag with the atributes names845 # a s keys and their respective values864 # Returns a dict with the attributes of a given tag with the 865 # atributes names as keys and their respective values 846 866 dic = {} 847 867 for at in attrs_list: … … 854 874 855 875 def _parse_host_tcpsequence(self, attrs): 856 self.host_info.set_tcpsequence(self._parsing(attrs, ['index', 'class', 857 'difficulty', 'values'])) 876 self.host_info.set_tcpsequence(self._parsing(attrs, ['index', 877 'class', 878 'difficulty', 879 'values'])) 858 880 859 881 def _parse_host_tcptssequence(self, attrs): 860 self.host_info.set_tcptssequence(self._parsing(attrs, ['class', 'values'])) 882 self.host_info.set_tcptssequence(self._parsing(attrs, ['class', 883 'values'])) 861 884 862 885 def _parse_host_ipidsequence(self, attrs): 863 self.host_info.set_ipidsequence(self._parsing(attrs, ['class', 'values'])) 886 self.host_info.set_ipidsequence(self._parsing(attrs, ['class', 887 'values'])) 864 888 865 889 def startElement(self, name, attrs): … … 900 924 self.in_port = True 901 925 self._parse_host_port(attrs) 902 elif self.in_host and self.in_ports and self.in_port and name == "state": 926 elif self.in_host and self.in_ports and \ 927 self.in_port and name == "state": 903 928 self._parse_host_port_state(attrs) 904 elif self.in_host and self.in_ports and self.in_port and name == "service": 929 elif self.in_host and self.in_ports and \ 930 self.in_port and name == "service": 905 931 self._parse_host_port_service(attrs) 906 932 elif self.in_host and name == "os": … … 937 963 elif self.in_host and name == "ports": 938 964 self.in_ports = False 939 self.list_ports.append({"extraports":self.list_extraports, "port":self.list_port}) 965 self.list_ports.append({"extraports":self.list_extraports, 966 "port":self.list_port}) 940 967 elif self.in_host and self.in_ports and name == "port": 941 968 self.in_port = False … … 986 1013 ## Finished element 987 1014 self.write_parser.startElement("finished", 988 Attributes(dict(time = str(self.finish_epoc_time))))1015 Attributes(dict(time = str(self.finish_epoc_time)))) 989 1016 self.write_parser.endElement("finished") 990 1017 991 1018 ## Hosts element 992 self.write_parser.startElement("hosts", Attributes(dict(up = str(self.hosts_up), 993 down = str(self.hosts_down), 994 total = str(self.hosts_scanned)))) 1019 self.write_parser.startElement("hosts", 1020 Attributes(dict(up = str(self.hosts_up), 1021 down = str(self.hosts_down), 1022 total = str(self.hosts_scanned)))) 995 1023 self.write_parser.endElement("hosts") 996 1024 … … 1003 1031 for host in self.hosts: 1004 1032 # Start host element 1005 self.write_parser.startElement("host", Attributes(dict(comment=host.comment))) 1033 self.write_parser.startElement("host", 1034 Attributes(dict(comment=host.comment))) 1006 1035 1007 1036 # Status element 1008 self.write_parser.startElement("status", Attributes(dict(state=host.state))) 1037 self.write_parser.startElement("status", 1038 Attributes(dict(state=host.state))) 1009 1039 self.write_parser.endElement("status") 1010 1040 … … 1015 1045 if type(host.ip) == type({}): 1016 1046 self.write_parser.startElement("address", 1017 Attributes(dict(addr=host.ip.get("addr", ""),1018 vendor=host.ip.get("vendor", ""),1019 addrtype=host.ip.get("type", ""))))1047 Attributes(dict(addr=host.ip.get("addr", ""), 1048 vendor=host.ip.get("vendor", ""), 1049 addrtype=host.ip.get("type", "")))) 1020 1050 self.write_parser.endElement("address") 1021 1051 … … 1023 1053 if type(host.ipv6) == type({}): 1024 1054 self.write_parser.startElement("address", 1025 Attributes(dict(addr=host.ipv6.get("addr", ""),1026 vendor=host.ipv6.get("vendor", ""),1027 addrtype=host.ipv6.get("type", ""))))1055 Attributes(dict(addr=host.ipv6.get("addr", ""), 1056 vendor=host.ipv6.get("vendor", ""), 1057 addrtype=host.ipv6.get("type", "")))) 1028 1058 self.write_parser.endElement("address") 1029 1059 … … 1031 1061 if type(host.mac) == type({}): 1032 1062 self.write_parser.startElement("address", 1033 Attributes(dict(addr=host.mac.get("addr", ""),1034 vendor=host.mac.get("vendor", ""),1035 addrtype=host.mac.get("type", ""))))1063 Attributes(dict(addr=host.mac.get("addr", ""), 1064 vendor=host.mac.get("vendor", ""), 1065 addrtype=host.mac.get("type", "")))) 1036 1066 self.write_parser.endElement("address") 1037 1067 # End of Address elements … … 1046 1076 if type(hname) == type({}): 1047 1077 self.write_parser.startElement("hostname", 1048 Attributes(dict(name = hname.get("hostname", ""),1049 type = hname.get("hostname_type", ""))))1078 Attributes(dict(name = hname.get("hostname", ""), 1079 type = hname.get("hostname_type", "")))) 1050 1080 1051 1081 self.write_parser.endElement("hostname") … … 1065 1095 if type(ext) == type({}): 1066 1096 self.write_parser.startElement("extraports", 1067 Attributes(dict(count = ext.get("count", ""),1068 state = ext.get("state", ""))))1097 Attributes(dict(count = ext.get("count", ""), 1098 state = ext.get("state", "")))) 1069 1099 self.write_parser.endElement("extraports") 1070 1100 … … 1073 1103 if type(p) == type({}): 1074 1104 self.write_parser.startElement("port", 1075 Attributes(dict(portid = p.get("portid", ""),1076 protocol = p.get("protocol", ""))))1105 Attributes(dict(portid = p.get("portid", ""), 1106 protocol = p.get("protocol", "")))) 1077 1107 1078 1108 ### Port state 1079 1109 self.write_parser.startElement("state", 1080 Attributes(dict(state=p.get("port_state", ""))))1110 Attributes(dict(state=p.get("port_state", "")))) 1081 1111 self.write_parser.endElement("state") 1082 1112 1083 1113 ### Port service info 1084 1114 self.write_parser.startElement("service", 1085 Attributes(dict(conf = p.get("service_conf", ""), 1086 method = p.get("service_method", ""), 1087 name = p.get("service_name", ""), 1088 product = p.get("service_product", ""), 1089 version = p.get("service_version", ""), 1090 extrainfo = p.get("service_extrainfo", "")))) 1115 Attributes(dict(conf = p.get("service_conf", ""), 1116 method = p.get("service_method", ""), 1117 name = p.get("service_name", ""), 1118 product = p.get("service_product", ""), 1119 version = p.get("service_version", ""), 1120 extrainfo = p.get("service_extrainfo", "")\ 1121 ))) 1091 1122 self.write_parser.endElement("service") 1092 1123 … … 1106 1137 if type(pu) == type({}): 1107 1138 self.write_parser.startElement("portused", 1108 Attributes(dict(state = pu.get("state", ""),1109 proto = pu.get("proto", ""),1110 portid = pu.get("portid", ""))))1139 Attributes(dict(state = pu.get("state", ""), 1140 proto = pu.get("proto", ""), 1141 portid = pu.get("portid", "")))) 1111 1142 self.write_parser.endElement("portused") 1112 1143 … … 1115 1146 if type(oc) == type({}): 1116 1147 self.write_parser.startElement("osclass", 1117 Attributes(dict(vendor = oc.get("vendor", ""),1118 osfamily = oc.get("osfamily", ""),1119 type = oc.get("type", ""),1120 osgen = oc.get("osgen", ""),1121 accuracy = oc.get("accuracy", ""))))1148 Attributes(dict(vendor = oc.get("vendor", ""), 1149 osfamily = oc.get("osfamily", ""), 1150 type = oc.get("type", ""), 1151 osgen = oc.get("osgen", ""), 1152 accuracy = oc.get("accuracy", "")))) 1122 1153 self.write_parser.endElement("osclass") 1123 1154 … … 1125 1156 if type(host.osmatch) == type({}): 1126 1157 self.write_parser.startElement("osmatch", 1127 Attributes(dict(name = host.osmatch.get("name", ""),1128 accuracy = host.osmatch.get("accuracy", ""))))1158 Attributes(dict(name = host.osmatch.get("name", ""), 1159 accuracy = host.osmatch.get("accuracy", "")))) 1129 1160 self.write_parser.endElement("osmatch") 1130 1161 … … 1136 1167 if type(host.uptime) == type({}): 1137 1168 self.write_parser.startElement("uptime", 1138 Attributes(dict(seconds = host.uptime.get("seconds", ""),1139 lastboot = host.uptime.get("lastboot", ""))))1169 Attributes(dict(seconds = host.uptime.get("seconds", ""), 1170 lastboot = host.uptime.get("lastboot", "")))) 1140 1171 self.write_parser.endElement("uptime") 1141 1172 … … 1146 1177 if type(host.tcpsequence) == type({}): 1147 1178 self.write_parser.startElement("tcpsequence", 1148 Attributes({"index":host.tcpsequence.get("index", ""),1149 "class":host.tcpsequence.get("class", ""),1150 "difficulty":host.tcpsequence.get("difficulty", ""),1151 "values":host.tcpsequence.get("values", "")}))1179 Attributes({"index":host.tcpsequence.get("index", ""), 1180 "class":host.tcpsequence.get("class", ""), 1181 "difficulty":host.tcpsequence.get("difficulty", ""), 1182 "values":host.tcpsequence.get("values", "")})) 1152 1183 self.write_parser.endElement("tcpsequence") 1153 1184 … … 1155 1186 if type(host.ipidsequence) == type({}): 1156 1187 self.write_parser.startElement("ipidsequence", 1157 Attributes({"class":host.ipidsequence.get("class", ""),1158 "values":host.ipidsequence.get("values", "")}))1188 Attributes({"class":host.ipidsequence.get("class", ""), 1189 "values":host.ipidsequence.get("values", "")})) 1159 1190 self.write_parser.endElement("ipidsequence") 1160 1191 … … 1162 1193 if type(host.tcptssequence) == type({}): 1163 1194 self.write_parser.startElement("tcptssequence", 1164 Attributes({"class":host.tcptssequence.get("class", ""),1165 "values":host.tcptssequence.get("values", "")}))1195 Attributes({"class":host.tcptssequence.get("class", ""), 1196 "values":host.tcptssequence.get("values", "")})) 1166 1197 self.write_parser.endElement("tcptssequence") 1167 1198 # End of sequences elements … … 1173 1204 def _write_debugging(self): 1174 1205 self.write_parser.startElement("debugging", Attributes(dict( 1175 level=str(self.debugging_level))))1206 level=str(self.debugging_level)))) 1176 1207 self.write_parser.endElement("debugging") 1177 1208 1178 1209 def _write_verbose(self): 1179 1210 self.write_parser.startElement("verbose", Attributes(dict( 1180 level=str(self.verbose_level))))1211 level=str(self.verbose_level)))) 1181 1212 self.write_parser.endElement("verbose") 1182 1213 … … 1185 1216 if type(scan) == type({}): 1186 1217 self.write_parser.startElement("scaninfo", 1187 Attributes(dict(type = scan.get("type", ""),1188 protocol = scan.get("protocol", ""),1189 numservices = scan.get("numservices", ""),1190 services = scan.get("services", ""))))1218 Attributes(dict(type = scan.get("type", ""), 1219 protocol = scan.get("protocol", ""), 1220 numservices = scan.get("numservices", ""), 1221 services = scan.get("services", "")))) 1191 1222 self.write_parser.endElement("scaninfo") 1192 1223 1193 1224 def _write_nmaprun(self): 1194 1225 self.write_parser.startElement("nmaprun", 1195 Attributes(dict(annotation = str(self.profile_annotation),1196 args = str(self.nmap_command),1197 description = str(self.profile_description),1198 hint = str(self.profile_hint),1199 nmap_output = str(self.nmap_output),1200 options = str(self.profile_options),1201 profile = str(self.profile),1202 profile_name = str(self.profile_name),1203 scanner = str(self.scanner),1204 start = str(self.start),1205 startstr = str(self.formated_date),1206 target = str(self.target),1207 version = str(self.scanner_version),1208 scan_name = str(self.scan_name))))1226 Attributes(dict(annotation = str(self.profile_annotation), 1227 args = str(self.nmap_command), 1228 description = str(self.profile_description), 1229 hint = str(self.profile_hint), 1230 nmap_output = str(self.nmap_output), 1231 options = str(self.profile_options), 1232 profile = str(self.profile), 1233 profile_name = str(self.profile_name), 1234 scanner = str(self.scanner), 1235 start = str(self.start), 1236 startstr = str(self.formated_date), 1237 target = str(self.target), 1238 version = str(self.scanner_version), 1239 scan_name = str(self.scan_name)))) 1209 1240 1210 1241 def _verify_file(self, xml_file): -
trunk/umitCore/UmitConf.py
r649 r765 24 24 25 25 from types import StringTypes 26 from ConfigParser import NoSectionError 26 from ConfigParser import NoSectionError, NoOptionError 27 27 28 28 from umitCore.Paths import Path … … 207 207 except: return None 208 208 209 [self._set_it(profile_name, attr, attributes[attr]) for attr in attributes] 209 [self._set_it(profile_name, attr, attributes[attr]) for attr in attributes if attr != "options"] 210 options = attributes["options"] 211 self._set_it(profile_name, "options", ",".join(options.keys())) 212 for opt in options: 213 if options[opt]: 214 self._set_it(profile_name, opt, options[opt]) 210 215 self.save_changes() 211 216 … … 239 244 240 245 def get_options(self, profile): 241 return self._get_it(profile, 'options').split(',') 242 246 dic = {} 247 for opt in self._get_it(profile, 'options').split(','): 248 try: 249 dic[unicode(opt.strip())] = self._get_it(profile, opt) 250 except NoOptionError: 251 dic[unicode(opt.strip())] = None 252 return dic 243 253 244 254 def set_command(self, profile, command=''): … … 254 264 self._set_it(profile, 'annotation', annotation) 255 265 256 def set_options(self, profile, options=''): 257 self._set_it(profile, 'options', options) 266 def set_options(self, profile, options={}): 267 for opt in options: 268 if options[opt]: 269 self._set_it(profile, opt, options[opt]) 270 self._set_it(profile, 'options', ",".join(options.keys())) 258 271 259 272 def get_profile(self, profile_name): -
trunk/umitGUI/OptionBuilder.py
r489 r765 35 35 36 36 37 class OptionTab(object): 38 def __init__(self, root_tab, options, constructor, update_func): 39 actions = {'option_list':self.__parse_option_list,\ 40 'option_check':self.__parse_option_check} 41 42 self.options = options 43 self.constructor = constructor 44 self.update_func = update_func 45 self.widgets_list = [] 46 47 options_used = self.constructor.get_options() 48 49 # Cannot use list comprehhension because text nodes raise exception 50 # when tagName is called 51 for option_element in root_tab.childNodes: 52 try:option_element.tagName 53 except:pass 54 else: 55 if option_element.tagName in actions.keys(): 56 self.widgets_list.append(actions[option_element.tagName](option_element, options_used)) 57 58 def __parse_option_list(self, option_list, options_used): 59 options = option_list.getElementsByTagName(u'option') 60 61 label = HIGEntryLabel(option_list.getAttribute(u'label')) 62 opt_list = OptionList() 63 64 for opt in options: 65 opt_list.append(self.options.get_option(opt.getAttribute(u'name'))) 66 67 for i, row in enumerate(opt_list.list): 68 if row[0] in options_used: 69 opt_list.set_active(i) 70 71 return label, opt_list 72 73 def __parse_option_check(self, option_check, options_used): 74 arg_type = option_check.getAttribute(u'arg_type') 75 option = option_check.getAttribute(u'option') 76 label = option_check.getAttribute(u'label') 77 78 check = OptionCheck(label, self.options.get_option(option)) 79 check.set_active(option in options_used) 80 81 type_mapping = { 82 "str": OptionEntry, 83 "int": OptionIntSpin, 84 "float": OptionFloatSpin, 85 "level": OptionLevelSpin, 86 "path": OptionFile, 87 "interface": OptionInterface 88 } 89 90 additional = None 91 if type_mapping.has_key(arg_type): 92 value = options_used.get(option, None) 93 if value: 94 additional = type_mapping[arg_type](value) 95 else: 96 additional = type_mapping[arg_type]() 97 98 check.connect('toggled', self.update_check, additional) 99 100 return check, additional 101 102 def fill_table(self, table, expand_fill = True): 103 yopt = (0, gtk.EXPAND | gtk.FILL)[expand_fill] 104 for y, widget in enumerate(self.widgets_list): 105 if widget[1] == None: 106 table.attach(widget[0], 0, 2, y, y+1, yoptions=yopt) 107 else: 108 table.attach(widget[0], 0, 1, y, y+1, yoptions=yopt) 109 table.attach(widget[1], 1, 2, y, y+1, yoptions=yopt) 110 111 for widget in self.widgets_list: 112 te = type(widget[1]) 113 if te == type(OptionList()): 114 widget[1].connect('changed',self.update_list_option) 115 elif te == type(OptionIntSpin()) or\ 116 te == type(OptionFloatSpin()) or\ 117 te == type(OptionEntry()): 118 widget[1].connect('changed', self.update_entry, widget[0]) 119 elif te == type(OptionLevelSpin()): 120 widget[1].connect('changed', self.update_level, widget[0]) 121 elif te == type(OptionFile()): 122 widget[1].entry.connect('changed', self.update_entry, widget[0]) 123 elif te == type(OptionInterface()): 124 widget[1].child.connect('changed', self.update_entry, widget[0]) 125 126 def update_check(self, check, extra): 127 if check.get_active(): 128 te = type(extra) 129 if te == type(OptionEntry()) or\ 130 te == type(OptionIntSpin()) or\ 131 te == type(OptionFloatSpin()): 132 self.update_entry(extra, check) 133 elif te == type(OptionLevelSpin()): 134 self.update_level(extra, check) 135 elif te == type(OptionFile()): 136 self.update_entry(extra.entry, check) 137 elif te == type(OptionInterface()): 138 self.update_entry(extra.child, check) 139 else: 140 self.constructor.add_option(check.option['name']) 141 else: 142 self.constructor.remove_option(check.option['name']) 143 144 self.update_command() 145 146 def update_entry(self, widget, check): 147 if not check.get_active(): 148 check.set_active(True) 149 150 self.constructor.remove_option(check.option['name']) 151 self.constructor.add_option(check.option['name'], widget.get_text()) 152 153 self.update_command() 154 155 def update_level(self, widget, check): 156 if not check.get_active(): 157 check.set_active(True) 158 159 try: 160 self.constructor.remove_option(check.option['name']) 161 if int(widget.get_text()) == 0: 162 check.set_active(False) 163 else: 164 self.constructor.add_option(check.option['name'],\ 165 level=int(widget.get_text())) 166 except:pass 167 168 self.update_command() 169 170 def update_list_option(self, widget): 171 try:widget.last_selected 172 except:pass 173 else: 174 self.constructor.remove_option(widget.last_selected) 175 176 option_name = widget.options[widget.get_active()]['name'] 177 178 self.constructor.add_option(option_name) 179 widget.last_selected = option_name 180 181 self.update_command() 182 183 def update_command(self): 184 if self.update_func: 185 self.update_func() 186 187 37 188 class OptionBuilder(object): 38 def __init__(self, xml_file): 189 def __init__(self, xml_file, constructor, update_func): 190 """ OptionBuilder(xml_file, constructor) 191 192 xml_file is a UI description xml-file 193 constructor is a CommandConstructor instance 194 """ 39 195 xml_desc = open(xml_file) 40 196 self.xml = minidom.parse(xml_desc) 41 42 197 # Closing file to avoid problems with file descriptors 43 198 xml_desc.close() 199 200 self.constructor = constructor 201 self.update_func = update_func 44 202 45 203 self.root_tag = "interface" 46 self.actions = {'option_list':self.__parse_option_list,\47 'option_check':self.__parse_option_check}48 204 49 205 self.xml = self.xml.getElementsByTagName(self.root_tag)[0] … … 69 225 dic = {} 70 226 for tab_name in self.groups: 71 tab = self.xml.getElementsByTagName(tab_name)[0] 72 widgets_list = [] 73 # Cannot use list comprehhension because text nodes raise exception 74 # when tagName is called 75 for option in tab.childNodes: 76 try:option.tagName 77 except:pass 78 else: 79 if option.tagName in self.actions.keys(): 80 widgets_list.append\ 81 (self.actions[option.tagName](option)) 82 83 dic[tab_name] = widgets_list 84 227 dic[tab_name] = OptionTab(self.xml.getElementsByTagName(tab_name)[0], 228 self.options, self.constructor, self.update_func) 85 229 return dic 86 87 def __parse_option_list(self, option_list): 88 options = option_list.getElementsByTagName(u'option') 89 90 label = HIGEntryLabel(option_list.getAttribute(u'label')) 91 opt_list = OptionList() 92 93 for opt in options: 94 opt_list.append(self.options.get_option\ 95 (opt.getAttribute(u'name'))) 96 97 return label, opt_list 98 99 def __parse_option_check(self, option_check): 100 arg_type = option_check.getAttribute(u'arg_type') 101 option = option_check.getAttribute(u'option') 102 label = option_check.getAttribute(u'label') 103 104 check = OptionCheck(label, self.options.get_option\ 105 (option_check.getAttribute(u'option'))) 106 additional = None 107 108 if arg_type == "str": 109 additional = OptionEntry() 110 elif arg_type == "int": 111 additional = OptionIntSpin() 112 elif arg_type == "float": 113 additional = OptionFloatSpin() 114 elif arg_type == "level": 115 additional = OptionLevelSpin() 116 elif arg_type == "path": 117 additional = OptionFile() 118 elif arg_type == "interface": 119 additional = OptionInterface() 120 121 return check, additional 122 230 231 123 232 class OptionWidget: 124 233 def enable_widget(self): … … 163 272 164 273 class OptionEntry(gtk.Entry, OptionWidget): 165 def __init__(self ):274 def __init__(self, param = ""): 166 275 gtk.Entry.__init__(self) 276 self.set_text(param) 167 277 168 278 class OptionLevelSpin(gtk.SpinButton, OptionWidget): 169 279 def __init__(self, initial=0): 170 gtk.SpinButton.__init__(self,gtk.Adjustment(in itial,0,10,1),0.0,0)280 gtk.SpinButton.__init__(self,gtk.Adjustment(int(initial),0,10,1),0.0,0) 171 281 172 282 class OptionIntSpin(gtk.SpinButton, OptionWidget): 173 283 def __init__(self, initial=1): 174 gtk.SpinButton.__init__(self,gtk.Adjustment(in itial,0,10**100,1),0.0,0)284 gtk.SpinButton.__init__(self,gtk.Adjustment(int(initial),0,10**100,1),0.0,0) 175 285 176 286 class OptionFloatSpin(gtk.SpinButton, OptionWidget): 177 287 def __init__(self, initial=1): 178 gtk.SpinButton.__init__(self,gtk.Adjustment( initial,0,10**100,1),0.1,2)288 gtk.SpinButton.__init__(self,gtk.Adjustment(float(initial),0,10**100,1),0.1,2) 179 289 180 290 class OptionFile(HIGHBox, OptionWidget, object): 181 def __init__(self ):291 def __init__(self, param=""): 182 292 HIGHBox.__init__(self) 183 293 … … 187 297 self._pack_expand_fill(self.entry) 188 298 self._pack_noexpand_nofill(self.button) 189 299 300 self.entry.set_text(param) 190 301 self.button.connect('clicked', self.open_dialog_cb) 191 302 -
trunk/umitGUI/ProfileEditor.py
r508 r765 50 50 self.__pack_widgets() 51 51 52 self.options = OptionBuilder(profile_editor)53 54 log.debug("Option groups: %s" % str(self.options.groups))55 log.debug("Option section names: %s" % str(self.options.section_names))56 #log.debug("Option tabs: %s" % str(self.options.tabs))57 58 self.constructor = CommandConstructor()59 52 self.profile = CommandProfile() 60 53 61 54 self.deleted = False 62 self.options_used = []55 options_used = {} 63 56 64 57 if profile_name: 65 58 log.debug("Showing profile %s" % profile_name) 66 59 prof = self.profile.get_profile(profile_name) 67 self.options_used = prof['options']68 60 options_used = prof['options'] 61 69 62 # Interface settings 70 63 self.profile_name_entry.set_text(profile_name) … … 77 70 self.profile.remove_profile(profile_name) 78 71 self.deleted = True 72 73 self.constructor = CommandConstructor(options_used) 74 self.options = OptionBuilder(profile_editor, self.constructor, self.update_command) 75 log.debug("Option groups: %s" % str(self.options.groups)) 76 log.debug("Option section names: %s" % str(self.options.section_names)) 77 #log.debug("Option tabs: %s" % str(self.options.tabs)) 79 78 80 79 for tab in self.options.groups: … … 99 98 self.command_expander.set_expanded(True) 100 99 self.command_entry = gtk.Entry() 101 102 self.widgets = {}103 100 104 101 self.notebook = gtk.Notebook() … … 176 173 self.buttons_hbox.set_spacing(6) 177 174 178 def __create_tab(self, tab_name, section_name, tab_widgets): 175 def __create_tab(self, tab_name, section_name, tab): 176 log.debug(">>> Tab name: %s" % tab_name) 177 log.debug(">>>Creating profile editor section: %s" % section_name) 178 179 179 vbox = HIGVBox() 180 180 table = HIGTable() 181 181 section = HIGSectionLabel(section_name) 182 log.debug(">>> Tab name: %s" % tab_name)183 log.debug(">>>Creating profile editor section: %s" % section_name)184 182 185 183 vbox._pack_noexpand_nofill(section) 186 184 vbox._pack_noexpand_nofill(HIGSpacer(table)) 187 188 185 vbox.set_border_width(5) 189 190 self.widgets[tab_name] = tab_widgets 191 192 y1 = 0 193 y2 = 1 194 195 for widget in tab_widgets: 196 log.debug(">>> Widget: %s" % str(widget)) 197 198 if widget[1] == None: 199 table.attach(widget[0],0,2,y1,y2) 200 else: 201 table.attach(widget[0],0,1,y1,y2) 202 table.attach(widget[1],1,2,y1,y2) 203 204 if type(widget[0]) == type(OptionCheck()): 205 widget[0].connect('toggled', self.update_check, widget[1]) 206 207 if widget[0].option['name'] in self.options_used: 208 widget[0].set_active(True) 209 210 te = type(widget[1]) 211 212 if te == type(OptionList()): 213 widget[1].connect('changed',self.update_list_option) 214 215 for wid in range(widget[1].list.__len__()): 216 if widget[1].list[wid][0] in self.options_used: 217 widget[1].set_active(wid) 218 elif te == type(OptionIntSpin()) or\ 219 te == type(OptionFloatSpin()) or\ 220 te == type(OptionEntry()): 221 widget[1].connect('changed', self.update_entry, widget[0]) 222 elif te == type(OptionLevelSpin()): 223 widget[1].connect('changed', self.update_level, widget[0]) 224 elif te == type(OptionFile()): 225 widget[1].entry.connect('changed', self.update_entry, widget[0]) 226 227 y1+=1;y2+=1 186 187 tab.fill_table(table, True) 228 188 229 189 self.notebook.append_page(vbox, gtk.Label(tab_name)) 230 231 def update_entry(self, widget, check):232 if not check.get_active():233 check.set_active(True)234 235 self.constructor.remove_option(check.option['name'])236 self.constructor.add_option(check.option['name'], widget.get_text())237 self.update_command()238 239 def update_level(self, widget, check):240 if not check.get_active():241 check.set_active(True)242 243 try:244 self.constructor.remove_option(check.option['name'])245 if int(widget.get_text()) == 0:246 check.set_active(False)247 else:248 self.constructor.add_option(check.option['name'],\249 level=int(widget.get_text()))250 except:pass251 self.update_command()252 190 253 191 def save_profile(self, widget): … … 275 213 annotation = buf.get_text(buf.get_start_iter(),\ 276 214 buf.get_end_iter()) 277 215 278 216 self.profile.add_profile(profile_name,\ 279 217 command=command,\ … … 281 219 description=description,\ 282 220 annotation=annotation,\ 283 options= ','.join(self.options_used))221 options=self.constructor.get_options()) 284 222 285 223 self.deleted = False … … 291 229 self.profile_description_text.get_buffer().set_text('') 292 230 self.profile_annotation_text.get_buffer().set_text('') 293 294 def update_list_option(self, widget):295 try:widget.last_selected296 except:pass297 else:298 self.constructor.remove_option(widget.last_selected)299 try:del(self.options_used[self.options_used.index\300 (widget.last_selected)])301 except:pass302 303 option_name = widget.options[widget.get_active()]['name']304 305 self.constructor.add_option(option_name)306 self.options_used.append(option_name)307 widget.last_selected = option_name308 309 self.update_command()310 311 def update_check(self, check, extra):312 if check.get_active():313 te = type(extra)314 if te == type(OptionEntry()) or\315 te == type(OptionIntSpin()) or\316 te == type(OptionFloatSpin()):317 self.update_entry(extra, check)318 elif te == type(OptionLevelSpin()):319 self.update_level(extra, check)320 elif te == type(OptionFile()):321 self.update_entry(extra.entry, check)322 elif te == type(OptionInterface()):323 self.update_entry(extra.child, check)324 else:325 self.constructor.add_option(check.option['name'])326 self.update_command()327 328 self.options_used.append(check.option['name'])329 else:330 self.constructor.remove_option(check.option['name'])331 self.update_command()332 try:del(self.options_used[self.options_used.index\333 (check.option['name'])])334 except:pass335 336 #print self.options_used337 231 338 232 def set_notebook(self, notebook): -
trunk/umitGUI/Wizard.py
r664 r765 50 50 self.set_position(gtk.WIN_POS_CENTER) 51 51 52 self. options = OptionBuilder(wizard)52 self.profile = CommandProfile() 53 53 self.constructor = CommandConstructor() 54 self.profile = CommandProfile() 55 self.options_used = [] 54 self.options = OptionBuilder(wizard, self.constructor, self.update_command) 56 55 57 56 self.target = '<target>' … … 98 97 99 98 def __create_steps(self, step_name, back_step, next_step, step_description, content): 100 step = CommandPage(step_description, content, self) 101 step.bar.cancel.connect('clicked', self.close_wizard) 102 step.bar.help.connect('clicked', self._show_help) 103 step.bar.back.connect('clicked', self.switch_page, step_name, back_step) 104 step.bar.forward.connect('clicked', self.switch_page, step_name, next_step) 105 106 return step 99 vbox = HIGVBox() 100 vbox.set_spacing(12) 101 102 description = HIGEntryLabel(step_description) 103 bar = ForwardBar() 104 table = HIGTable() 105 106 vbox._pack_noexpand_nofill(description) 107 vbox._pack_expand_fill(table) 108 vbox._pack_noexpand_nofill(bar) 109 110 content.fill_table(table, False) 111 112 bar.cancel.connect('clicked', self.close_wizard) 113 bar.help.connect('clicked', self._show_help) 114 bar.back.connect('clicked', self.switch_page, step_name, back_step) 115 bar.forward.connect('clicked', self.switch_page, step_name, next_step) 116 117 return vbox 107 118 108 119 def set_notebook(self, notebook): … … 288 299 pass 289 300 290 def update_entry(self, widget, check):291 if not check.get_active():292 check.set_active(True)293 294 self.constructor.remove_option(check.option['name'])295 self.constructor.add_option(check.option['name'], widget.get_text())296 self.update_command()297 298 def update_level(self, widget, check):299 if not check.get_active():300 check.set_active(True)301 302 try:303 self.constructor.remove_option(check.option['name'])304 if int(widget.get_text()) == 0:305 check.set_active(False)306 else:307 self.constructor.add_option(check.option['name'],\308 level=int(widget.get_text()))309 except:pass310 self.update_command()311 312 def update_list_option(self, widget):313 try:widget.last_selected314 except:pass315 else:316 self.constructor.remove_option(widget.last_selected)317 try:del(self.options_used[self.options_used.index\318 (widget.last_selected)])319 except:pass320 321 option_name = widget.options[widget.get_active()]['name']322 323 self.constructor.add_option(option_name)324 self.options_used.append(option_name)325 widget.last_selected = option_name326 327 self.update_command()328 329 def update_check(self, check, extra):330 if check.get_active():331 te = type(extra)332 if te == type(OptionEntry()) or\333 te == type(OptionIntSpin()) or\334 te == type(OptionFloatSpin()):335 self.update_entry(extra, check)336 elif te == type(OptionLevelSpin()):337 self.update_level(extra, check)338 elif te == type(OptionFile()):339 self.update_entry(extra.entry, check)340 elif te == type(OptionInterface()):341 self.update_entry(extra.child, check)342 else:343 self.constructor.add_option(check.option['name'])344 self.update_command()345 346 self.options_used.append(check.option['name'])347 else:348 self.constructor.remove_option(check.option['name'])349 self.update_command()350 try:del(self.options_used[self.options_used.index\351 (check.option['name'])])352 except:pass353 354 301 def save_profile(self, widget): 355 302 command = self.constructor.get_command('%s') … … 373 320 description=description,\ 374 321 annotation=annotation,\ 375 options=','.join(self. options_used))322 options=','.join(self.constructor.get_options())) 376 323 377 324 for i in xrange(self.notebook.get_n_pages()): … … 388 335 389 336 self.close_wizard() 390 391 class CommandPage(HIGVBox):392 def __init__(self, description, content, wizard):393 HIGVBox.__init__(self)394 self.set_spacing(12)395 396 self.description = HIGEntryLabel(description)397 self.bar = ForwardBar()398 table = HIGTable()399 400 self._pack_noexpand_nofill(self.description)401 self._pack_expand_fill(table)402 self._pack_noexpand_nofill(self.bar)403 404 y1 = 0405 y2 = 1406 407 for widget in content:408 if widget[1] == None:409 table.attach(widget[0],0,2,y1,y2, yoptions=0)410 else:411 table.attach(widget[0],0,1,y1,y2, yoptions=0)412 table.attach(widget[1],1,2,y1,y2, yoptions=0)413 414 if type(widget[0]) == type(OptionCheck()):415 widget[0].connect('toggled', wizard.update_check, widget[1])416 417 te = type(widget[1])418 419 if te == type(OptionList()):420 widget[1].connect('changed',wizard.update_list_option)421 elif te == type(OptionIntSpin()) or\422 te == type(OptionFloatSpin()) or\423 te == type(OptionEntry()):424 widget[1].connect('changed', wizard.update_entry, widget[0])425 elif te == type(OptionLevelSpin()):426 widget[1].connect('changed', wizard.update_level, widget[0])427 elif te == type(OptionFile()):428 widget[1].entry.connect('changed', \429 wizard.update_entry, widget[0])430 431 y1+=1;y2+=1432 337 433 338 class FinishPage(HIGVBox):
