Changeset 433
- Timestamp:
- 05/12/08 16:28:10
- Arquivos:
-
- cacic/trunk/agente-linux/pycacic/src/cacic.py (modified) (9 diffs)
- cacic/trunk/agente-linux/pycacic/src/ger_cols.py (modified) (7 diffs)
- cacic/trunk/agente-linux/pycacic/src/globals.py (modified) (3 diffs)
- cacic/trunk/agente-linux/pycacic/src/gui.py (modified) (8 diffs)
Legenda:
- Não modificado
- Adicionado
- Removido
- Modificado
- Copiado
- Movido
cacic/trunk/agente-linux/pycacic/src/cacic.py
r430 r433 5 5 import time 6 6 import thread 7 from config.io import *8 7 from socket import * 9 8 from ger_cols import * 10 from config.io import Writer11 9 from globals import Globals 12 10 … … 16 14 17 15 def __init__(self): 18 #try: 16 try: 17 18 sys.path[0] = Globals.PATH 19 19 20 if not Globals.INSTALLED: 20 self.install()21 21 Globals.install() 22 22 23 if not self.isRoot(): 23 24 raise Exception("Para executar o programa é necessário estar como super usuário (root).") … … 25 26 print "\n\tBem-Vindo ao PyCacic\n" 26 27 # flags do Gerente de Coletas 27 self.gc_stopped = False28 self.gc_started = False29 self.gc_ok = False28 self.gc_stopped = 0 # False 29 self.gc_started = 0 # False 30 self.gc_ok = 0 # False 30 31 self.isforcada = [] 31 32 # Gerente de Coletas 32 33 self.gc = Ger_Cols(self.VERSION) 33 34 # 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() 39 36 # criando socket 40 37 self.udp_sock = socket.socket(AF_INET, SOCK_DGRAM) 41 38 self.udp_sock.bind(self.addr) 42 while True:39 while 1: 43 40 # verifica se o coletor nao esta parado 44 41 if not self.gc_stopped: 45 42 # muda estado do coletor para parado 46 self.gc_stopped = True43 self.gc_stopped = 1 # True 47 44 # conecta ao servidor para pegar as informacoes 48 45 xml = self.gc.conecta(self.gc.cacic_url, self.gc.dicionario) … … 60 57 if not self.gc_started and (self.gc_ok or len(self.isforcada) > 0): 61 58 # muda estado para nao habilitado 62 self.gc_ok = False59 self.gc_ok = 0 # False 63 60 # inicia coletas 64 61 self.gc.coletas_forcadas = self.isforcada … … 69 66 # fechando conexao 70 67 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 73 73 74 74 def isRoot(self): 75 75 """Retorna se o usuario e root ou nao""" 76 76 if os.getuid() != 0: 77 return False78 return True77 return 0 # False 78 return 1 # True 79 79 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"96 80 97 81 def start(self): 98 82 """Inicia as coletas""" 99 83 try: 100 self.gc_started = True84 self.gc_started = 1 # True 101 85 self.isforcada = [] 102 86 print(" --- INICIO DAS COLETAS ---") … … 106 90 self.gc.createDat() 107 91 self.gc.sendColetas() 108 self.gc_started = False92 self.gc_started = 0 # False 109 93 print(" --- FIM DAS COLETAS ---") 110 94 except Exception, e: … … 119 103 time.sleep(self.interval) 120 104 print '---- timeout !!!' 121 self.gc_stopped = False122 self.gc_ok = True105 self.gc_stopped = 0 # False 106 self.gc_ok = 1 # True 123 107 124 108 def checkSocket(self): … … 126 110 data, self.addr = self.udp_sock.recvfrom(self.buf) 127 111 self.isforcada.append(data) 128 time.sleep(1)129 112 130 113 … … 132 115 ver = sys.version_info 133 116 version = int(''.join([ '%s' %sys.version_info[x] for x in range(3)])) 134 if version < 2 40:135 print "ERROR: Python 2. 4or greater required"117 if version < 230: 118 print "ERROR: Python 2.3 or greater required" 136 119 sys.exit(1) 137 120 Cacic() cacic/trunk/agente-linux/pycacic/src/ger_cols.py
r430 r433 52 52 def __init__(self, version): 53 53 # para controle de intervalo 54 self.first_time = True54 self.first_time = 1 # True 55 55 # Inicializa o objeto que representa o computador 56 56 self.computador = Computador() … … 88 88 self.coletas_forcadas = [] 89 89 # se for True forca todas as coletas 90 self.all_forcada = False90 self.all_forcada = 0 # False 91 91 # Informacoes a serem passadas para o Gerente Web 92 92 self.computador.ipAtivo = self.computador.getIPAtivo(self.cacic_server) … … 141 141 print(" --- FIM ---") 142 142 except Exception, e: 143 import traceback 144 traceback.print_exc() 143 145 print(e) 144 146 … … 147 149 interval = self.intervalo_exec 148 150 if self.first_time: 149 self.first_time = False151 self.first_time = 0 # False 150 152 interval = self.exec_apos 151 153 return interval … … 173 175 """ Le o XML gerado pelo servidor WEB """ 174 176 # returns void 177 #print "XML: "+xml 175 178 self.xml = minidom.parseString(xml) 176 179 # se nao achar o status==OK, retorna … … 188 191 # COLETAS 189 192 elif no.nodeName == 'cs_coleta_forcada' and self.decode(no.firstChild.nodeValue) == 'OK': 190 self.all_forcada = True193 self.all_forcada = 1 # True 191 194 elif no.nodeName == 'cs_coleta_compart': 192 195 #self.addColeta(None, self.decode(no.firstChild.nodeValue)) … … 203 206 pass 204 207 # VERSOES 205 elif no.nodeName == ' DT_VERSAO_CACIC2_DISPONIVEL':208 elif no.nodeName == 'TE_VERSAO_PYCACIC_DISPONIVEL': 206 209 self.versao_disponivel = self.decode(no.firstChild.nodeValue) 207 210 elif no.nodeName == 'in_exibe_bandeja': cacic/trunk/agente-linux/pycacic/src/globals.py
r430 r433 11 11 """ 12 12 13 import os 14 import re 13 15 import sys 14 import os16 import commands 15 17 from config.io import Reader 18 from config.io import Writer 16 19 17 20 class Globals: … … 19 22 VERSION = "1.0.0" 20 23 PATH = "" 21 INSTALLED = False24 INSTALLED = 0 # False 22 25 PC_XML = "" 23 26 24 27 def __init__(self): 25 28 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) 26 69 # fim classe 27 70 … … 47 90 Globals.INSTALLED = isInstalled() 48 91 49 50 92 getArgs() cacic/trunk/agente-linux/pycacic/src/gui.py
r430 r433 6 6 7 7 import sys 8 import commands9 from ger_cols import *10 from config.io import *11 8 from globals import Globals 12 9 … … 18 15 ICON_PATH = "%s/img/logo.png" % Globals.PATH 19 16 GLADE_PATH = '%s/glade/' % Globals.PATH 17 TITLE = 'PyCacic' 20 18 21 19 main_visible = False … … 26 24 27 25 def createTray(self): 28 # TrayIcon 26 # TrayIcon 29 27 self.statusIcon = gtk.StatusIcon() 30 28 31 29 self.window = gtk.Window(gtk.WINDOW_TOPLEVEL) 32 self.window.set_title( "StatusIcon test (II)")30 self.window.set_title(self.TITLE) 33 31 self.window.connect('delete_event', self.delete_cb, self.statusIcon) 34 32 … … 43 41 self.imageicon = gtk.Image() 44 42 pixbuf = gtk.gdk.pixbuf_new_from_file(self.ICON_PATH) 45 scaled_buf = pixbuf.scale_simple(2 3, 23, gtk.gdk.INTERP_BILINEAR)43 scaled_buf = pixbuf.scale_simple(21, 23, gtk.gdk.INTERP_BILINEAR) 46 44 self.statusIcon.set_from_pixbuf(scaled_buf) 47 45 48 self.statusIcon.set_tooltip( "Pycacic")46 self.statusIcon.set_tooltip(self.TITLE) 49 47 self.statusIcon.connect('activate', self.activate_icon_cb) 50 48 self.statusIcon.connect('popup-menu', self.popup_menu_cb, self.menu) … … 59 57 if data: 60 58 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) 62 60 dialog.set_icon_from_file(self.ICON_PATH) 63 61 dialog.width, dialog.height = dialog.get_size() … … 98 96 self.xml.signal_autoconnect(self) 99 97 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 101 106 def show(self): 102 107 self.window.show() … … 115 120 def on_btn_executar_clicked(self, button): 116 121 """Executa o ger_cols""" 117 # Set the socket parameters118 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)124 122 self.udp_sock.sendto('col_hard' , self.addr) 125 123 self.udp_sock.close() … … 142 140 gtk.main() 143 141 except Exception, e: 144 print e.message 142 print e 143 import traceback 144 traceback.print_exc()
