How to use update_folder method in lisa

Best Python code snippet using lisa_python

zupdate.py

Source:zupdate.py Github

copy

Full Screen

1#!/usr/bin/python2# -*- coding: utf-8 -*-3import zipfile4import shutil5import os6import urllib27import sys8from zred import decode9from os.path import exists10#https://drive.google.com/uc?export=download&confirm=no_antivirus&id=XXXXXXXXX11#https://drive.google.com/file/d/0ByJYMxvQwmxFNkpRa19hU3RZWWc/view?usp=sharing12def status(count, data_size, total_data):13 """Llamado por cada bloque de datos recibido"""14 print count, data_size, total_data15def descargarVersion2(config,version="0ByJYMxvQwmxFNkpRa19hU3RZWWc",dom="http://zerpatechnology.com.ve/"):16 from urllib import urlretrieve, urlcleanup17 url = ("https://drive.google.com/uc?export=download&confirm=no_antivirus&id="+version)18 # Nombre del archivo a partir del URL19 filename = url[url.rfind("/") + 1:]20 while not filename:21 filename = raw_input("No se ha podido obtener el nombre del "22 "archivo.\nEspecifique uno: ")23 24 print "Descargando %s..." % filename25 26 urlretrieve(url, filename, status) # Descargar archivo27 urlcleanup() # Limpiar cache28 29 print "%s descargado correctamente." % filename30def checkSize(version="0ByJYMxvQwmxFNkpRa19hU3RZWWc",dom="https://drive.google.com/"):31 import urllib32 site=urllib.urlopen(dom+"uc?export=download&confirm=bKUz&id="+version)33 meta=site.info()34 return meta.getheaders("Content-Length")[0]35def descargarVersion(config,version="0ByJYMxvQwmxFNkpRa19hU3RZWWc",dom="https://drive.google.com/"):36 try:37 #doc_url=dom+"update/"+version+".zip"38 doc_url=dom+"uc?export=download&confirm=bKUz&id="+version39 u = urllib2.urlopen(doc_url)40 #print u.headers41 42 localFile = open( "../"+config.update_folder+version+".zip" , 'w')43 44 localFile.write(u.read())45 localFile.close()46 return doc_url47 except Exception,e:48 print e49 return None50def backup(archivo,path):51 archivos=[]52 archivo=archivo.replace("/","")53 for elem in os.listdir(path):54 55 if (archivo[:archivo.rfind(".")]== elem[:elem.rfind(".")] or archivo[:archivo.rfind(".")]+"_backup" in elem[:elem.rfind(".")]) and elem[elem.rfind("."):]==archivo[archivo.rfind("."):]:56 archivos+=[elem]57 58 if archivo in archivos:59 archivos.remove(archivo)60 if "." in archivo:61 return archivo[:archivo.rfind(".")]+"_backup"+str(len(archivos))+archivo[archivo.rfind("."):]62 else:63 return archivo+"_backup"+str(len(archivos))64 65def lastbackup(archivo,path):66 archivos=[]67 archivo=archivo.replace("/","")68 for elem in os.listdir(path):69 70 if "." in archivo:71 if (archivo[:archivo.rfind(".")]== elem[:elem.rfind(".")] or archivo[:archivo.rfind(".")]+"_backup" in elem[:elem.rfind(".")]) and elem[elem.rfind("."):]==archivo[archivo.rfind("."):]:72 archivos+=[elem]73 else:74 if archivo==elem or archivo+"_backup" in elem:75 archivos+=[elem] 76 77 if len(archivos)>1:78 79 80 return archivo[:archivo.rfind(".")]+"_backup"+str(len(archivos)-2)+archivo[archivo.rfind("."):]81 else:82 return None83 84def actualizar(config,settings,version="update"):85 86 zf=zipfile.ZipFile("../"+config.update_folder+version+".zip", "r")87 88 carpetas=[]89 import chardet90 91 #zipfile.ZipInfo._decodeFilename = lambda self: self.filename92 #zf.extractall("../"+config.update_folder)93 for m in zf.infolist():94 data = zf.read(m) # extract zipped data into memory95 # convert unicode file path to utf896 disk_file_name = m.filename.encode('utf8')97 dir_name = os.path.dirname("../"+config.update_folder+disk_file_name)98 99 try:100 if dir_name[len("../"+config.update_folder):].split("/")[0] not in carpetas:101 carpetas.append(dir_name[len("../"+config.update_folder):].split("/")[0])102 os.makedirs(dir_name)103 except OSError as e:104 105 if e.errno == os.errno.EEXIST:106 pass107 else:108 raise109 except Exception as e:110 pass111 try:112 with open("../"+config.update_folder+disk_file_name, 'wb') as fd:113 fd.write(data)114 except Exception as e:115 pass116 zf.close()117 118 for elem in carpetas:119 if elem =="apps":120 121 if elem!=config.apps_dir:122 os.rename("../"+config.update_folder+"apps",config.apps_dir)123 carpetas[carpetas.index("apps")]=config.apps_dir124 if os.listdir("../"+config.update_folder+config.apps_folder)[0]!=config.apps_folder+settings.app:125 os.rename("../"+config.update_folder+config.apps_folder+os.listdir("../"+config.update_folder+config.apps_folder)[0],"../"+config.update_folder+config.apps_folder+settings.app)126 for folder, subfolders, files in os.walk("../"+config.update_folder+elem):127 128 for file in files:129 archivo=os.path.join(folder,file)130 if exists(archivo):131 132 mibackup=backup(archivo[archivo.rfind("/"):],archivo[:archivo.rfind("/")])133 if archivo.endswith(".py") or archivo.endswith(".php") or archivo.endswith(".rb") or archivo.endswith(".perl"):134 os.rename("../"+archivo[len("../update/"):],"../"+archivo[len("../update/"):archivo.rfind("/")]+"/"+mibackup)135 else:136 137 ultbackup=lastbackup(archivo[archivo.rfind("/"):],"../"+archivo[len("../update/"):archivo.rfind("/")]) 138 139 if ultbackup:140 141 if exists(archivo[:archivo.rfind("/")]+"/"+ultbackup):142 143 os.remove(archivo[:archivo.rfind("/")]+"/"+ultbackup)144 145 146 mibackup=backup(archivo[archivo.rfind("/"):],"../"+archivo[len("../update/"):archivo.rfind("/")])147 148 os.rename("../"+archivo[len("../update/"):],"../"+archivo[len("../update/"):archivo.rfind("/")]+"/"+mibackup)149 150 else:151 152 153 os.rename("../"+archivo[len("../update/"):],"../"+archivo[len("../update/"):archivo.rfind("/")]+"/"+mibackup)154 155 shutil.move(archivo,"../"+archivo[len("../update/"):archivo.rfind("/")])156 157 else:158 shutil.move(archivo,"../"+archivo[len("update/"):archivo.rfind("/")])159 160def crearVersion(config,settings,routes,nombre="update"):161 f=zipfile.ZipFile(nombre+".zip","w")162 for filename in ["../"+config.apps_folder+settings.app+"/user/"+config.controller_folder+routes.http_dir,163 "../"+config.apps_folder+settings.app+"/user/"+config.controller_folder+routes.websocket_dir,164 "../"+config.apps_folder+settings.app+"/admin/"+routes.models_dir,165 "../"+config.apps_folder+settings.app+"/admin/"+routes.vistas_dir,166 "../"+config.apps_folder+settings.app+"/admin/"+routes.static_dir,167 "../"+config.static_dir,168 ]:169 for folder, subfolders, files in os.walk(filename):170 for file in files:171 f.write(os.path.join(folder, file), os.path.relpath(os.path.join(folder,file),os.getcwd()).replace("../",""), compress_type = zipfile.ZIP_DEFLATED)172 ...

