Changeset 1431

Show
Ignore:
Timestamp:
08/19/07 04:05:09 (6 years ago)
Author:
ggpolo
Message:

Huge speed gain on XML insertion into databaseng, including insertion on Inventory and calculating changes.

Location:
branch/ggpolo
Files:
14 modified

Legend:

Unmodified
Added
Removed
  • branch/ggpolo/umitDB/InventoryChanges.py

    r1382 r1431  
    2020from umitCore.I18N import _ 
    2121 
     22from umitDB.Connection import ConnectDB 
    2223from umitDB.Store import RawStore 
    2324from umitDB.Retrieve import InventoryRetrieve 
     
    2627    pass 
    2728 
    28 class UpdateChanges(InventoryRetrieve, RawStore): 
     29class ConnectToUpdate(ConnectDB, InventoryRetrieve, RawStore): 
    2930    """ 
    30     Updates list of changes for a given Inventory id. 
     31    You should use this when doing inventory changes update exclusively  
     32    in database. 
    3133    """ 
    32      
    33     def __init__(self, database, fk_inventory=None): 
    34          
    35         InventoryRetrieve.__init__(self, database) 
     34 
     35    def __init__(self, database): 
     36        ConnectDB.__init__(self, database) 
     37        InventoryRetrieve.__init__(self, self.conn, self.cursor) 
    3638        RawStore.__init__(self, self.conn, self.cursor) 
     39 
     40 
     41class UpdateChanges: 
     42    """ 
     43    Updates/creates list of changes for Inventory. 
     44    """ 
     45     
     46    def __init__(self, invdb, fk_inventory=None): 
     47         
     48        self.invdb = invdb 
    3749        self.fk_inventory = fk_inventory 
    3850         
     
    4961         
    5062        # get scan ids and finish time for especified inventory 
    51         finish_data = self.get_finish_data_for_inventory_from_db(inv_id) 
    52          
    53          
     63        finish_data = self.invdb.get_finish_data_for_inventory_from_db(inv_id) 
     64          
    5465        # retrieve host addresses for especified inventory id 
    5566        for scan in finish_data: 
    5667            # retrieve host ids for each scan 
    57             for host in self.get_hosts_id_for_scan_from_db(scan[0]): 
     68            for host in self.invdb.get_hosts_id_for_scan_from_db(scan[0]): 
    5869                # retrieve ipv4 address for host 
    59                 addr = self.get_ipv4_for_host_from_db(host[0]) 
     70                addr = self.invdb.get_ipv4_for_host_from_db(host[0]) 
    6071                 
    6172                if addr in addresses: 
     
    6374                 
    6475                addresses.append(addr) 
    65                  
    66                  
     76                         
    6777        # generate changes list for each address in especified inventory 
    6878        for addr in addresses: 
     
    7080            # get all host pks for especified inventory and for each address  
    7181            # in addresses 
    72             base_data = self.get_hosts_base_data_for_inventory_from_db(addr,  
     82            base_data = self.invdb.get_hosts_base_data_for_inventory_from_db(addr,  
    7383                                                                       inv_id) 
    7484             
     
    105115            date = finish_data[indexes[0]][1] 
    106116            hostA = base_data[0] 
    107             self.use_dict_cursor() 
    108             pdata1 = self.get_portid_and_state_for_host_from_db(hostA[1]) 
    109             self.use_standard_cursor() 
    110             fpinfo1 = self.get_fingerprint_info_for_host_from_db(hostA[1]) 
    111             osmatch1 = self.get_osmatch_for_host_from_db(hostA[1]) 
    112             osclasses1 = self.get_osclasses_for_host_from_db(hostA[1]) 
    113             pcdata1 = self.get_portid_and_fks_for_host_from_db(hostA[1]) 
     117            self.invdb.use_dict_cursor() 
     118            pdata1 = self.invdb.get_portid_and_state_for_host_from_db(hostA[1]) 
     119            self.invdb.use_standard_cursor() 
     120            fpinfo1 = self.invdb.get_fingerprint_info_for_host_from_db(hostA[1]) 
     121            osmatch1 = self.invdb.get_osmatch_for_host_from_db(hostA[1]) 
     122            osclasses1 = self.invdb.get_osclasses_for_host_from_db(hostA[1]) 
     123            pcdata1 = self.invdb.get_portid_and_fks_for_host_from_db(hostA[1]) 
    114124             
    115125            host_count = 1 
     
    120130                 
    121131                # load data to compare against hostA 
    122                 self.use_dict_cursor() 
    123                 pdata2 = self.get_portid_and_state_for_host_from_db(hostB[1]) 
    124                 self.use_standard_cursor() 
    125                 fpinfo2 = self.get_fingerprint_info_for_host_from_db(hostB[1]) 
    126                 osmatch2 = self.get_osmatch_for_host_from_db(hostB[1]) 
    127                 osclasses2 = self.get_osclasses_for_host_from_db(hostB[1]) 
    128                 pcdata2 = self.get_portid_and_fks_for_host_from_db(hostB[1]) 
     132                self.invdb.use_dict_cursor() 
     133                pdata2 = self.invdb.get_portid_and_state_for_host_from_db(hostB[1]) 
     134                self.invdb.use_standard_cursor() 
     135                fpinfo2 = self.invdb.get_fingerprint_info_for_host_from_db(hostB[1]) 
     136                osmatch2 = self.invdb.get_osmatch_for_host_from_db(hostB[1]) 
     137                osclasses2 = self.invdb.get_osclasses_for_host_from_db(hostB[1]) 
     138                pcdata2 = self.invdb.get_portid_and_fks_for_host_from_db(hostB[1]) 
    129139                 
    130140                # compare old data against new data 
     
    169179             
    170180        # insert data into database 
    171         fk_address = self.get_address_id_for_address_from_db(addr_id) 
     181        fk_address = self.invdb.get_address_id_for_address_from_db(addr_id) 
    172182        for key in dict_keys: 
    173183            affected = data_dict[key][0] 
     
    178188             
    179189            # check if category 'affected' already exists on database 
    180             fk_category = self.get_inventory_change_category_id(affected) 
     190            fk_category = self.invdb.get_inventory_change_category_id(affected) 
    181191            if not fk_category: 
    182192                # didn't exist, create it now 
    183                 self.insert_inventory_change_category_db(affected) 
    184                 fk_category = self.get_id_for("inventory_change_category") 
     193                self.invdb.insert_inventory_change_category_db(affected) 
     194                fk_category = self.invdb.get_id_for("inventory_change_category") 
    185195                     
    186196            # check if comparison is already in database 
    187197            # (this should have been done at earlier stage, but for now 
    188198            #  it is being done here) 
    189             ret = self.get_inventory_comparison(old_hostid, new_hostid,  
    190                                                 date, inventory_id) 
     199            ret = self.invdb.get_inventory_comparison(old_hostid, new_hostid,  
     200                                                      date, inventory_id) 
    191201                     
    192202            if not ret: 
    193203                # need to insert new comparison 
    194                 self.insert_inventory_comparison_db(old_hostid, new_hostid,  
     204                self.invdb.insert_inventory_comparison_db(old_hostid, new_hostid,  
    195205                                                    date, text, inventory_id,  
    196206                                                    fk_category, fk_address) 
    197                  
     207 
    198208             
    199209    def _compare_data(self, pdata2, fpinfo2, osmatch2, osclasses2, pcdata2, 
     
    209219        # compare pdataNs 
    210220        if pdata1 != pdata2: 
    211             host_diff += self._ports_diff(pdata2, pdata1) 
     221            host_diff = self._ports_diff(pdata2, pdata1) 
    212222            fp_only = False 
    213223            ports_only = True 
     
    219229        new_ports = { } 
    220230 
    221         self.use_dict_cursor() 
     231        self.invdb.use_dict_cursor() 
    222232        for pd in pcdata2: 
    223             fpd = self.get_port_data_for_pdata_from_db(pd[2], pd[3], pd[1]) 
     233            fpd = self.invdb.get_port_data_for_pdata_from_db(pd[2], pd[3],  
     234                                                             pd[1]) 
    224235            old_ports[pd[0]] = fpd 
    225236 
    226237        for pd in pcdata1: 
    227             fpd = self.get_port_data_for_pdata_from_db(pd[2], pd[3], pd[1]) 
     238            fpd = self.invdb.get_port_data_for_pdata_from_db(pd[2], pd[3],  
     239                                                             pd[1]) 
    228240            new_ports[pd[0]] = fpd 
    229         self.use_standard_cursor() 
     241        self.invdb.use_standard_cursor() 
    230242         
    231243        info_changes = [ ] 
     
    241253            verb, plural = self.conjugate(info_changes, False) 
    242254            ports_str = ', '.join([str(p) for p in info_changes]) 
    243             host_diff += _("Port%s %s %s changed info!" % (plural, ports_str, 
    244                                                            verb)) 
     255            host_diff = ''.join([host_diff, 
     256                                 _("Port%s %s %s changed info!" % (plural,  
     257                                                          ports_str, verb))]) 
    245258 
    246259        # compare fpinfoNs 
     
    257270        if osmatch1 != osmatch2: 
    258271            space = host_diff and ' ' or '' 
    259             common_text += _("OS Match, ") 
     272            common_text = ''.join([common_text, _("OS Match, ")]) 
    260273            fp_only = False 
    261274            ports_only = False 
     
    265278            space = host_diff and ' ' or '' 
    266279            if len(common_text) == len("Fingerprint, "): 
    267                 common_text = common_text[:-2] + " " 
     280                common_text = ''.join([common_text[:-2], " "]) 
    268281            if common_text: 
    269                 common_text += _("and OS Classes") 
     282                common_text = ''.join([common_text, _("and OS Classes")]) 
    270283            else: 
    271                 common_text += _("OS Classes") 
     284                common_text = ''.join([common_text, _("OS Classes")]) 
    272285            fp_only = False 
    273286            ports_only = False 
     
    276289            if fp_only or len(common_text) == len(" Fingerprint, "): 
    277290                common_text = common_text[:-2] 
    278             host_diff += common_text + _(" changed.") 
     291 
     292            host_diff = ''.join([host_diff, common_text, _(" changed.")]) 
    279293 
    280294        # check diff 
     
    377391 
    378392        if open_ports and closed_ports: 
    379             text = open_ports[:-1 -len(now_text) -1] + ' ' + and_text + \ 
    380                    ' ' + closed_ports 
     393            text = ' '.join([open_ports[:-1 -len(now_text) -1], and_text, 
     394                             closed_ports]) 
    381395        elif open_ports: 
    382396            text = open_ports 
     
    416430    """ 
    417431     
    418     def __init__(self, database): 
    419         InventoryRetrieve.__init__(self, database) 
     432    def __init__(self, conn, cursor): 
     433        InventoryRetrieve.__init__(self, conn, cursor) 
    420434         
    421435 
  • branch/ggpolo/umitDB/Retrieve.py

    r1404 r1431  
    350350        Expects a conn and cursor from database connection.    
    351351        """ 
    352         self.conn = conn 
    353         self.cursor = cursor 
    354          
    355         RawRetrieve.__init__(self, self.conn, self.cursor) 
     352        RawRetrieve.__init__(self, conn, cursor) 
    356353 
    357354 
     
    617614         
    618615        return classes 
    619      
    620  
    621 class InventoryRetrieve(ConnectDB, CompositeRetrieve): 
     616    
     617 
     618class InventoryRetrieve(CompositeRetrieve): 
    622619    """ 
    623620    Retrieves inventory data from database. 
    624621    """ 
    625622 
    626     def __init__(self, db): 
    627         """ 
    628         Expects an umit database. 
    629         """ 
    630         ConnectDB.__init__(self, db) 
    631         CompositeRetrieve.__init__(self, self.conn, self.cursor) 
     623    def __init__(self, conn, cursor): 
     624        CompositeRetrieve.__init__(self, conn, cursor) 
    632625 
    633626 
     
    823816         
    824817        return changes 
    825          
     818     
     819 
    826820    def get_inventory_changes_for_category(self, fk_inventory, fk_address, 
    827821                                           fk_category): 
     
    862856 
    863857        return changes 
    864      
     858 
     859 
     860class ConnectInventoryDB(ConnectDB, InventoryRetrieve): 
     861    """ 
     862    This replaces the previous UpdateChanges class in InventoryChanges module. 
     863    ToDo: Write a better doc =) 
     864    """ 
     865 
     866    def __init__(self, db): 
     867        ConnectDB.__init__(self, db) 
     868        InventoryRetrieve.__init__(self, self.conn, self.cursor) 
     869 
  • branch/ggpolo/umitDB/Store.py

    r1400 r1431  
    5555                    scan_d["hosts_down"], scan_d["scanner"])) 
    5656 
    57         self.conn.commit() 
    58  
    5957     
    6058    def insert_scaninfo_db(self, scaninfo): 
     
    6967                        scaninfo["services"], scaninfo["fk_scan"], 
    7068                        scaninfo["type"], scaninfo["protocol"])) 
    71         self.conn.commit() 
    7269 
    7370 
     
    8077        self.cursor.execute("INSERT INTO scan_type (name) VALUES \ 
    8178                                 (?)", (scan_name, )) 
    82         self.conn.commit() 
    8379 
    8480 
     
    9187        self.cursor.execute("INSERT INTO scanner (name, version) VALUES \ 
    9288                                 (?, ?)", (scanner_name, scanner_version)) 
    93         self.conn.commit() 
    9489         
    9590 
     
    105100                       (portid, service_info_id, protocol_id, 
    106101                        port_state_id)) 
    107         self.conn.commit() 
    108102             
    109103     
     
    116110        self.cursor.execute("INSERT INTO port_state (state) VALUES \ 
    117111                                (?)", (port_state, )) 
    118         self.conn.commit() 
    119112     
    120113     
     
    127120        self.cursor.execute("INSERT INTO protocol (name) VALUES \ 
    128121                                 (?)", (protocol, )) 
    129         self.conn.commit() 
    130122         
    131123     
     
    138130        self.cursor.execute("INSERT INTO _host_port (fk_host, fk_port) \ 
    139131                    VALUES (?, ?)", (fk_host, fk_port)) 
    140         self.conn.commit() 
    141132         
    142133 
     
    150141                            fk_port_state) VALUES (?, ?, ?)", 
    151142                            (count, fk_host, fk_port_state)) 
    152         self.conn.commit() 
    153143 
    154144 
     
    163153                        fk_protocol, fk_host) VALUES (?, ?, ?, ?)", 
    164154                        (portid, fk_port_state, fk_protocol, fk_host)) 
    165         self.conn.commit() 
    166155 
    167156 
     
    177166                        (?, ?, ?, ?, ?, ?)", (osclass_accuracy, fk_osgen, 
    178167                        fk_osfamily, fk_osvendor, fk_ostype, fk_host)) 
    179         self.conn.commit() 
    180168 
    181169    
     
    190178                    fk_host) VALUES (?, ?, ?, ?)", (osmatch["name"],  
    191179                    osmatch["accuracy"], osmatch["line"], host)) 
    192         self.conn.commit() 
    193180         
    194181         
     
    200187         
    201188        self.cursor.execute("INSERT INTO osgen (gen) VALUES (?)", (osgen, )) 
    202         self.conn.commit() 
     189 
    203190         
    204191    def insert_osfamily_db(self, osfamily): 
     
    210197        self.cursor.execute("INSERT INTO osfamily (family) VALUES (?)",  
    211198                        (osfamily, )) 
    212         self.conn.commit() 
    213199             
    214200 
     
    221207        self.cursor.execute("INSERT INTO osvendor (vendor) VALUES (?)",  
    222208                        (osvendor, )) 
    223         self.conn.commit() 
    224209 
    225210     
     
    232217        self.cursor.execute("INSERT INTO ostype (type) VALUES (?)",  
    233218                        (ostype, )) 
    234         self.conn.commit() 
    235219         
    236220 
     
    244228                     fk_host_state) VALUES (?, ?, ?)", (host_d["distance"], 
    245229                     host_d["fk_scan"], host_d["fk_host_state"])) 
    246         self.conn.commit() 
    247230 
    248231 
     
    255238        self.cursor.execute("INSERT INTO _host_address (fk_host, fk_address) \ 
    256239                            VALUES (?, ?)", (fk_host, fk_address)) 
    257         self.conn.commit() 
    258240 
    259241 
     
    267249                                fk_hostname) VALUES (?, ?)", (fk_host,  
    268250                                fk_hostname)) 
    269         self.conn.commit() 
    270251     
    271252     
     
    279260                                 (?, ?)", (hostname["hostname_type"],  
    280261                                           hostname["hostname"])) 
    281         self.conn.commit() 
    282262    
    283263 
     
    302282                ip_id_sequence_value, fk_host) VALUES (?, ?, ?, ?, ?, ?, ?, \ 
    303283                ?, ?, ?, ?)", (data)) 
    304         self.conn.commit() 
    305284 
    306285     
     
    313292        self.cursor.execute("INSERT INTO service_name (name) VALUES \ 
    314293                            (?)", (service_name, )) 
    315         self.conn.commit() 
    316294         
    317295         
     
    325303                    extrainfo, method, conf, fk_service_name) VALUES (?, ?, ?,\ 
    326304                    ?, ?, ?)", service_data) 
    327         self.conn.commit() 
    328305         
    329306     
     
    337314                        fk_vendor) VALUES (?, ?, ?)", (address_addr, 
    338315                        address_type, vendor)) 
    339         self.conn.commit() 
    340316 
    341317     
     
    348324        self.cursor.execute("INSERT INTO vendor (name) \ 
    349325                                         VALUES (?)", (vendor_name, )) 
    350         self.conn.commit() 
    351326 
    352327         
     
    359334        self.cursor.execute("INSERT INTO host_state (state) \ 
    360335                        VALUES (?)", (host_state, )) 
    361         self.conn.commit() 
    362336 
    363337 
     
    372346                        tcpseq_dict["index"], tcpseq_dict["class"],  
    373347                        tcpseq_dict["difficulty"], tcpseq_dict["values"])) 
    374         self.conn.commit() 
    375348 
    376349 
     
    385358                      tcp_ts_values)  VALUES (?, ?)", (tcptsseq_dict["class"],  
    386359                      tcptsseq_dict["values"])) 
    387         self.conn.commit() 
    388360 
    389361 
     
    397369                      ip_id_values)  VALUES (?, ?)", (ipidseq_dict["class"],  
    398370                      ipidseq_dict["values"])) 
    399         self.conn.commit() 
    400371 
    401372 
     
    408379        self.cursor.execute("INSERT INTO inventory (name) VALUES (?)",  
    409380                    (inventory, )) 
    410         self.conn.commit() 
    411381         
    412382     
     
    419389        self.cursor.execute("INSERT INTO _inventory_scan (fk_scan, \ 
    420390                    fk_inventory) VALUES (?, ?)", (scan, inventory)) 
    421         self.conn.commit() 
    422391         
    423392         
     
    431400        self.cursor.execute("INSERT INTO inventory_change_category (name) \ 
    432401                             VALUES (?)", (category, )) 
    433         self.conn.commit() 
    434402         
    435403     
     
    448416                                                      short_descr, fk_inventory, 
    449417                                                      fk_category, fk_address)) 
    450         self.conn.commit() 
    451           
     418 
  • branch/ggpolo/umitDB/XMLStore.py

    r1295 r1431  
    2020from datetime import datetime 
    2121 
     22from umitCore.UmitLogging import log 
    2223from umitCore.NmapParser import NmapParser 
    2324 
    2425from umitDB.Connection import ConnectDB 
    2526from umitDB.Store import RawStore 
    26 from umitDB.Retrieve import RawRetrieve 
     27from umitDB.Retrieve import InventoryRetrieve 
    2728from umitDB.InventoryChanges import UpdateChanges 
    28 from umitDB.Utils import empty 
    29 from umitDB.Utils import debug 
    30 from umitDB.Utils import normalize 
    31  
    32 class XMLStore(ConnectDB, RawRetrieve, RawStore): 
     29from umitDB.Utils import empty, debug, normalize 
     30 
     31class XMLStore(ConnectDB, InventoryRetrieve, RawStore): 
    3332    """ 
    3433    Stores xml into database. 
    3534    """ 
    3635         
    37     def __init__(self, database, xml_file=None, parsed=None, 
     36    def __init__(self, database, xml_files=None, parsed=None, 
    3837                 inventory=None, store_original=False): 
    3938        """ 
    40         xml_file        -  nmap xml output 
     39        xml_files       -   a list or a single nmap xml output 
    4140        parsed          -   a NmapParserSAX object or None 
    4241        inventory       -   inventory that scan will be added to, or None 
     
    4544 
    4645        ConnectDB.__init__(self, database) 
    47         RawRetrieve.__init__(self, self.conn, self.cursor) 
     46        InventoryRetrieve.__init__(self, self.conn, self.cursor) 
    4847        RawStore.__init__(self, self.conn, self.cursor) 
    4948         
     
    5150        self.store_original = store_original 
    5251         
    53         if xml_file: 
    54             self.store_xml(xml_file, parsed, inventory) 
     52        if xml_files: 
     53            self.store_xml(xml_files, parsed, inventory) 
    5554          
    5655             
    57     def store_xml(self, xml_file, parsed=None, inventory=None): 
    58         """ 
    59         Inserts xml file into database. 
    60         """ 
    61         debug("Inserting file %s" % xml_file) 
    62          
    63         self.xml_file = xml_file 
    64         if parsed: 
    65             self.parsed = parsed 
    66         else: 
    67             self.parsed = self.parse(xml_file) 
    68         self.scan = self.scan_from_xml() 
    69         self.scaninfo = self.scaninfo_from_xml() 
    70         self.hosts = self.hosts_from_xml() 
    71  
     56    def store_xml(self, xml_files, parsed=None, inventory=None): 
     57        """ 
     58        Inserts xml file(s) into database. 
     59        """ 
     60        log.debug(">>> Inserting file(s) into databaseng: ", xml_files) 
     61         
    7262        if inventory: 
    73             debug("Inserting scan into Inventory '%s'" % inventory) 
    74             inv_id = self.get_inventory_id_from_db(inventory) 
    75             if not inv_id: # create new inventory 
    76                 self.insert_inventory_db(inventory) 
    77                 inv_id = self.get_id_for("inventory") 
    78             self.insert_inventory_scan_db(self.scan["pk"], inv_id) 
    79  
     63            self.invchanges = UpdateChanges(self) 
     64 
     65        if isinstance(xml_files, str): 
     66            # using singe file 
     67            xml_files = [xml_files, ] 
     68 
     69        for xml_file in xml_files: 
     70            self.xml_file = xml_file 
     71            if parsed: # used only for single file 
     72                self.parsed = parsed 
     73            else: 
     74                self.parsed = self.parse(xml_file) 
     75 
     76            self.scan = self.scan_from_xml() 
     77            self.scaninfo = self.scaninfo_from_xml() 
     78            self.hosts = self.hosts_from_xml() 
     79 
     80            if inventory: 
     81                log.debug(">>> Inserting scan into Inventory '%s'" % inventory) 
     82                inv_id = self.get_inventory_id_from_db(inventory) 
     83                if not inv_id: # create new inventory 
     84                    self.insert_inventory_db(inventory) 
     85                    inv_id = self.get_id_for("inventory") 
     86                self.insert_inventory_scan_db(self.scan["pk"], inv_id) 
     87 
     88        if inventory: 
    8089            # update list of changes for inventory 
    81             debug("Updating list of changes for Inventory '%s'" % inventory) 
    82             self.update_inventory_changes(inv_id) 
    83  
    84         debug("%s inserted into database (hopefully)." % xml_file) 
    85  
    86          
    87     def update_inventory_changes(self, fk_inventory): 
    88         """ 
    89         Updates list of changes for an Inventory. 
    90         """ 
    91         UpdateChanges(self.database, fk_inventory) 
     90            log.debug(">>> Updating changes for Inventory '%s'" % inventory) 
     91            self.invchanges.do_update(inv_id) 
     92 
     93        self.conn.commit() 
     94 
     95        log.debug(xml_files, "inserted into database (hopefully).") 
    9296 
    9397 
  • branch/ggpolo/umitDBUpdates/insert-changes-into-db.py

    r1382 r1431  
    88 
    99import sys 
    10 from umitDB.InventoryChanges import UpdateChanges 
     10from umitDB.InventoryChanges import ConnectToUpdate, UpdateChanges 
    1111 
    1212def perform_update(database): 
     
    1414    Update changes for each inventory. 
    1515    """ 
    16     uc_instance = UpdateChanges(database) 
    17     inv_ids = uc_instance.get_inventories_ids() 
     16    db_conn = ConnectToUpdate(database) 
     17 
     18    uc_instance = UpdateChanges(db_conn) 
     19    inv_ids = db_conn.get_inventories_ids() 
    1820    inv_ids = [i_id[0] for i_id in inv_ids] 
    1921     
     
    2123        uc_instance.do_update(i_id) 
    2224 
     25    db_conn.conn.commit() 
    2326 
    2427if __name__ == "__main__": 
  • branch/ggpolo/umitInventory/About.py

    r1372 r1431  
    3131from umitCore.I18N import _ 
    3232from umitCore.Paths import Path, VERSION, REVISION 
    33 from umitInventory.Version import NI_BUILD 
     33from umitInventory.Version import __version__ 
    3434 
    3535pixmaps_dir = Path.pixmaps_dir 
     
    4747<span size='10000' weight='heavy'>Rev. %s</span> 
    4848<span size='10000' weight='heavy'>Network Inventory Build %s</span>""" % (VERSION,  
    49                                                         REVISION, NI_BUILD))) 
     49                                                        REVISION, __version__))) 
    5050        self.lbl_program_description = gtk.Label(_(""" 
    5151UMIT Network Inventory and UMIT Scheduler are UMIT 
  • branch/ggpolo/umitInventory/ChangesDiff.py

    r1382 r1431  
    2929from umitGUI.DiffCompare import DiffLegendWindow 
    3030 
    31 from umitDB.Retrieve import InventoryRetrieve 
    32  
    3331EMPTY = _("Nothing being shown.") 
    3432NA = _("Not Available") 
     
    533531        # extraports 
    534532        epdata = self.invdb.get_extraports_data_for_host_from_db(host_id) 
     533 
    535534        ep_d = { } 
    536535        for ep in epdata: 
     
    661660        self.show_all() 
    662661 
    663  
    664 class DiffWindow(gtk.Window): 
    665     def __init__(self, db): 
    666         gtk.Window.__init__(self) 
    667  
    668         self.invdb = InventoryRetrieve(db) 
    669  
    670         self.compare_view = ChangesDiff(self.invdb) 
    671         self.compare_view.make_diff(133, 1) 
    672         self.add(self.compare_view) 
    673  
    674  
    675 if __name__ == "__main__": 
    676     w = DiffWindow("/home/polo/.umit/umitng.db") 
    677     w.show_all() 
    678     w.connect('delete-event', lambda *args:gtk.main_quit()) 
    679     gtk.main() 
    680  
  • branch/ggpolo/umitInventory/ChangesList.py

    r1320 r1431  
    3232 
    3333class ChangesList(gtk.VBox): 
    34     def __init__(self, daddy, display, data, data_built=False, load_now=True, 
    35                  data_range=(None, None)): 
     34    def __init__(self, daddy, invdb, display, data, data_built=False,  
     35                 load_now=True, data_range=(None, None)): 
    3636        """ 
    3737        display expects to receive a ChangesDiff instance. 
     
    5050        gtk.VBox.__init__(self) 
    5151 
    52         self.invdb = ChangesRetrieve(umitdb) 
     52        self.invdb = invdb 
    5353        self.display = display 
    5454        self.daddy = daddy 
  • branch/ggpolo/umitInventory/DataGrabber.py

    r1260 r1431  
    2626#from umitInventory.TLBase import view_kind 
    2727 
     28from umitDB.Connection import ConnectDB 
    2829from umitDB.InventoryChanges import ChangesRetrieve 
    2930 
     
    3738                } 
    3839             
    39 class DataGrabber(ChangesRetrieve): 
     40class DataGrabber(ConnectDB, ChangesRetrieve): 
    4041    """ 
    4142    Grab data from Inventories or a single host for an Inventory, for a time  
     
    4445     
    4546    def __init__(self, calendar, inventory=None, hostaddr=None): 
    46         ChangesRetrieve.__init__(self, umitdb) 
     47        ConnectDB.__init__(self, umitdb) 
     48        ChangesRetrieve.__init__(self, self.conn, self.cursor) 
    4749 
    4850        self.calendar = calendar 
  • branch/ggpolo/umitInventory/InventoryLoad.py

    r1416 r1431  
    2222 
    2323from umitCore.Paths import Path 
     24from umitDB.Connection import ConnectDB 
    2425from umitDB.Retrieve import InventoryRetrieve 
    2526 
    2627UMITDB = Path.umitdb_ng 
    2728 
    28 class InventoryLoad(InventoryRetrieve): 
     29class InventoryLoad(ConnectDB, InventoryRetrieve): 
    2930    """ 
    3031    Load Inventories data to be used in Network Inventory. 
     
    3233     
    3334    def __init__(self): 
    34         InventoryRetrieve.__init__(self, UMITDB) 
     35        ConnectDB.__init__(self, UMITDB) 
     36        InventoryRetrieve.__init__(self, self.conn, self.cursor) 
    3537 
    3638        self.invdata = None 
  • branch/ggpolo/umitInventory/SearchBar.py

    r1300 r1431  
    231231    inventory = property(get_inventory, set_inventory) 
    232232 
    233  
    234 if __name__ == "__main__": 
    235     # sample 
    236     from umitDB.Retrieve import InventoryRetrieve 
    237     c = InventoryRetrieve("/home/polo/.umit/umitng.db") 
    238      
    239     w = gtk.Window() 
    240     box = gtk.HBox() 
    241     box.add(SearchBar(c)) 
    242     box.add(SearchBar(c)) 
    243     w.add(box) 
    244     w.show_all() 
    245     w.connect('delete-event', lambda *args: gtk.main_quit()) 
    246     gtk.main() 
    247  
  • branch/ggpolo/umitInventory/Timeline.py

    r1382 r1431  
    4343        gtk.VBox.__init__(self) 
    4444 
    45         self.connector = Connector()        
     45        self.connector = Connector() 
    4646        self.base = TLBase(self.connector, inventory, hostaddr) 
    4747 
     
    7979        # changes displaying 
    8080        self.changes_display = ChangesDiff(self.base) 
    81         self.changes_list = ChangesList(self, self.changes_display, None,  
     81        self.changes_list = ChangesList(self, self.base,  
     82                                        self.changes_display, None,  
    8283                                        load_now=False) 
    8384     
     
    203204        self.pack_start(main_hbox, True, True, 3) 
    204205         
    205  
    206 if __name__ == "__main__": 
    207     # sample 
    208     win = gtk.Window() 
    209     win.add(TLHolder()) 
    210     win.show_all() 
    211     win.connect('delete-event', lambda *args:gtk.main_quit()) 
    212     gtk.main() 
    213  
  • branch/ggpolo/umitInventory/Version.py

    r1403 r1431  
    2222""" 
    2323 
    24 NI_BUILD = "628" 
     24__version__ = "629" # more like a build version 
  • branch/ggpolo/umitInventory/Viewer.py

    r1421 r1431  
    3838from umitCore.Utils import open_url_as 
    3939 
    40 from umitDB.Retrieve import InventoryRetrieve 
     40from umitDB.Retrieve import ConnectInventoryDB 
    4141from umitDB.Search import SearchDB 
    4242 
     
    202202         
    203203        self.invsearch = SearchDB(umitdb) 
    204         self.invdb = InventoryRetrieve(umitdb) 
     204        self.invdb = ConnectInventoryDB(umitdb) 
    205205        self.invtree = InventoryTree(self) 
    206206        self.invnb = HIGNotebook() 
     
    404404        """ 
    405405        changesd = ChangesDiff(self.invdb) 
    406         changesl = ChangesList(self, changesd,  
     406        changesl = ChangesList(self, self.invdb, changesd,  
    407407                               data={-1: (inventory_name, host_addr)}) 
    408408 
     
    723723                <toolitem action='Sched Control' /> 
    724724                <separator /> 
    725                 <toolitem action='Report a bug' /> 
    726                 <toolitem action='Show Help' /> 
    727725            </toolbar> 
    728726            """ % invmenu