Changeset 765

Show
Ignore:
Timestamp:
06/02/07 13:00:08 (6 years ago)
Author:
boltrix
Message:

Merged the changes sent by Max, and fixed a bug related to his fix. Also, fixed a bug on setup.py which were installing the docs in the wrong place.

Location:
trunk
Files:
7 modified

Legend:

Unmodified
Added
Removed
  • trunk/setup.py

    r649 r765  
    226226        parser.set(sec, "config_file", config_file) 
    227227        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)) 
    229229        parser.set(sec, "pixmaps_dir", os.path.join(self.install_data, pixmaps_dir)) 
    230230        parser.set(sec, "icons_dir", os.path.join(self.install_data, icons_dir)) 
  • trunk/umitCore/NmapCommand.py

    r668 r765  
    263263 
    264264class CommandConstructor: 
    265     def __init__(self, profile=None): 
     265    def __init__(self, options = {}): 
     266        self.options = {} 
    266267        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 
    268270 
    269271    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         
    282274 
    283275    def remove_option(self, option_name): 
     
    287279    def get_command(self, target): 
    288280        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             
    292297        splited.append(target) 
    293298        return ' '.join(splited) 
    294299 
    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     
    300303class CommandThread(threading.Thread): 
    301304    def __init__(self, command): 
  • trunk/umitCore/NmapParser.py

    r449 r765  
    355355                break 
    356356        else: 
    357             raise Exception("Comment could not be saved! Host not found at NmapParser!") 
     357            raise Exception("Comment could not be saved! Host not \ 
     358found at NmapParser!") 
    358359 
    359360    def get_host_comment(self, host_id): 
     
    362363                return host.comment 
    363364        else: 
    364             raise Exception("Comment could not be saved! Host not found at NmapParser!") 
     365            raise Exception("Comment could not be saved! Host not \ 
     366found at NmapParser!") 
    365367 
    366368    def get_profile(self): 
     
    404406        if (type(options) == type([])) or (type(options) in StringTypes): 
    405407            self.nmap['nmaprun']['options'] = options 
     408        elif type(options) == type({}): 
     409            self.nmap['nmaprun']['options'] = options.keys() 
    406410        else: 
    407411            raise Exception("Profile option error: wrong argument format! \ 
     
    498502            self.nmap['nmaprun']['start'] = date 
    499503        else: 
    500             raise Exception("Wrong date format. Date should be saved in epoch format!") 
     504            raise Exception("Wrong date format. Date should be saved \ 
     505in epoch format!") 
    501506     
    502507    def get_openned_ports(self): 
     
    526531    def get_formated_date(self): 
    527532        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)) 
    530538 
    531539    def get_scanner (self): 
     
    630638     
    631639    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'))) 
    633642 
    634643    def set_finish_time(self, finish): 
     
    649658    def get_formated_finish_date(self): 
    650659        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)) 
    653665 
    654666    def _verify_output_options (self, command): 
     
    669681    profile = property(get_profile, set_profile) 
    670682    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) 
    672685    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) 
    674688    profile_options = property(get_profile_options, set_profile_options) 
    675689    target = property(get_target, set_target) 
     
    759773        self.nmap[run_tag]["scanner"] = attrs.get("scanner", "") 
    760774        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                                                           "") 
    762777        self.nmap["scan_name"] = attrs.get("scan_name", "") 
    763778 
     
    818833 
    819834    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", "")} 
    821837 
    822838    def _parse_host_port_state(self, attrs): 
     
    835851 
    836852    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'])) 
    838855 
    839856    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'])) 
    842862 
    843863    def _parsing(self, attrs, attrs_list): 
    844         # Returns a dict with the attributes of a given tag with the atributes names 
    845         # as keys and their respective values 
     864        # Returns a dict with the attributes of a given tag with the 
     865        # atributes names as keys and their respective values 
    846866        dic = {} 
    847867        for at in attrs_list: 
     
    854874 
    855875    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'])) 
    858880     
    859881    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'])) 
    861884 
    862885    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'])) 
    864888 
    865889    def startElement(self, name, attrs): 
     
    900924            self.in_port = True 
    901925            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": 
    903928            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": 
    905931            self._parse_host_port_service(attrs) 
    906932        elif self.in_host and name == "os": 
     
    937963        elif self.in_host and name == "ports": 
    938964            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}) 
    940967        elif self.in_host and self.in_ports and name == "port": 
    941968            self.in_port = False 
     
    9861013        ## Finished element 
    9871014        self.write_parser.startElement("finished", 
    988                                        Attributes(dict(time = str(self.finish_epoc_time)))) 
     1015                        Attributes(dict(time = str(self.finish_epoc_time)))) 
    9891016        self.write_parser.endElement("finished") 
    9901017 
    9911018        ## 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)))) 
    9951023        self.write_parser.endElement("hosts") 
    9961024 
     
    10031031        for host in self.hosts: 
    10041032            # 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))) 
    10061035 
    10071036            # 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))) 
    10091039            self.write_parser.endElement("status") 
    10101040 
     
    10151045            if type(host.ip) == type({}): 
    10161046                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", "")))) 
    10201050                self.write_parser.endElement("address") 
    10211051 
     
    10231053            if type(host.ipv6) == type({}): 
    10241054                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", "")))) 
    10281058                self.write_parser.endElement("address") 
    10291059 
     
    10311061            if type(host.mac) == type({}): 
    10321062                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", "")))) 
    10361066                self.write_parser.endElement("address") 
    10371067            # End of Address elements 
     
    10461076                if type(hname) == type({}): 
    10471077                    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", "")))) 
    10501080                     
    10511081                    self.write_parser.endElement("hostname") 
     
    10651095                    if type(ext) == type({}): 
    10661096                        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", "")))) 
    10691099                        self.write_parser.endElement("extraports") 
    10701100 
     
    10731103                    if type(p) == type({}): 
    10741104                        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", "")))) 
    10771107 
    10781108                        ### Port state 
    10791109                        self.write_parser.startElement("state", 
    1080                                                 Attributes(dict(state=p.get("port_state", "")))) 
     1110                            Attributes(dict(state=p.get("port_state", "")))) 
    10811111                        self.write_parser.endElement("state") 
    10821112 
    10831113                        ### Port service info 
    10841114                        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                                ))) 
    10911122                        self.write_parser.endElement("service") 
    10921123 
     
    11061137                if type(pu) == type({}): 
    11071138                    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", "")))) 
    11111142                    self.write_parser.endElement("portused") 
    11121143 
     
    11151146                if type(oc) == type({}): 
    11161147                    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", "")))) 
    11221153                    self.write_parser.endElement("osclass") 
    11231154 
     
    11251156            if type(host.osmatch) == type({}): 
    11261157                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", "")))) 
    11291160                self.write_parser.endElement("osmatch") 
    11301161 
     
    11361167            if type(host.uptime) == type({}): 
    11371168                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", "")))) 
    11401171                self.write_parser.endElement("uptime") 
    11411172 
     
    11461177            if type(host.tcpsequence) == type({}): 
    11471178                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", "")})) 
    11521183                self.write_parser.endElement("tcpsequence") 
    11531184 
     
    11551186            if type(host.ipidsequence) == type({}): 
    11561187                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", "")})) 
    11591190                self.write_parser.endElement("ipidsequence") 
    11601191 
     
    11621193            if type(host.tcptssequence) == type({}): 
    11631194                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", "")})) 
    11661197                self.write_parser.endElement("tcptssequence") 
    11671198            # End of sequences elements 
     
    11731204    def _write_debugging(self): 
    11741205        self.write_parser.startElement("debugging", Attributes(dict( 
    1175                                                            level=str(self.debugging_level)))) 
     1206                                            level=str(self.debugging_level)))) 
    11761207        self.write_parser.endElement("debugging") 
    11771208 
    11781209    def _write_verbose(self): 
    11791210        self.write_parser.startElement("verbose", Attributes(dict( 
    1180                                                              level=str(self.verbose_level)))) 
     1211                                            level=str(self.verbose_level)))) 
    11811212        self.write_parser.endElement("verbose") 
    11821213 
     
    11851216            if type(scan) == type({}): 
    11861217                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", "")))) 
    11911222                self.write_parser.endElement("scaninfo") 
    11921223 
    11931224    def _write_nmaprun(self): 
    11941225        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)))) 
    12091240 
    12101241    def _verify_file(self, xml_file): 
  • trunk/umitCore/UmitConf.py

    r649 r765  
    2424 
    2525from types import StringTypes 
    26 from ConfigParser import NoSectionError 
     26from ConfigParser import NoSectionError, NoOptionError 
    2727 
    2828from umitCore.Paths import Path 
     
    207207        except: return None 
    208208         
    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]) 
    210215        self.save_changes() 
    211216 
     
    239244 
    240245    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 
    243253 
    244254    def set_command(self, profile, command=''): 
     
    254264        self._set_it(profile, 'annotation', annotation) 
    255265     
    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())) 
    258271 
    259272    def get_profile(self, profile_name): 
  • trunk/umitGUI/OptionBuilder.py

    r489 r765  
    3535 
    3636 
     37class 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                  
    37188class 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        """ 
    39195        xml_desc = open(xml_file) 
    40196        self.xml = minidom.parse(xml_desc) 
    41  
    42197        # Closing file to avoid problems with file descriptors 
    43198        xml_desc.close() 
     199 
     200        self.constructor = constructor 
     201        self.update_func = update_func 
    44202         
    45203        self.root_tag = "interface" 
    46         self.actions = {'option_list':self.__parse_option_list,\ 
    47                         'option_check':self.__parse_option_check} 
    48204         
    49205        self.xml = self.xml.getElementsByTagName(self.root_tag)[0] 
     
    69225        dic = {} 
    70226        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) 
    85229        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     
    123232class OptionWidget: 
    124233    def enable_widget(self): 
     
    163272 
    164273class OptionEntry(gtk.Entry, OptionWidget): 
    165     def __init__(self): 
     274    def __init__(self, param = ""): 
    166275        gtk.Entry.__init__(self) 
     276        self.set_text(param) 
    167277 
    168278class OptionLevelSpin(gtk.SpinButton, OptionWidget): 
    169279    def __init__(self, initial=0): 
    170         gtk.SpinButton.__init__(self,gtk.Adjustment(initial,0,10,1),0.0,0) 
     280        gtk.SpinButton.__init__(self,gtk.Adjustment(int(initial),0,10,1),0.0,0) 
    171281 
    172282class OptionIntSpin(gtk.SpinButton, OptionWidget): 
    173283    def __init__(self, initial=1): 
    174         gtk.SpinButton.__init__(self,gtk.Adjustment(initial,0,10**100,1),0.0,0) 
     284        gtk.SpinButton.__init__(self,gtk.Adjustment(int(initial),0,10**100,1),0.0,0) 
    175285 
    176286class OptionFloatSpin(gtk.SpinButton, OptionWidget): 
    177287    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) 
    179289 
    180290class OptionFile(HIGHBox, OptionWidget, object): 
    181     def __init__(self): 
     291    def __init__(self, param=""): 
    182292        HIGHBox.__init__(self) 
    183293         
     
    187297        self._pack_expand_fill(self.entry) 
    188298        self._pack_noexpand_nofill(self.button) 
    189          
     299 
     300        self.entry.set_text(param) 
    190301        self.button.connect('clicked', self.open_dialog_cb) 
    191302     
  • trunk/umitGUI/ProfileEditor.py

    r508 r765  
    5050        self.__pack_widgets() 
    5151         
    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() 
    5952        self.profile = CommandProfile() 
    6053         
    6154        self.deleted = False 
    62         self.options_used = [] 
     55        options_used = {} 
    6356         
    6457        if profile_name: 
    6558            log.debug("Showing profile %s" % profile_name) 
    6659            prof = self.profile.get_profile(profile_name) 
    67             self.options_used = prof['options'] 
    68  
     60            options_used = prof['options'] 
     61             
    6962            # Interface settings 
    7063            self.profile_name_entry.set_text(profile_name) 
     
    7770                self.profile.remove_profile(profile_name) 
    7871                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)) 
    7978         
    8079        for tab in self.options.groups: 
     
    9998        self.command_expander.set_expanded(True) 
    10099        self.command_entry = gtk.Entry() 
    101          
    102         self.widgets = {} 
    103100         
    104101        self.notebook = gtk.Notebook() 
     
    176173        self.buttons_hbox.set_spacing(6) 
    177174 
    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 
    179179        vbox = HIGVBox() 
    180180        table = HIGTable() 
    181181        section = HIGSectionLabel(section_name) 
    182         log.debug(">>> Tab name: %s" % tab_name) 
    183         log.debug(">>>Creating profile editor section: %s" % section_name) 
    184182         
    185183        vbox._pack_noexpand_nofill(section) 
    186184        vbox._pack_noexpand_nofill(HIGSpacer(table)) 
    187          
    188185        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) 
    228188         
    229189        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:pass 
    251         self.update_command() 
    252190     
    253191    def save_profile(self, widget): 
     
    275213        annotation = buf.get_text(buf.get_start_iter(),\ 
    276214                                      buf.get_end_iter()) 
    277          
     215 
    278216        self.profile.add_profile(profile_name,\ 
    279217                                 command=command,\ 
     
    281219                                 description=description,\ 
    282220                                 annotation=annotation,\ 
    283                                  options=','.join(self.options_used)) 
     221                                 options=self.constructor.get_options()) 
    284222         
    285223        self.deleted = False 
     
    291229        self.profile_description_text.get_buffer().set_text('') 
    292230        self.profile_annotation_text.get_buffer().set_text('') 
    293      
    294     def update_list_option(self, widget): 
    295         try:widget.last_selected 
    296         except:pass 
    297         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:pass 
    302          
    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_name 
    308          
    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:pass 
    335          
    336         #print self.options_used 
    337231     
    338232    def set_notebook(self, notebook): 
  • trunk/umitGUI/Wizard.py

    r664 r765  
    5050        self.set_position(gtk.WIN_POS_CENTER) 
    5151         
    52         self.options = OptionBuilder(wizard) 
     52        self.profile = CommandProfile() 
    5353        self.constructor = CommandConstructor() 
    54         self.profile = CommandProfile() 
    55         self.options_used = [] 
     54        self.options = OptionBuilder(wizard, self.constructor, self.update_command) 
    5655         
    5756        self.target = '<target>' 
     
    9897 
    9998    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 
    107118 
    108119    def set_notebook(self, notebook): 
     
    288299        pass 
    289300     
    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:pass 
    310         self.update_command() 
    311  
    312     def update_list_option(self, widget): 
    313         try:widget.last_selected 
    314         except:pass 
    315         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:pass 
    320          
    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_name 
    326          
    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:pass 
    353          
    354301    def save_profile(self, widget): 
    355302        command = self.constructor.get_command('%s') 
     
    373320                                     description=description,\ 
    374321                                     annotation=annotation,\ 
    375                                      options=','.join(self.options_used)) 
     322                                     options=','.join(self.constructor.get_options())) 
    376323             
    377324            for i in xrange(self.notebook.get_n_pages()): 
     
    388335         
    389336        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 = 0 
    405         y2 = 1 
    406          
    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+=1 
    432337 
    433338class FinishPage(HIGVBox):