Full Screen

Full Screen

download.py

Source:download.py Github

copy

Full Screen

1try:2 if p["app"]==settings.app and p["method"]=="ajax":3 import os4 5 if p["action"]=="download":6 from ztec import zupdate7 8 completo=False9 #def verificar()10 size=None11 sizefile=p["model"]["global"].obtenerContenido("0ByJYMxvQwmxFNkpRa19hU3RZWWc","Asenzor")["0ByJYMxvQwmxFNkpRa19hU3RZWWc"]["size"]["value"]12 if len(normalizar(p["args"]))==2:13 if normalizar(p["args"])[1]+".zip" in os.listdir("../"+config.update_folder):14 (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)=os.stat("../"+config.update_folder+normalizar(p["args"])[1]+".zip")15 if (size!=None or size<sizefile):16 dom=zupdate.descargarVersion(config,normalizar(p["args"])[1])17 else:18 dom=zupdate.descargarVersion(config,normalizar(p["args"])[1])19 20 HEADERS.show()21 print "|","Descarga en curso..."22 elif len(normalizar(p["args"]))==1:23 if normalizar(p["args"])[0]+".zip" in os.listdir("../"+config.update_folder):24 (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)=os.stat("../"+config.update_folder+normalizar(p["args"])[0]+".zip")25 if (size!=None or size<sizefile):26 dom=zupdate.descargarVersion(config,normalizar(p["args"])[0])27 else:28 dom=zupdate.descargarVersion(config,normalizar(p["args"])[0])29 HEADERS.show()30 print "|","Descarga en curso..."31 32 elif p["action"]=="check": 33 HEADERS.show()34 sizefile=135 size=None36 sizefile=p["model"]["global"].obtenerContenido("0ByJYMxvQwmxFNkpRa19hU3RZWWc","Asenzor")["0ByJYMxvQwmxFNkpRa19hU3RZWWc"]["size"]["value"]37 if normalizar(p["args"])[0]+".zip" in os.listdir("../"+config.update_folder):38 (mode, ino, dev, nlink, uid, gid, size, atime, mtime, ctime)=os.stat("../"+config.update_folder+normalizar(p["args"])[0]+".zip")39 if size>=sizefile:40 print "@"+"Descarga exitosa. Presiona <a href='"+zred.urlBuilder(config,p["app"],"admin","index","Actualizar",normalizar(p["args"])[0],action="install")+"'>aquí</a> para instalar la nueva version"41 else:42 print "#","Descargando...",(size*100)/sizefile,"%"43 else:44 print "$","Su descarga iniciara en breve"45 46except Exception,e: 47 HEADERS.show()48 print p["action"]...

