def base_datos(): import StringIO import os right_version = right_firefox_version(request.env.http_user_agent) if not "archivos" in session.keys(): session.archivos = [] form = SQLFORM.factory(submit_button='Enviar') if form.accepts(request.vars, session): response.flash = 'Procesando datos, espere' #borrando = form.vars.principiocurso if len(session.archivos) > 0: import pdb lista_completa = [] #SQLite=SQLiteConnection() #SQLite.define_tables() #dbcontrolies = SQLite.getDB() #result = db.executesql(sql) for archivo in session.archivos: f = open(archivo) linea = f.readline() last_id = "" while linea: if linea != '\n' and linea != '': linea = linea.split(",") # Datos del portatil serial_number = linea[1].replace("'", "") id_trademark = linea[2] laptop = Laptops(cdb, "", serial_number, id_trademark) if not laptop.existsSerialNumber(laptop.serial_number): laptop.add() last_id = laptop.getIdbySerialNumber( laptop.serial_number) if last_id: # Datos del registro historico id_laptop = last_id username = linea[9].replace("'", "") name = linea[10].replace("'", "") id_user_type = linea[6] nif = linea[5].replace("'", "") id_state = linea[8] laptopshistory = LaptopsHistory( cdb, "", id_laptop, id_state, id_user_type, nif, username, name, "") laptopshistory.add() #dbcontrolies.laptops_historical.insert (**attributes) linea = f.readline() response.flash = T('Ficheros importados correctamente') session.archivos = [] return dict(form=form, right_version=right_version)
def base_datos(): import StringIO import os right_version=right_firefox_version(request.env.http_user_agent) if not "archivos" in session.keys(): session.archivos=[] form=SQLFORM.factory(submit_button='Enviar') if form.accepts(request.vars, session): response.flash = 'Procesando datos, espere' #borrando = form.vars.principiocurso if len(session.archivos)>0: import pdb lista_completa=[] #SQLite=SQLiteConnection() #SQLite.define_tables() #dbcontrolies = SQLite.getDB() #result = db.executesql(sql) for archivo in session.archivos: f = open(archivo) linea = f.readline() last_id = "" while linea: if linea!= '\n' and linea != '': linea = linea.split(",") # Datos del portatil serial_number = linea[1].replace("'","") id_trademark = linea[2] laptop = Laptops (cdb,"",serial_number, id_trademark) if not laptop.existsSerialNumber (laptop.serial_number): laptop.add () last_id = laptop.getIdbySerialNumber (laptop.serial_number) if last_id: # Datos del registro historico id_laptop = last_id username = linea [9].replace("'","") name = linea [10].replace("'","") id_user_type = linea [6] nif = linea [5].replace("'","") id_state = linea [8] laptopshistory = LaptopsHistory (cdb, "", id_laptop, id_state, id_user_type, nif, username, name, "") laptopshistory.add () #dbcontrolies.laptops_historical.insert (**attributes) linea = f.readline() response.flash = T('Ficheros importados correctamente') session.archivos=[] return dict(form=form,right_version=right_version)
def databaseDumpExec(): try: if request.vars['massive_desasignation']=="ok": # Get all students asigned laptops sql="SELECT id_laptop FROM laptops_historical lh" sql=sql+" WHERE lh.id_state=2 AND lh.id_user_type=2" sql=sql+" AND lh.id_historical IN (SELECT MAX(lh2.id_historical) FROM laptops_historical lh2 WHERE lh2.id_laptop=lh.id_laptop)" sql=sql+" GROUP BY id_laptop" sql=sql+" ORDER BY id_laptop" result = cdb.executesql(sql) for r in result: lh = LaptopsHistory(cdb,"",r[0],1,"","","","","Desasignación masiva ControlIES","") lh.add() except: pass l=conecta() t = Thinclients(l) result = t.getAllComputers() for c in result["computers"]: computer_name = c["cn"].strip() serial = c["serial"].replace("serial-number","").strip() username = c["username"].replace("user-name","").strip() mac = c["mac"].replace("ethernet","").strip() macWlan = c["macWlan"].replace("ethernet","").strip() if serial!="": id_laptop = Laptops(cdb,"","","","","","","","").existsSerialNumber(serial) if id_laptop: addHistory(l,username,id_laptop,computer_name) lap = Laptops(cdb,id_laptop,"","","","","","","") laptop = lap.getLaptopData() if laptop["mac_eth0"]!=mac or laptop["mac_wlan0"]!=macWlan: lap.updateMAC(mac,macWlan) else: # Si no existe el portatil try: if request.vars['add_laptop']=="ok": lap = Laptops(cdb,"", serial, "", "", "", "", mac, macWlan) lap.add() addHistory(l,username,lap.getIdLaptop(),computer_name) except: pass l.close() return dict(response = "OK")