Home Page do Portal
Brasil, um país de todos

Changeset 433

Show
Ignorar:
Timestamp:
05/12/08 16:28:10
Autor:
rogeriolino@gmail.com
Mensagem:

--

Arquivos:

Legenda:

Não modificado
Adicionado
Removido
Modificado
Copiado
Movido
  • cacic/trunk/agente-linux/pycacic/src/cacic.py

    r430 r433  
    55import time 
    66import thread 
    7 from config.io import * 
    87from socket import * 
    98from ger_cols import * 
    10 from config.io import Writer 
    119from globals import Globals 
    1210 
     
    1614     
    1715    def __init__(self):        
    18         #try:             
     16        try: 
     17             
     18            sys.path[0] = Globals.PATH 
     19             
    1920            if not Globals.INSTALLED: 
    20                 self.install() 
    21  
     21                Globals.install() 
     22             
    2223            if not self.isRoot(): 
    2324                raise Exception("Para executar o programa é necessário estar como super usuário (root).") 
     
    2526            print "\n\tBem-Vindo ao PyCacic\n" 
    2627            # flags do Gerente de Coletas 
    27             self.gc_stopped = False 
    28             self.gc_started = False 
    29             self.gc_ok = False 
     28            self.gc_stopped = 0 # False 
     29            self.gc_started = 0 # False 
     30            self.gc_ok = 0 # False 
    3031            self.isforcada = [] 
    3132            # Gerente de Coletas 
    3233            self.gc = Ger_Cols(self.VERSION) 
    3334            # configuracao do socket para comunicacao interna 
    34             sock = Reader.getSocket() 
    35             self.host = sock['host'] 
    36             self.port = int(sock['port']) 
    37             self.buf  = int(sock['buffer']) 
    38             self.addr = (self.host, self.port) 
     35            self.host, self.port, self.buf, self.addr = Globals.getSocketAttr() 
    3936            # criando socket 
    4037            self.udp_sock = socket.socket(AF_INET, SOCK_DGRAM) 
    4138            self.udp_sock.bind(self.addr) 
    42             while True
     39            while 1
    4340                # verifica se o coletor nao esta parado 
    4441                if not self.gc_stopped: 
    4542                    # muda estado do coletor para parado 
    46                     self.gc_stopped = True 
     43                    self.gc_stopped = 1 # True 
    4744                    # conecta ao servidor para pegar as informacoes 
    4845                    xml = self.gc.conecta(self.gc.cacic_url, self.gc.dicionario) 
     
    6057                if not self.gc_started and (self.gc_ok or len(self.isforcada) > 0): 
    6158                    # muda estado para nao habilitado 
    62                     self.gc_ok = False 
     59                    self.gc_ok = 0 # False 
    6360                    # inicia coletas 
    6461                    self.gc.coletas_forcadas = self.isforcada 
     
    6966            # fechando conexao 
    7067            self.udp_sock.close() 
    71         #except Exception, e: 
    72         #    print e  
     68        except Exception, e: 
     69            import traceback 
     70            traceback.print_exc() 
     71            print e 
     72 
    7373     
    7474    def isRoot(self): 
    7575        """Retorna se o usuario e root ou nao""" 
    7676        if os.getuid() != 0: 
    77             return False 
    78         return True 
     77            return 0 # False 
     78        return 1 # True 
    7979     
    80     def install(self): 
    81         """Abre console para configuracao do PyCacic""" 
    82         print "\n\t--- Bem-Vindo a Configuracao do PyCacic ---" 
    83         print "\n\tapos preencher as informacoes abaixo o programa ira iniciar\n" 
    84         addr = raw_input("End. do  Servidor ('ex: http://10.0.0.1'): ") 
    85         user = raw_input("Usuario do Servidor: ") 
    86         pwd = raw_input("Senha: ") 
    87         if raw_input("\n\t*** Os dados estao corretos? [y|n]").lower() != 'y': 
    88             self.install() 
    89         else: 
    90             Writer.setStatus('installed', True) 
    91             if addr[len(addr)-1] == '/': addr = addr[:-1] 
    92             Writer.setServer('address', addr) 
    93             Writer.setServer('username', user) 
    94             Writer.setServer('password', pwd) 
    95         print "\t--- Configuracao concluida com sucesso ---\n\n" 
    9680 
    9781    def start(self): 
    9882        """Inicia as coletas""" 
    9983        try: 
    100             self.gc_started = True             
     84            self.gc_started = 1 # True             
    10185            self.isforcada = [] 
    10286            print(" --- INICIO DAS COLETAS ---") 
     
    10690            self.gc.createDat() 
    10791            self.gc.sendColetas() 
    108             self.gc_started = False 
     92            self.gc_started = 0 # False 
    10993            print(" --- FIM DAS COLETAS ---") 
    11094        except Exception, e: 
     
    119103        time.sleep(self.interval) 
    120104        print '---- timeout !!!' 
    121         self.gc_stopped = False 
    122         self.gc_ok = True 
     105        self.gc_stopped = 0 # False 
     106        self.gc_ok = 1 # True 
    123107 
    124108    def checkSocket(self): 
     
    126110        data, self.addr = self.udp_sock.recvfrom(self.buf) 
    127111        self.isforcada.append(data) 
    128         time.sleep(1) 
    129112 
    130113 
     
    132115    ver =  sys.version_info 
    133116    version = int(''.join([ '%s' %sys.version_info[x] for x in range(3)])) 
    134     if version < 240: 
    135         print "ERROR: Python 2.4 or greater required" 
     117    if version < 230: 
     118        print "ERROR: Python 2.3 or greater required" 
    136119        sys.exit(1) 
    137120    Cacic() 
  • cacic/trunk/agente-linux/pycacic/src/ger_cols.py

    r430 r433  
    5252    def __init__(self, version): 
    5353        # para controle de intervalo 
    54         self.first_time = True 
     54        self.first_time = 1 # True 
    5555        # Inicializa o objeto que representa o computador 
    5656        self.computador = Computador() 
     
    8888        self.coletas_forcadas = [] 
    8989        # se for True forca todas as coletas 
    90         self.all_forcada = False 
     90        self.all_forcada = 0 # False 
    9191        # Informacoes a serem passadas para o Gerente Web 
    9292        self.computador.ipAtivo = self.computador.getIPAtivo(self.cacic_server) 
     
    141141            print(" --- FIM ---") 
    142142        except Exception, e: 
     143            import traceback 
     144            traceback.print_exc() 
    143145            print(e) 
    144146 
     
    147149        interval = self.intervalo_exec 
    148150        if self.first_time: 
    149             self.first_time = False 
     151            self.first_time = 0 # False 
    150152            interval = self.exec_apos 
    151153        return interval 
     
    173175        """ Le o XML gerado pelo servidor WEB """ 
    174176        # returns void 
     177        #print "XML: "+xml 
    175178        self.xml = minidom.parseString(xml) 
    176179        # se nao achar o status==OK, retorna 
     
    188191                    # COLETAS 
    189192                    elif no.nodeName == 'cs_coleta_forcada' and self.decode(no.firstChild.nodeValue) == 'OK': 
    190                         self.all_forcada = True 
     193                        self.all_forcada = 1 # True 
    191194                    elif no.nodeName == 'cs_coleta_compart':                        
    192195                        #self.addColeta(None, self.decode(no.firstChild.nodeValue)) 
     
    203206                        pass 
    204207                    # VERSOES 
    205                     elif no.nodeName == 'DT_VERSAO_CACIC2_DISPONIVEL': 
     208                    elif no.nodeName == 'TE_VERSAO_PYCACIC_DISPONIVEL': 
    206209                        self.versao_disponivel = self.decode(no.firstChild.nodeValue) 
    207210                    elif no.nodeName == 'in_exibe_bandeja': 
  • cacic/trunk/agente-linux/pycacic/src/globals.py

    r430 r433  
    1111""" 
    1212 
     13import os 
     14import re 
    1315import sys 
    14 import o
     16import command
    1517from config.io import Reader 
     18from config.io import Writer 
    1619 
    1720class Globals: 
     
    1922    VERSION = "1.0.0" 
    2023    PATH = "" 
    21     INSTALLED = False 
     24    INSTALLED = 0 # False 
    2225    PC_XML = "" 
    2326     
    2427    def __init__(self): 
    2528        pass 
     29     
     30    def getSocketAttr(): 
     31        """Retorna as informacoes do Socket""" 
     32        sock = Reader.getSocket() 
     33        host = sock['host'] 
     34        port = int(sock['port']) 
     35        buf  = int(sock['buffer']) 
     36        addr = (host, port) 
     37        return host, port, buf, addr 
     38     
     39    def install(): 
     40        """Abre console para configuracao do PyCacic""" 
     41        print "\n\t--- Bem-Vindo a Configuracao do PyCacic ---" 
     42        print "\n\tapos preencher as informacoes abaixo o programa ira iniciar\n" 
     43        addr = raw_input("End. do  Servidor ('ex: http://10.0.0.1'): ") 
     44        print "Testando conexao..." 
     45        p = re.compile('[0-9]{1,3}(?:\.[0-9]{1,3}){3}') 
     46        if len(p.findall(addr)) == 0: 
     47            print "Endereco invalido" 
     48            Globals.install() 
     49            return  
     50        ip = p.findall(addr)[0]             
     51        if commands.getoutput('ping %s -c 1; echo $?' % ip)[-1:] != '0': 
     52            print "Erro ao tentar conectar ao servidor" 
     53            Globals.install() 
     54            return 
     55        user = raw_input("Usuario do Servidor: ") 
     56        pwd = raw_input("Senha: ") 
     57        if raw_input("\n\t*** Os dados estao corretos? [y|n]").lower() != 'y': 
     58            Globals.install() 
     59            return 
     60        Writer.setStatus('installed', 1) 
     61        if addr[len(addr)-1] == '/': addr = addr[:-1] 
     62        Writer.setServer('address', addr) 
     63        Writer.setServer('username', user) 
     64        Writer.setServer('password', pwd)             
     65        print "\t--- Configuracao concluida com sucesso ---\n\n" 
     66         
     67    getSocketAttr = staticmethod(getSocketAttr) 
     68    install = staticmethod(install) 
    2669# fim classe 
    2770 
     
    4790Globals.INSTALLED = isInstalled() 
    4891 
    49  
    5092getArgs() 
  • cacic/trunk/agente-linux/pycacic/src/gui.py

    r430 r433  
    66 
    77import sys 
    8 import commands 
    9 from ger_cols import * 
    10 from config.io import * 
    118from globals import Globals  
    129 
     
    1815    ICON_PATH = "%s/img/logo.png" % Globals.PATH 
    1916    GLADE_PATH = '%s/glade/' % Globals.PATH 
     17    TITLE = 'PyCacic' 
    2018       
    2119    main_visible = False 
     
    2624     
    2725    def createTray(self): 
    28         # TrayIcon         
     26        # TrayIcon 
    2927        self.statusIcon = gtk.StatusIcon() 
    3028         
    3129        self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 
    32         self.window.set_title("StatusIcon test (II)"
     30        self.window.set_title(self.TITLE
    3331        self.window.connect('delete_event', self.delete_cb, self.statusIcon) 
    3432  
     
    4341        self.imageicon = gtk.Image() 
    4442        pixbuf = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH) 
    45         scaled_buf = pixbuf.scale_simple(23, 23, gtk.gdk.INTERP_BILINEAR) 
     43        scaled_buf = pixbuf.scale_simple(21, 23, gtk.gdk.INTERP_BILINEAR) 
    4644        self.statusIcon.set_from_pixbuf(scaled_buf) 
    4745         
    48         self.statusIcon.set_tooltip("Pycacic"
     46        self.statusIcon.set_tooltip(self.TITLE
    4947        self.statusIcon.connect('activate', self.activate_icon_cb) 
    5048        self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu) 
     
    5957        if data: 
    6058            dialog = gtk.MessageDialog( None, gtk.DIALOG_MODAL, gtk.MESSAGE_QUESTION, gtk.BUTTONS_YES_NO, 'Deseja realmente sair?')         
    61             dialog.set_title('PyCacic')                 
     59            dialog.set_title(self.TITLE)                 
    6260            dialog.set_icon_from_file(self.ICON_PATH) 
    6361            dialog.width, dialog.height = dialog.get_size() 
     
    9896        self.xml.signal_autoconnect(self) 
    9997        self.window = self.xml.get_widget('main_window') 
    100          
     98        self.connect() 
     99     
     100    def connect(self): 
     101        # Set the socket parameters 
     102        self.host, self.port, self.buf, self.addr = Globals.getSocketAttr() 
     103        self.udp_sock = socket(AF_INET, SOCK_DGRAM) 
     104             
     105     
    101106    def show(self): 
    102107        self.window.show()        
     
    115120    def on_btn_executar_clicked(self, button): 
    116121        """Executa o ger_cols""" 
    117         # Set the socket parameters 
    118         sock = Reader.getSocket() 
    119         self.host = sock['host'] 
    120         self.port = int(sock['port']) 
    121         self.buf  = int(sock['buffer']) 
    122         self.addr = (self.host, self.port) 
    123         self.udp_sock = socket(AF_INET, SOCK_DGRAM) 
    124122        self.udp_sock.sendto('col_hard' , self.addr) 
    125123        self.udp_sock.close() 
     
    142140        gtk.main() 
    143141    except Exception, e: 
    144         print e.message 
     142        print e 
     143        import traceback 
     144        traceback.print_exc()