Full Screen

Full Screen

updater.py

Source:updater.py Github

copy

Full Screen

1#im gleichen verzeichnis muss die updater.json liegen um2#regelmaesige updates zu ermoeglichen3import os4import git5import sys6import requests7from colorama import init, Fore, Style8path = '/home/pi/roos'9def main():10 print('checking for updates...')11 need_to_update = len(sys.argv) <= 112 if not need_to_update :13 need_to_update = (sys.argv[1] == '-force' or sys.argv[1] == '-f')14 else:15 need_to_update = check_version()16 if need_to_update == 2:17 print('no network')18 if need_to_update == 1:19 print('update...')20 update()21 else:22 print('up to date')23 #wait 24hours24def check_version():25 path_of_updates = path + '/updates/'26 lastest_version = '0'27 for file in os.listdir(path_of_updates):28 version = file.replace('update', '')29 if version > lastest_version:30 lastest_version = version31 #send https request an license.enwatmon.de fuer version vergleich32 url = 'https://license.enwatmon.de/RPIROversion'33 myobj = {'version': (lastest_version)}34 x = {}35 try:36 x = requests.post(url, data = myobj)37 except Exception as e:38 print(e)39 if not x:40 return 241 print(x.text)42 return x.text == 'new version available'43def update():44 #git pull muss config auslassen bzw in gitignore schreiben45 print(path)46 g = git.cmd.Git(path + '/')47 g.stash()48 g.pull()49 lastest_version = ''50 for file in os.listdir(path + '/updates'):51 version = file.replace('update', '')52 if version > lastest_version:53 lastest_version = version54 global update_folder55 update_folder = path + '/updates/' + file56 if not update_folder or update_folder == '':57 print('no updates available')58 return59 print(update_folder + '/update.sh')60 f = open(update_folder + '/update.sh')61 orders = f.readlines()62 for order in orders:63 print('\n' + order)64 print(Fore.WHITE + 'Order executing...')65 res = os.popen(order).read()66 print(res)67 print(Fore.GREEN + 'Order done\n')68 print('done')69if __name__ == '__main__':...

Full Screen

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run lisa automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful