Esempio n. 1
def get_ssh():
    global _ssh
    if not _ssh:
        _ssh = paramiko.SSHClient()
    return _ssh
Esempio n. 2
def sqlquery(query, file):
    '''Run the query over the read-replica DB. Store the results in a file

    Known issues: 
    * The query is passed over a Unix commandline in single quotes. We
      should clean this up, but for now, don't use single quotes.
    * This code is *intentionally* *not* *secure*. It presumes you
    have ssh access to the replica. It should *not* be co-opted for
    secure applications.

    ssh = get_ssh()
    command = "echo '{query}' | {replica}".format(query=query, replica=setting('replica-sql'))
    ssh_stdin, ssh_stdout, ssh_stderr = ssh.exec_command(command)
    with open(file, "w") as f:
        for x in ssh_stdout:
Esempio n. 3
def populate_tables():
    for query in queries:
        sqlquery(queries[query], os.path.join(setting("userinfo"), query+".csv"))