Changeset 944

Show
Ignore:
Timestamp:
08/06/08 19:52:38 (4 months ago)
Author:
mariodebian
Message:

tcosmonitor (0.2.16~rc3)

  • New class: TcosListView?.py:
    • Move some code from TcosActions?.py (code to work with list view mode)
  • New class: TcosMenus?.py:
    • Move some code from TcosActions?.py to generate menus and capture events
  • Delete deprecated and comented gtk.gdk.threads_*() calls
  • Update template and spanish translation
Location:
trunk/tcosmonitor
Files:
2 added
26 modified

Legend:

Unmodified
Added
Removed
  • trunk/tcosmonitor/Initialize.py

    r930 r944  
    5454 
    5555 
    56 class Initialize: 
    57     #drop_targets = [ ( "text/plain", 0, TARGET_TYPE_TEXT ) ] 
    58      
     56class Initialize(object): 
     57 
    5958    def __init__(self, main): 
    6059        print_debug ( "__init__() starting" ) 
     
    7271        self.main.viewtabs=self.ui.get_widget('viewtabs') 
    7372        self.main.viewtabs.set_property('show-tabs', False) 
    74         #for m in dir(self.main.viewtabs): 
    75         #    if "page" in m: print m 
    76         #print "get_n_pages", self.main.viewtabs.get_n_pages() 
    77         #print "set_current_page", self.main.viewtabs.set_current_page(2)) 
     73        self.main.viewtabs.connect("switch_page", self.on_viewtabs_change) 
    7874         
    7975        self.ask_mode=None 
    8076         
     77    def on_viewtabs_change(self, widget, pointer, tabnum): 
     78        if tabnum != 0: 
     79            self.main.searchbutton.set_sensitive(False) 
     80            self.main.searchtxt.set_sensitive(False) 
     81        else: 
     82            self.main.searchbutton.set_sensitive(True) 
     83            self.main.searchtxt.set_sensitive(True) 
     84    """ 
    8185    def get_widget(self, wname): 
    8286        widgets = gtk.glade.XML( shared.GLADE_DIR + 'tcosmonitor.glade', wname ) 
    8387        return widgets.get_widget( wname ) 
    84          
     88    """ 
     89     
    8590    def init_progressbar(self): 
    8691        self.main.progressbar=self.ui.get_widget('progressbar') 
     
    228233        return 
    229234     
    230      
     235    """ 
    231236    def init_hostlist(self): 
    232237        print_debug ( "init_hostlist()" ) 
     
    303308        print_debug("on_sel_click() ip=%s status=%s" %(model[path][COL_IP], model[path][col])) 
    304309        return True 
     310    """ 
    305311 
    306312if __name__ == '__main__': 
  • trunk/tcosmonitor/LocalData.py

    r930 r944  
    319319                    return False 
    320320            return True 
    321         except: 
     321        except Exception, err: 
     322            print_debug("ipValid() Exception, error=%s"%err) 
    322323            return False 
    323324 
     
    325326        try: 
    326327            return socket.getaddrinfo(hostname, None)[0][4][0]   
    327         except: 
     328        except Exception, err: 
     329            print_debug("GetIpAddress() Exception, error=%s"%err) 
    328330            return None 
    329331         
     
    353355            self.add_to_cache( ip, 1 , self.hostname ) 
    354356            return self.hostname 
    355         except: 
     357        except Exception, err: 
     358            print_debug("GetHostname() Exception, error=%s"%err) 
    356359            pass 
    357360         
     
    436439 
    437440    def GetLast(self, ip, ingroup=None): 
     441        start=time() 
    438442        last=None 
    439443        data={} 
     
    498502            data={"pid":last.ut_pid, "user":last.ut_user, "host":last.ut_host.split(":")[0], "time":last.ut_tv[0], "timelogged":timelogged, "exclude":exclude} 
    499503            print_debug("IsLast() data=%s"%data) 
     504        crono(start, "GetLast()") 
    500505        return data 
    501506     
  • trunk/tcosmonitor/Makefile

    r930 r944  
    9999        install -m 644 WakeOnLan.py        $(DESTDIR)/$(PREFIX)/share/$(PACKAGE)/ 
    100100        install -m 644 TcosIconView.py     $(DESTDIR)/$(PREFIX)/share/$(PACKAGE)/ 
     101        install -m 644 TcosClassView.py    $(DESTDIR)/$(PREFIX)/share/$(PACKAGE)/ 
     102        install -m 644 TcosListView.py     $(DESTDIR)/$(PREFIX)/share/$(PACKAGE)/ 
    101103 
    102104        install -m 755 tcosmonitor.py           $(DESTDIR)/$(PREFIX)/bin/tcosmonitor 
     
    180182        sed -i 's/__VERSION__/$(VERSION)/g' TcosStaticHosts.py 
    181183        sed -i 's/__VERSION__/$(VERSION)/g' TcosIconView.py 
     184        sed -i 's/__VERSION__/$(VERSION)/g' TcosListView.py 
     185        sed -i 's/__VERSION__/$(VERSION)/g' TcosClassView.py 
    182186        sed -i 's/__VERSION__/$(VERSION)/g' tcos-devices-ng.py 
    183187        sed -i 's/__VERSION__/$(VERSION)/g' tcos-volume-manager.py 
  • trunk/tcosmonitor/TcosActions.py

    r931 r944  
    5353        print_debug ( "__init__()" ) 
    5454        self.main=main 
    55         self.model=self.main.init.model 
     55        #self.model=self.main.init.model 
    5656        #self.main.progressstop_args={} 
    5757 
     
    101101        print_debug ( "on_another_screenshot_button_click() __init__ ip=%s" %(ip) ) 
    102102        self.main.worker=shared.Workers(self.main, target=self.get_screenshot, args=[ip]) 
    103         self.main.worker.start()    
    104      
    105     def on_rightclickmenuone_click(self, menu, number): 
    106         print_debug ( "on_rightclickmenuone_click() => onehost_menuitems[%d]=%s" \ 
    107                         % (number, shared.onehost_menuitems[number][0]) ) 
    108         self.menu_event_one(number) 
     103        self.main.worker.start() 
    109104 
    110105    def on_allhostbutton_click(self, widget): 
     
    113108        self.main.allmenu.popup( None, None, None, event.button, event.time) 
    114109        return True 
    115  
    116     def on_rightclickmenuall_click(self, menu, number): 
    117         print_debug ( "on_rightclickmenuall_click() => allhost_menuitems[%d]=%s" \ 
    118                         % (number, shared.allhost_menuitems[number][0]) ) 
    119         self.menu_event_all(number) 
    120110 
    121111    def on_preferencesbutton_click(self,widget): 
     
    173163            if len(allclients) == 0: 
    174164                self.main.write_into_statusbar ( _("Not connected hosts found.") ) 
    175                 # clean treeview 
    176                 model=self.main.tabla.get_model() 
    177                 model.clear() 
     165                # clean icons and files 
     166                self.main.listview.clear() 
    178167                self.main.iconview.clear() 
    179168                self.main.classview.clear() 
     
    230219        return self.main.updating 
    231220 
    232  
    233     def on_hostlist_click(self, hostlist): 
    234         if self.main.worker_running: 
    235             return 
    236          
    237         self.main.progressbar.hide() 
    238         (model, iter) = hostlist.get_selected() 
    239         if not iter: 
    240             return 
    241         self.main.selected_host=model.get_value(iter,COL_HOST) 
    242         self.main.selected_ip=model.get_value(iter, COL_IP) 
    243          
    244         print_debug ( "on_hostlist_clic() selectedhost=%s selectedip=%s" \ 
    245             %(self.main.selected_host, self.main.selected_ip) ) 
    246              
    247         # call to read remote info 
    248         #self.main.localdata.newhost(self.main.selected_ip) 
    249         self.main.xmlrpc.newhost(self.main.selected_ip) 
    250         self.main.xmlrpc.ip=self.main.selected_ip 
    251         if not self.main.xmlrpc.isPortListening(self.main.selected_ip, self.main.xmlrpc.lastport): 
    252             print_debug ( "on_host_list_click() XMLRPC not running in %s" %(self.main.selected_ip) ) 
    253             self.main.write_into_statusbar ( _("Error connecting to tcosxmlrpc in %s") %(self.main.selected_ip) ) 
    254             return 
    255          
    256         print_debug ( "on_host_list_click() AUTH OK" ) 
    257          
    258         self.main.write_into_statusbar ( "" ) 
    259         print_debug ( "on_hostlist_click() callig worker to populate in Thread" ) 
    260          
    261         self.main.worker=shared.Workers( self.main,\ 
    262                      target=self.populate_datatxt, args=([self.main.selected_ip]) ).start() 
    263          
    264         return 
    265221         
    266222    def askwindow_close(self, widget, event): 
     
    514470         
    515471        # print into statusbar 
    516         #gtk.gdk.threads_enter() 
    517472        self.main.common.threads_enter("TcosActions:populate_datatxt show progressbar") 
    518473         
    519         if shared.disable_textview_on_update: self.main.tabla.set_sensitive(False) 
     474        if shared.disable_textview_on_update and self.main.iconview.isactive(): 
     475            self.main.tabla.set_sensitive(True) 
    520476         
    521477        #self.main.write_into_statusbar( _("Connecting with %s to retrieve some info..."  ) %(ip) ) 
     
    524480        #self.main.progressbutton.show() 
    525481        self.set_progressbar( _("Connecting with %s to retrieve some info..."  ) %(ip) , 0 ,show_percent=False) 
    526         #gtk.gdk.threads_leave() 
     482         
    527483        self.main.common.threads_leave("TcosActions:populate_datatxt show progressbar") 
    528484         
     
    758714                    try: 
    759715                        (key,value)=data.split('=') 
    760                     except: 
     716                    except Exception, err: 
     717                        print_debug("populate_datatxt() Exception spliting data=%s, err=%s"%(data,err)) 
    761718                        key=data 
    762719                        value="" 
     
    844801                    try: 
    845802                        value=float(value) 
    846                     except: 
     803                    except Exception, err: 
     804                        print_debug("populate_datatxt() Exception getting volume=%s, err=%s"%(value,err) ) 
    847805                        value=0.0 
    848806                     
     
    945903                self.datatxt.insert_block ( _("Sound server is not running"), image=shared.IMG_DIR + "info_sound_ko.png") 
    946904         
    947         #gtk.gdk.threads_enter() 
    948905        self.main.common.threads_enter("TcosActions:populate_datatxt end") 
    949906        self.datatxt.display() 
     
    951908        self.main.progressbar.hide() 
    952909         
    953         if shared.disable_textview_on_update: self.main.tabla.set_sensitive(True) 
    954          
    955         #gtk.gdk.threads_leave() 
     910        if shared.disable_textview_on_update and self.main.iconview.isactive(): 
     911            self.main.tabla.set_sensitive(True) 
     912         
    956913        self.main.common.threads_leave("TcosActions:populate_datatxt end") 
    957914         
     
    999956        print_debug ( "populate_hostlist() clear list and start progressbar!!!" ) 
    1000957         
    1001         #gtk.gdk.threads_enter() 
    1002958        self.main.common.threads_enter("TcosActions:populate_hostlist show progressbar") 
    1003959         
    1004         if shared.disable_textview_on_update: self.main.tabla.set_sensitive(False) 
     960        if shared.disable_textview_on_update and self.main.iconview.isactive(): 
     961            self.main.tabla.set_sensitive(True) 
    1005962 
    1006963        #disable refresh button 
     
    1009966        self.main.progressbutton.show() 
    1010967        self.set_progressbar( _("Searching info of hosts..."), 0) 
    1011         self.model.clear() 
     968        if self.main.listview.isenabled(): 
     969            self.main.listview.clear() 
    1012970        if self.main.iconview.isenabled(): 
    1013                 self.main.iconview.clear() 
     971            self.main.iconview.clear() 
    1014972        if self.main.classview.isenabled(): 
    1015                 self.main.classview.clear() 
    1016         #gtk.gdk.threads_leave() 
     973            self.main.classview.clear() 
    1017974        self.main.common.threads_leave("TcosActions:populate_hostlist show progressbar") 
    1018975         
     
    1036993                    print_debug ( "populate_hostlist() WORKER IS STOPPED" ) 
    1037994                    break 
    1038             except: 
     995            except Exception, err: 
     996                print_debug("populate_hostlist() can't read worker status, error=%s"%err) 
    1039997                pass 
    1040998            i += 1 
    1041             #gtk.gdk.threads_enter() 
    1042999            self.main.common.threads_enter("TcosActions:populate_hostlist show connecting") 
    10431000            self.main.progressbar.show() 
    1044             self.set_progressbar( _("Connecting to %s...") \ 
    1045                             %(host), float(i)/float(len(clients)) ) 
    1046             #gtk.gdk.threads_leave() 
     1001            self.set_progressbar( _("Connecting to %s...") %(host), float(i)/float(len(clients)) ) 
    10471002            self.main.common.threads_leave("TcosActions:populate_hostlist show connecting") 
    10481003             
     
    10511006            self.main.xmlrpc.newhost (host) 
    10521007             
    1053             ip=host 
    1054             standalone=False 
    1055             logged=False 
     1008            data={} 
     1009            data['host']=host 
     1010            data['ip']=host 
     1011            data['standalone']=False 
     1012            data['logged']=False 
    10561013            print_debug("populate_hostlist() => get username") 
    1057             username=self.main.localdata.GetUsername(ip) 
     1014            data['username']=self.main.localdata.GetUsername(data['ip']) 
    10581015             
    10591016            if shared.dont_show_users_in_group != None: 
    1060                 if self.main.xmlrpc.IsStandalone(ip): 
     1017                if self.main.xmlrpc.IsStandalone(data['ip']): 
    10611018                    groupexclude=self.main.xmlrpc.GetStandalone("get_exclude", shared.dont_show_users_in_group) 
    10621019                else: 
    1063                     groupexclude=self.main.localdata.isExclude(ip, shared.dont_show_users_in_group) 
     1020                    groupexclude=self.main.localdata.isExclude(data['ip'], shared.dont_show_users_in_group) 
    10641021             
    10651022                if groupexclude:  
    1066                     print_debug("Host %s excluded, blacklisted by group" %ip) 
     1023                    print_debug("Host %s excluded, blacklisted by group" %data['ip']) 
    10671024                    continue 
    10681025             
    10691026            print_debug("populate_hostlist() => get hostname") 
    1070             hostname=self.main.localdata.GetHostname(ip) 
    1071              
    1072             if username.startswith('error: tcos-last'): 
    1073                 username="---" 
     1027            data['hostname']=self.main.localdata.GetHostname(data['ip']) 
     1028             
     1029            if data['username'].startswith('error: tcos-last'): 
     1030                data['username']="---" 
    10741031             
    10751032            try: 
    10761033                print_debug("populate_hostlist() => get num process") 
    1077                 num_process=self.main.localdata.GetNumProcess(ip) 
    1078             except: 
    1079                 num_process="---" 
     1034                data['num_process']=self.main.localdata.GetNumProcess(data['ip']) 
     1035            except Exception, err: 
     1036                print_debug("populate_hostlist() Exception getting num process, error=%s"%err) 
     1037                data['num_process']="---" 
    10801038             
    10811039            print_debug("populate_hostlist() => get time logged") 
    1082             if self.main.xmlrpc.IsStandalone(ip): 
    1083                 time_logged=self.main.xmlrpc.GetStandalone("get_time") 
    1084                 standalone=True 
     1040            if self.main.xmlrpc.IsStandalone(data['ip']): 
     1041                data['time_logged']=self.main.xmlrpc.GetStandalone("get_time") 
     1042                data['standalone']=True 
    10851043            else: 
    1086                 time_logged=self.main.localdata.GetTimeLogged(ip) 
    1087                 standalone=False 
    1088              
    1089             if not time_logged or time_logged == "" or time_logged.startswith('error: tcos-last'): 
    1090                 time_logged="---" 
     1044                data['time_logged']=self.main.localdata.GetTimeLogged(data['ip']) 
     1045                data['standalone']=False 
     1046             
     1047            if not data['time_logged'] or data['time_logged'] == "" or data['time_logged'].startswith('error: tcos-last'): 
     1048                data['time_logged']="---" 
    10911049             
    10921050            print_debug("populate_hostlist() => get active connection") 
    1093             if self.main.localdata.IsActive(ip): 
     1051            if self.main.localdata.IsActive(data['ip']): 
     1052                data['active']=True 
    10941053                if self.main.xmlrpc.sslconnection: 
    1095                     image_active=active_ssl_image 
     1054                    data['image_active']=active_ssl_image 
    10961055                else: 
    1097                     image_active=active_image 
     1056                    data['image_active']=active_image 
    10981057            else: 
    1099                 image_active=inactive_image 
     1058                data['image_active']=inactive_image 
     1059                data['active']=False 
    11001060             
    11011061            print_debug("populate_hostlist() => get is logged") 
    1102             if self.main.localdata.IsLogged(ip): 
    1103                 image_logged=logged_image 
    1104                 logged=True 
     1062            if self.main.localdata.IsLogged(data['ip']): 
     1063                data['image_logged']=logged_image 
     1064                data['logged']=True 
    11051065            else: 
    1106                 image_logged=unlogged_image 
    1107                 logged=False 
     1066                data['image_logged']=unlogged_image 
     1067                data['logged']=False 
    11081068             
    11091069            print_debug("populate_hostlist() => get is blocked") 
    1110             if self.main.localdata.IsBlocked(host): 
    1111                 blocked_screen=True 
     1070            if self.main.localdata.IsBlocked(data['ip']): 
     1071                data['blocked_screen']=True 
    11121072            else: 
    1113                 blocked_screen=False 
     1073                data['blocked_screen']=False 
    11141074             
    11151075            print_debug("populate_hostlist() => get is blocked net") 
    1116             if self.main.localdata.IsBlockedNet(host,username): 
    1117                 blocked_net=True 
     1076            if self.main.localdata.IsBlockedNet(host,data['username']): 
     1077                data['blocked_net']=True 
    11181078            else: 
    1119                 blocked_net=False 
    1120                  
    1121             if blocked_screen and blocked_net: 
    1122                 image_blocked=locked_net_screen_image 
    1123             elif blocked_screen == False and blocked_net: 
    1124                 image_blocked=locked_net_image 
    1125             elif blocked_screen and blocked_net == False: 
    1126                 image_blocked=locked_image 
     1079                data['blocked_net']=False 
     1080                 
     1081            if data['blocked_screen'] and data['blocked_net']: 
     1082                data['image_blocked']=locked_net_screen_image 
     1083            elif data['blocked_screen'] == False and data['blocked_net']: 
     1084                data['image_blocked']=locked_net_image 
     1085            elif data['blocked_screen'] and data['blocked_net'] == False: 
     1086                data['image_blocked']=locked_image 
    11271087            else: 
    1128                 image_blocked=unlocked_image 
    1129              
    1130             data={'ip':ip, 'hostname':hostname, 'host':host,  
    1131                       'standalone':standalone, 'username':username, 
    1132                       'blocked_screen':blocked_screen, 'blocked_net': blocked_net, 
    1133                       'logged':logged, 'time_logged':time_logged} 
     1088                data['image_blocked']=unlocked_image 
     1089             
     1090             
     1091            if self.main.listview.isactive(): 
     1092                self.main.common.threads_enter("TcosActions:populate_hostlist LIST generate_icon") 
     1093                self.main.listview.generate_file(data) 
     1094                self.main.common.threads_leave("TcosActions:populate_hostlist LIST generate_icon") 
    11341095             
    11351096            if self.main.iconview.isactive(): 
     
    11371098                self.main.iconview.generate_icon(data) 
    11381099                self.main.common.threads_leave("TcosActions:populate_hostlist ICON generate_icon") 
    1139                  
     1100             
    11401101            if self.main.classview.isactive(): 
    11411102                self.main.common.threads_enter("TcosActions:populate_hostlist CLASS generate_icon") 
     
    11431104                self.main.common.threads_leave("TcosActions:populate_hostlist CLASS generate_icon") 
    11441105             
    1145             #gtk.gdk.threads_enter() 
    1146             self.main.common.threads_enter("TcosActions:populate_hostlist print data") 
    1147             self.iter = self.model.append (None) 
    1148             self.model.set_value (self.iter, COL_HOST, hostname ) 
    1149             self.model.set_value (self.iter, COL_IP, host ) 
    1150             self.model.set_value (self.iter, COL_USERNAME, username ) 
    1151             self.model.set_value (self.iter, COL_ACTIVE, image_active ) 
    1152             self.model.set_value (self.iter, COL_LOGGED, image_logged) 
    1153             self.model.set_value (self.iter, COL_BLOCKED, image_blocked) 
    1154             self.model.set_value (self.iter, COL_PROCESS, num_process ) 
    1155             self.model.set_value (self.iter, COL_TIME, time_logged) 
    1156             #gtk.gdk.threads_leave() 
    1157             self.main.common.threads_leave("TcosActions:populate_hostlist print data") 
    1158              
    1159             crono(start2, "populate_host_list(%s)" %(ip) ) 
    1160          
    1161         #gtk.gdk.threads_enter() 
     1106             
     1107            crono(start2, "populate_host_list(%s)" %(data['ip']) ) 
     1108         
    11621109        self.main.common.threads_enter("TcosActions:populate_hostlist END") 
    11631110        self.main.progressbar.hide() 
     
    11661113        self.main.progressbutton.set_sensitive(True) 
    11671114         
    1168         if shared.disable_textview_on_update: self.main.tabla.set_sensitive(True) 
    1169          
    1170         #gtk.gdk.threads_leave() 
     1115        if shared.disable_textview_on_update and self.main.iconview.isactive(): 
     1116            self.main.tabla.set_sensitive(True) 
     1117         
    11711118        self.main.common.threads_leave("TcosActions:populate_hostlist END") 
    11721119         
    11731120        try: 
    11741121            self.main.worker.set_finished() 
    1175         except: 
     1122        except Exception, err: 
     1123            print_debug("populate_hostlist() Exception setting worker status, err=%s" %err) 
    11761124            pass 
    11771125        crono(start1, "populate_host_list(ALL)" ) 
     
    12041152            self.main.selected_host=self.main.classview.get_host(self.main.selected_ip) 
    12051153        else: 
    1206             (model, iter) = self.main.tabla.get_selection().get_selected() 
    1207             if iter == None: 
    1208                 print_debug( "menu_event_one() not selected thin client !!!" ) 
    1209                 return 
    1210             self.main.selected_host=model.get_value(iter,COL_HOST) 
    1211             self.main.selected_ip=model.get_value(iter, COL_IP) 
     1154            self.main.selected_ip=self.main.listview.get_selected() 
     1155            self.main.selected_host=self.main.listview.get_host(self.main.selected_ip) 
     1156            #(model, iter) = self.main.tabla.get_selection().get_selected() 
     1157            #if iter == None: 
     1158            #    print_debug( "menu_event_one() not selected thin client !!!" ) 
     1159            #    return 
     1160            #self.main.selected_host=model.get_value(iter,COL_HOST) 
     1161            #self.main.selected_ip=model.get_value(iter, COL_IP) 
     1162         
     1163        if not self.main.selected_ip: 
     1164            # show a msg 
     1165            shared.error_msg ( _("Error: no IP!") ) 
     1166            return 
    12121167         
    12131168        if not self.doaction_onthisclient(action, self.main.selected_ip): 
     
    16771632                 
    16781633            if self.main.config.GetVar("selectedhosts") == 1: 
    1679                 allclients=[] 
    1680                 model=self.main.tabla.get_model() 
    1681                 rows = [] 
    1682                 model.foreach(lambda model, path, iter: rows.append(path)) 
    1683                 for host in rows: 
    1684                     iter=model.get_iter(host) 
    1685                     if model.get_value(iter, COL_SEL_ST): 
    1686                         allclients.append(model.get_value(iter, COL_IP)) 
     1634                #allclients=[] 
     1635                #model=self.main.tabla.get_model() 
     1636                #rows = [] 
     1637                #model.foreach(lambda model, path, iter: rows.append(path)) 
     1638                #for host in rows: 
     1639                #    iter=model.get_iter(host) 
     1640                #    if model.get_value(iter, COL_SEL_ST): 
     1641                #        allclients.append(model.get_value(iter, COL_IP))