def Main(): cmdparser = init_argparse() try: args = cmdparser.parse_args() except IOError as msg: args.error(str(msg)) filename = args.inputfile if not file_accessible(filename, "rb"): print(_("Error: El archivo {0} no se ha encontrado o no es accesible para lectura").format(filename)) sys.exit(-1) if not args.outputpath: outputfile = "export" else: outputfile = args.outputpath # if not Utils.file_accessible(outputfile, "wb"): # print(_("Error: El archivo {0} no es accesible para escritura").format(outputfile)) # sys.exit(-1) tablestr = process_file(args.configfile, filename, outputfile, args.compressiontype, args.complevel, args.ciphertype, args.testall, args.append, args.pagesingroups) print("") print(tablestr) print("")
kwargs.update(val) cmdparser.add_argument(*args, **kwargs) return cmdparser if __name__ == "__main__": cmdparser = init_argparse() try: args = cmdparser.parse_args() except IOError as msg: args.error(str(msg)) filename = args.inputfile if not file_accessible(filename, "rb"): print( _("Error: El archivo {0} no se ha encontrado o no es accesible para lectura" ).format(filename)) sys.exit(-1) if not args.configfile: print( _("Error: Debe definir el archivo de configuración del proceso"). format(args.configfile)) sys.exit(-1) if not file_accessible(args.configfile, "r"): print( _("Error: El archivo de configuración del proceso {0} no se ha encontrado o no es accesible para su lectura" ).format(args.configfile))
cmdparser.add_argument('inputfile' , type=str, action="store" , help="Archivo Excel de entrada") cmdparser.add_argument('-v', '--version' , action='version', version=__version__ , help='Mostrar el número de versión y salir') return cmdparser if __name__ == "__main__": cmdparser = init_argparse() try: args = cmdparser.parse_args() except IOError as msg: args.error(str(msg)) test_file = args.inputfile if not file_accessible(test_file, "rb"): print("Error: El archivo {0} no se ha encontrado o no es accesible para lectura".format(test_file)) sys.exit(-1) if test_file: size_test_file = os.path.getsize(test_file) resultados = [] totales = {} bloques = 0 paginas = 0 start = time.time() b = Block() pg = PageContainer() with OermDataBase(test_file) as bloques:
kwargs.update(val) cmdparser.add_argument(*args, **kwargs) return cmdparser if __name__ == "__main__": cmdparser = init_argparse() try: args = cmdparser.parse_args() except IOError as msg: args.error(str(msg)) filename = args.inputfile if not file_accessible(filename, "rb"): print( _("Error: El archivo {0} no se ha encontrado o no es accesible para lectura" ).format(filename)) sys.exit(-1) d = Database(filename, mode="rb") # Listar reportes en la base oerm if args.listreports or (not args.showpages and not args.searchtext): reports_list = [] for report in d.reports(): reports_list.append((report.id, report.nombre, report.total_pages)) if reports_list: print("")
def add_repo(self, catalog_id, path, update=False): """Procesa el path de un repositorio de datbases Oerm y genera el repo.db (sqlite). Basicamente cataloga cada database y genera una base sqlite (repo.db) en el directorio root del repositorio. Args: catalog_id (string): Id del catálogo al cual se le agregará este repositorio path (string): Carpeta principal del repositorio update (bool): (Opcional) Se actualiza o regenera completamente el catalogo Ejemplo: >>> from openerm.OermClient import OermClient >>> c = OermClient("samples/openermcfg.yaml") >>> c.add_repo("catalogo1", "/var/repo1") """ dbname = os.path.join(path, 'repo.db') if file_accessible(dbname, "r"): os.remove(dbname) conn = sqlite3.connect(dbname) # conn.text_factory = lambda x: repr(x) c = conn.cursor() c.execute("CREATE TABLE databases (database_id int, path text)") c.execute( "CREATE TABLE date (date_id INTEGER PRIMARY KEY ASC, date text)") c.execute( "CREATE TABLE system (system_id INTEGER PRIMARY KEY ASC, system_name text)" ) c.execute( "CREATE TABLE department (department_id INTEGER PRIMARY KEY ASC, department_name text)" ) c.execute( "CREATE TABLE report (report_id INTEGER PRIMARY KEY ASC, report_name text)" ) c.execute( "CREATE TABLE reports (database_id int, report_id int, date_id int, system_id, department_id int, pages int)" ) # c.execute("CREATE TABLE reports (database_id int, report_id text, report_name text, aplicacion text, fecha text, sistema text, departamento text, pages int)") databases = [] reports_list = [] reportid = AutoNum() dateid = AutoNum() systemid = AutoNum() deptid = AutoNum() for i, f in enumerate(filesInPath(path, "*.oerm"), 1): databases.append((i, f)) d = Database(os.path.join(path, f), mode="rb") for report in d.reports(): # print("{0}: {1}".format(report.nombre, reportid.get(report.nombre))) elemento = (i, reportid.get(report.nombre), dateid.get(report.fecha), systemid.get(report.sistema), deptid.get(report.departamento), report.total_pages) reports_list.append(elemento) c.executemany("INSERT INTO date (date, date_id) VALUES (?,?)", dateid.list()) c.executemany( "INSERT INTO system (system_name, system_id) VALUES (?,?)", systemid.list()) c.executemany( "INSERT INTO department (department_name, department_id) VALUES (?,?)", deptid.list()) c.executemany( "INSERT INTO report (report_name, report_id) VALUES (?,?)", reportid.list()) c.executemany("INSERT INTO databases (database_id, path) VALUES (?,?)", databases) c.executemany( "INSERT INTO reports (database_id, report_id, date_id, system_id, department_id, pages) VALUES (?,?,?,?,?,?)", reports_list) conn.commit() conn.close() d = self.config["catalogs"].get(catalog_id) if "urls" not in d: d["urls"] = [path] else: d["urls"].append(path) self._flush()
def procces_tree(path, update=False): """Procesa el path de un repositorio de datbases Oerm Args: path (string): Carpeta principal del repositorio update (bool): (Opcional) Se actualiza o regenera completamente el catalogo """ dbname = os.path.join(path, 'catalog.db') if file_accessible(dbname, "r"): os.remove(dbname) conn = sqlite3.connect(dbname) # conn.text_factory = lambda x: repr(x) c = conn.cursor() c.execute("CREATE TABLE databases (database_id int, path text, size int)") c.execute( "CREATE TABLE date (date_id INTEGER PRIMARY KEY ASC, date text)") c.execute( "CREATE TABLE system (system_id INTEGER PRIMARY KEY ASC, system_name text)" ) c.execute( "CREATE TABLE department (department_id INTEGER PRIMARY KEY ASC, department_name text)" ) c.execute( "CREATE TABLE report (report_id INTEGER PRIMARY KEY ASC, report_name text)" ) c.execute( "CREATE TABLE reports (database_id int, report_id int, date_id int, system_id, department_id int, pages int)" ) # c.execute("CREATE TABLE reports (database_id int, report_id text, report_name text, aplicacion text, fecha text, sistema text, departamento text, pages int)") databases = [] reports_list = [] reportid = AutoNum() dateid = AutoNum() systemid = AutoNum() deptid = AutoNum() for i, f in enumerate(filesInPath(path, "*.oerm"), 1): fname = os.path.join(path, f) databases.append((i, f, os.stat(fname).st_size)) d = Database(fname, mode="rb") for report in d.reports(): print("{0}: {1}".format(report.nombre, reportid.get(report.nombre))) elemento = (i, reportid.get(report.nombre), dateid.get(report.fecha), systemid.get(report.sistema), deptid.get(report.departamento), report.total_pages) reports_list.append(elemento) c.executemany("INSERT INTO date (date, date_id) VALUES (?,?)", dateid.list()) c.executemany("INSERT INTO system (system_name, system_id) VALUES (?,?)", systemid.list()) c.executemany( "INSERT INTO department (department_name, department_id) VALUES (?,?)", deptid.list()) c.executemany("INSERT INTO report (report_name, report_id) VALUES (?,?)", reportid.list()) c.executemany( "INSERT INTO databases (database_id, path, size) VALUES (?,?,?)", databases) c.executemany( "INSERT INTO reports (database_id, report_id, date_id, system_id, department_id, pages) VALUES (?,?,?,?,?,?)", reports_list) conn.commit() conn.close()