Example #1
0
def get_wrapper_path(scripts_directory: Path):
    """
    This function is either run from the "python\Scripts" directory or from the
    original source directory. In the case of the original directory, we
    want to copy over all the necessary resources to overwrite the default
    python exe wrappers.
    
    The function returns the paths of the resources located in "python\Scripts"
    """

    py_wrap_origin = locate.this_dir().joinpath("..", "resources",
                                                "python-exe-wrappers",
                                                "python-exe-wrapper.exe")
    pyw_wrap_origin = locate.this_dir().joinpath("..", "resources",
                                                 "python-exe-wrappers",
                                                 "pythonw-exe-wrapper.exe")
    pip_wrap_origin = locate.this_dir().joinpath("..", "resources",
                                                 "batch-exe-wrappers",
                                                 "launcher.exe")

    py_wrap = scripts_directory.joinpath("(python-exe-wrapper.exe)")
    pyw_wrap = scripts_directory.joinpath("(pythonw-exe-wrapper.exe)")
    pip_wrap = scripts_directory.joinpath("(pip-exe-wrapper.exe)")

    if pyw_wrap_origin.exists() and py_wrap_origin.exists():
        shutil.copy2(py_wrap_origin, py_wrap)
        shutil.copy2(pyw_wrap_origin, pyw_wrap)
        shutil.copy2(pip_wrap_origin, pip_wrap)
        shutil.copy2(__file__,
                     scripts_directory.joinpath("fix-pip-python-binaries.py"))

    return py_wrap, pyw_wrap, pip_wrap
Example #2
0
def hellosub():
    wb = xw.Book.caller()

    txt = wb.sheets[0].range('A1').value
    fout = locate.this_dir().joinpath("hello.txt")
    with fout.open("w") as fw:
        fw.write(txt)
Example #3
0
 def test_this_dir(self):
     self.assertEqual(locate.this_dir().name, "tests")
     self.assertEqual(locate.this_dir(),
                      Path(os.path.abspath(__file__)).parent)
Example #4
0
import wmi  #Importando biblioteca que conecta no windows.
from locate import this_dir  #Biblioteca que pega o diretório onde está executando o .py ou no caso o executável

#Caminho dos arquivos
caminho_raiz = (this_dir())
caminho_servidores = str(caminho_raiz) + '\\Servidores.ini'
comando_senha = str(caminho_raiz) + '\\Comando.ini'

#Definindo usuários e senhas
usuario_remoto = "xxxx"
senha_remoto = "yyyy"

#Abaixo estou definindo o arquivo para ler onde fica o nome dos servidores
with open(caminho_servidores, "r") as arquivo:
    #Na variável Servidores fica os dados do arquivo Servidores.ini, vai ler linha a linha no caso o nome do servidor.
    Servidores = arquivo.readlines()

for servidor in Servidores:
    #Cortando o enter do arquivo Servidores.ini
    servidor = servidor.rstrip('\n')

    #Caso queira testar posso conectar na máquina local no comando abaixo
    #localhost = wmi.WMI()

    #Conectando máquina remota
    conectar_remoto = wmi.WMI(servidor,
                              user=usuario_remoto,
                              password=senha_remoto)

    #Construção do Comando para criar arquivo do powershell "reset.ps1" com comando para resetar a senha do Active Directory(AD).
    comando = "powershell /c ECHO \'DSQUERY user \"\"\"\"\"cn=infra_guilherme,ou=Validacao, ou=GTM-BR-PeaPOD-QA-USERS,ou=XenApp,ou=Gtm,ou=Business Products,dc=LHTRQA,dc=loc\"\"\"\"\" -limit 0 | DSMOD user -pwd Welcome@30\' > D:\Guilherme\Resultado\\reset.ps1"
Example #5
0
    else:
        # New book, not connected to any file.
        book = app.books[0]

    try:
        yield book
    finally:
        if save:
            book.save()
        if close:
            book.close()
        if kill:
            app_pid = app.pid
            app.kill()


szipbin = locate.this_dir().parent.joinpath("bin", "7z.exe")
fiboutput = Path(tempfile.mktemp())
fibzip = locate.this_dir().parent.joinpath("resources", "fibonacci.zip")

subprocess.check_output([
    str(szipbin), 'x',
    str(fibzip), '-pabc123', f'-o{fiboutput}', '-aoa', '-y'
])

excel(path=fiboutput.joinpath("fibonacci.xlsm"),
      save=True,
      quiet=True,
      kill=True)

shutil.rmtree(fiboutput, ignore_errors=True)