Exemple #1
0
    def check_version(self):
        with open(os.path.join(common.get_current_path(), VERSIONFILE),
                  'r') as f:
            version = f.read().strip()
        print u"Verificando actualizaciones"
        data = {"checking_version": True, "version": version}
        try:
            response = common.send_data(data)
        except:
            return
        if response.get("command", None) == "update":
            print u"Nueva version disponible (Actual: %s,Nueva: %s)" % (
                version, response["new_version"])
            file_url = common.URL + response["file_url"]
            response = urllib2.urlopen(file_url)
            _file = StringIO(response.read())
            if zipfile.is_zipfile(_file):

                zfl = zipfile.ZipFile(_file)
                members = zfl.namelist()[:]
                root_path = None
                for n in members[:]:
                    if os.path.basename(n) == "cncid":
                        members.remove(n)
                    elif os.path.basename(n) == "main.py":
                        if not root_path:
                            root_path = os.path.dirname(n)
                if root_path is not None:
                    for n in members[:]:
                        if not n.startswith(root_path):
                            members.remove(n)
                for m in members:
                    source = zfl.open(m)
                    file_target = os.path.join(common.get_current_path(),
                                               os.path.relpath(m, root_path))
                    if os.path.basename(m) == "":  #es directorio
                        if not os.path.exists(file_target):
                            os.makedirs(file_target)
                    else:  #es archivo
                        target = file(file_target, "wb")
                        with source, target:
                            shutil.copyfileobj(source, target)
                print u"Reiniciando script..."
                common.restart_please()
        else:
            print u"Versión más reciente (%s)" % version
Exemple #2
0
 def check_version(self):
     with open(os.path.join(common.get_current_path(),VERSIONFILE), 'r') as f:
         version=f.read().strip()
     print u"Verificando actualizaciones"
     data={"checking_version":True,"version":version}
     try:
         response= common.send_data(data)
     except:
         return 
     if response.get("command",None)=="update":
         print u"Nueva version disponible (Actual: %s,Nueva: %s)"%(version,response["new_version"])
         file_url=common.URL+response["file_url"]
         response = urllib2.urlopen(file_url)
         _file = StringIO(response.read())
         if zipfile.is_zipfile(_file):
             
             
             zfl=zipfile.ZipFile(_file)
             members=zfl.namelist()[:]
             root_path=None
             for n in members[:]:
                 if os.path.basename(n)=="cncid":
                     members.remove(n)
                 elif os.path.basename(n)=="main.py":
                     if not root_path:
                         root_path=os.path.dirname(n)
             if root_path is not None:
                 for n in members[:]:
                     if not n.startswith(root_path):
                         members.remove(n)
             for m in members:       
                 source = zfl.open(m)
                 file_target=os.path.join(common.get_current_path(),os.path.relpath(m, root_path))
                 if os.path.basename(m)=="": #es directorio
                     if not os.path.exists(file_target):
                         os.makedirs(file_target)
                 else: #es archivo
                     target = file(file_target, "wb")
                     with source, target:
                         shutil.copyfileobj(source, target)  
             print u"Reiniciando script..."
             common.restart_please()
     else:
         print u"Versión más reciente (%s)"%version
Exemple #3
0
#
# Find us at: http://www.spkautomatizacion.com


import logging
import spkwifi
import common
import os.path
import time

print "Iniciando"

spkwifi.check_interfaces_file()
common.load_id()

logging.basicConfig(filename=os.path.join(common.get_current_path(),'errors.log'), level=logging.DEBUG, 
                    format='%(asctime)s %(levelname)s %(name)s %(message)s')
logger=logging.getLogger(__name__)
try:
    common.start_threads()

    while common.internet_thread.isAlive(): 
        #time.sleep(1)
        #pass
        common.internet_thread.join(1)  
        
except (KeyboardInterrupt, SystemExit):
    pass
except Exception as e:
    print e
    logger.error(e)