Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # !/usr/bin/python
- import binascii
- import os
- import zipfile
- import subprocess
- import psycopg2
- from psycopg2.extensions import ISOLATION_LEVEL_AUTOCOMMIT
- import io
- try:
- from Tkinter import *
- except ImportError:
- from tkinter import *
- try:
- import ttk
- py3 = 0
- except ImportError:
- import tkinter.ttk as ttk
- py3 = 1
- choosefile = r'%SystemDrive%\\Suport Linx'
- tmppath = "C:\\Users\\{}\\AppData\\Local\\Temp\\".format(os.getlogin())
- def unzip(file):
- with zipfile.ZipFile(file, "r") as zipped_file:
- zipped_file.extractall(tmppath)
- def install(db, pw, host, port, file):
- try:
- conn = psycopg2.connect(user='postgres', database='postgres', password=pw, host=host, port=port)
- conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
- cur = conn.cursor()
- print('Iniciando instalação do banco de dados')
- try:
- cur.execute('create user distro')
- print('Usuario distro criado')
- except Exception as e:
- print(e)
- try:
- cur.execute('create user autosystem')
- print('Usuario autosystem criado')
- except Exception as e:
- print(e)
- try:
- cur.execute(f'CREATE DATABASE {db} ENCODING "SQL_ASCII" TEMPLATE template0')
- print(f'Banco de dados {db} criado')
- except Exception as e:
- print(e)
- unzip(file)
- try:
- print('Iniciando carregamento ...')
- log = 'error.log'
- #filename = 'sqlquery'
- filename = tmppath + "load3.2.3.127-30052017.sql"
- '''command = f'cmd.exe set PGPASSWORD={pw}'
- subprocess.Popen(command, stdin=subprocess.PIPE, stdout=log)
- sqlrun = f'psql.exe -h {host} -p {port} -f {filename}{db} postgres'
- subprocess.Popen(sqlrun, stdin=subprocess.PIPE, stdout=log)'''
- file = open(filename, 'r')
- fileconv = binascii.a2b_uu(file)
- reader = io.BufferedReader(io.BytesIO(fileconv.encode("utf-8")))
- sql = s = " ".join(file.readlines())
- try:
- conn = psycopg2.connect(user='postgres', database=db, password=pw, host=host, port=port)
- conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
- #conn.set_client_encoding('iso8859_15')
- cur = conn.cursor()
- try:
- decoded = sql
- sqlfinal = decoded.encode('iso8859_15', 'replace')
- cur.execute(reader)
- except Exception as msg:
- print(msg)
- except Exception as e:
- print(e)
- print('LoadDB carregado com sucesso !')
- except Exception as e:
- print(e)
- except Exception as e:
- print(e)
- print('Verifique os parametros informados e tente novamente.')
- def change_pass_distro(pw, host, port):
- try:
- conn = psycopg2.connect(user='postgres', database='postgres', password=pw, host=host, port=port)
- conn.set_isolation_level(ISOLATION_LEVEL_AUTOCOMMIT)
- cur = conn.cursor()
- try:
- cur.execute(f"alter user distro with password '{pw}'")
- print('Senha usuário distro alterada')
- except Exception as e:
- print(e)
- except Exception as e:
- print(e)
- print('Verifique os parametros informados e tente novamente.')
- def init(top, gui, *args, **kwargs):
- global w, top_level, root
- w = gui
- top_level = top
- root = top
- def destroy_window():
- # Function which closes the window.
- global top_level
- top_level.destroy()
- top_level = None
- if __name__ == '__main__':
- import gui
- gui.vp_start_gui()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement