예제 #1
0
#    in all copies or substantial portions of the Software.

# -- config --
# description: Retrieve a list of roles.
# http_method: get
# lock: False
# tags: Postgres, Psql
# -- end config --

from os import linesep
from extension import CmdRun, ToolKit, Constants

# Spawn Instances
run = CmdRun()  # <class> Run
toolkit = ToolKit()  # <class> Misc. functions

# ******************
# *  SQL SENTENCE  *
# ******************
sql = ("\du")
sql_code = toolkit.write_temp(sql)

# ****************
# *  SQL RUNNER  *
# ****************
output = run.sql(sql_code)
print(output)
print("{status}=ok".format(status=Constants.API_SUMMARY_STRING))

toolkit.exit(0)
# *  SQL SENTENCE  *
# ******************
sql = ("SELECT"
       "    pid,"
       "    current_timestamp - xact_start as xact_runtime,"
       "    query"
       " FROM pg_stat_activity WHERE query NOT LIKE '%pg_stat_activity%' "
       " ORDER BY xact_start;"
       )
sql_code = toolkit.write_temp(sql)


# ****************
# *  SQL RUNNER  *
# ****************
query_result = run.sql(sql_code)


# **********************
# *  OUTPUT PROCESSOR  *
# **********************
print(query_result)
exitcode = 0  # We good
error_scenario_1 = False
error_scenario_2 = False
error_scenario_3 = False

for line in query_result.split(linesep):
    if ("psql:/tmp/" in line) and (" ERROR:  " in line):
        toolkit.print_stderr(line)
        error_scenario_1 = True