Ejemplo n.º 1
0
    def create_user(self):
        self.screen_manager.display_mid('Please enter your desired Username: '******'Please enter your desired Password: '******'%s\'" % self.username
        rows = query.query(to_query, 'postgres', self.screen)

        if rows[1]:
            ScreenManager.throw(self.screen, 'Username already in use.')
            return LoginScreen.create_user(self)
        else:
            to_query = "CREATE USER %s WITH CREATEDB PASSWORD \'%s\'" % (
                self.username, self.password)
            if query.query(to_query, 'postgres', self.screen) == -1:
                ScreenManager.throw(self.screen,
                                    "An error prevented user creation.")
                return False
            to_query = "CREATE DATABASE %s_default" % (self.username)
            if query.query(to_query, 'postgres', self.screen, 0) == -1:
                ScreenManager.throw(
                    self.screen,
                    "An error occured during user default database creation.")
                return False
            to_query = "ALTER DATABASE %s_default owner to %s" % (
                self.username, self.username)
            if query.query(to_query, 'postgres', self.screen) == -1:
                ScreenManager.throw(
                    self.screen,
                    "An error occured while assigning new user to default database."
                )
                return False

            return True
Ejemplo n.º 2
0
    def create_user(self):
        self.screen_manager.display_mid('Please enter your desired Username: '******'Please enter your desired Password: '******'%s\'" % self.username
        rows = query.query(to_query, 'postgres', self.screen)
        
        if rows[1]:
            ScreenManager.throw(self.screen, 'Username already in use.')
            return LoginScreen.create_user(self)
        else:
            to_query = "CREATE USER %s WITH CREATEDB PASSWORD \'%s\'" % (self.username, self.password)
            if query.query(to_query, 'postgres', self.screen) == -1:
                ScreenManager.throw(self.screen, "An error prevented user creation.")
                return False
            to_query = "CREATE DATABASE %s_default" % (self.username)
            if query.query(to_query, 'postgres', self.screen, 0) == -1:
                ScreenManager.throw(self.screen, "An error occured during user default database creation.")
                return False
            to_query = "ALTER DATABASE %s_default owner to %s" % (self.username, self.username)
            if query.query(to_query, 'postgres', self.screen) == -1:
                ScreenManager.throw(self.screen, "An error occured while assigning new user to default database.")
                return False

            return True
Ejemplo n.º 3
0
 def save(self):
     self.screen.clear()
     queryDB.display_top_left(self, "Please enter a query save below:\n")
     curses.echo()
     string = self.screen.getstr()
     q = "INSERT INTO queries_saved (query) VALUES (%s)"
     query.query(q, 'queries', None, None, string)
     self.screen.clear()
Ejemplo n.º 4
0
 def save(self):
     self.screen.clear()
     queryDB.display_top_left(self, "Please enter a query save below:\n")
     curses.echo()
     string = self.screen.getstr()
     q = "INSERT INTO queries_saved (query) VALUES (%s)"
     query.query(q, 'queries', None, None, string)
     self.screen.clear()
Ejemplo n.º 5
0
 def create_database(self, name):
     to_query = "SELECT 1 FROM pg_database WHERE datname = \'%s\'" % (name)
     database_exists = query.query(to_query, 'postgres', self.screen, None, None, self.username, self.password)
     if database_exists[1]:
         ScreenManager.throw(self.screen, 'Database already exists.')
         return False
     else:
         db_creation_query = "CREATE DATABASE " + name 
         if query.query(db_creation_query, 'postgres', self.screen, 0, None, self.username, self.password) == -1:
             ScreenManager.throw(self.screen, "An error prevented database creation.")
             return False
         return True
Ejemplo n.º 6
0
 def run(self, string, currentDB):
     result = query.query(string, currentDB, self.screen)
     if result == -1:
         error.throw(self.screen, "The query did not succeed.")
         self.screen.clear()
     elif result == 0:
         error.throw(self.screen, "The query was succesful.")
         self.screen.clear()
         q = "INSERT INTO queries_history (query) VALUES (%s)"
         query.query(q, 'queries', None, None, string)
     else:
         self.screen.clear()
         tableDisplay.navigate(result, 0, 0, self.screen)
         self.screen.clear()
         q = "INSERT INTO queries_history (query) VALUES (%s)"
         query.query(q, 'queries', None, None, string)
Ejemplo n.º 7
0
 def showTable(self, options):
     table = options['table']
     db = options['db']
     display_query = "SELECT * from " + table
     rows = query.query(display_query, db, self.screen, None, None, self.username, self.password)
     tableDisplay.navigate(rows,0,0,self.screen)
     self.screen.clear()
Ejemplo n.º 8
0
 def run(self, string, currentDB):
     result = query.query(string, currentDB, self.screen)
     if result == -1:
         error.throw(self.screen, "The query did not succeed.")
         self.screen.clear()
     elif result == 0:
         error.throw(self.screen, "The query was succesful.")
         self.screen.clear()
         q = "INSERT INTO queries_history (query) VALUES (%s)"
         query.query(q, 'queries', None, None, string)
     else:
         self.screen.clear()
         tableDisplay.navigate(result, 0, 0, self.screen)
         self.screen.clear()
         q = "INSERT INTO queries_history (query) VALUES (%s)"
         query.query(q, 'queries', None, None, string)
Ejemplo n.º 9
0
 def showTable(self, options):
     table = options['table']
     db = options['db']
     display_query = "SELECT * from " + table
     rows = query.query(display_query, db, self.screen, None, None,
                        self.username, self.password)
     tableDisplay.navigate(rows, 0, 0, self.screen)
     self.screen.clear()
Ejemplo n.º 10
0
 def list_drop_tables(self, dbname):
     table_query = "SELECT table_name FROM information_schema.tables where table_schema = 'public'"
     rows = query.query(table_query, dbname, self.screen, None, None, self.username, self.password)
     parsed_table_menu = []
     for datas in rows[1]:
         opts = {'db':dbname,'table':str(datas[0])}
         lst = (str(datas[0]),self.drop_table, opts)
         parsed_table_menu.append(tuple(lst))
     headeropts = {'db':dbname,'title':"Select Table to Drop",'user':self.username}
     table_menu = Menu(parsed_table_menu,self.screen, headeropts)
     table_menu.display()
Ejemplo n.º 11
0
 def createTable(self, dbname):
     self.screen_manager.set_cursor_visible()
     curses.echo()
     self.screen_manager.display_mid("Please enter a name for the new table: ")
     new_table_name = self.screen_manager.screen.getstr()
     self.screen.clear()
     
     table_creation_query = "CREATE TABLE IF NOT EXISTS " + new_table_name + "(ID INT PRIMARY KEY      NOT NULL);" 
     if query.query(table_creation_query, dbname, self.screen, 0, None, self.username, self.password) == -1:
         ScreenManager.throw(self.screen, "An error prevented table creation.")
     else:
         self.screen_manager.display_mid("Table successfully created!")
         self.screen_manager.screen.getstr()
     self.screen.clear()
Ejemplo n.º 12
0
 def list_drop_tables(self, dbname):
     table_query = "SELECT table_name FROM information_schema.tables where table_schema = 'public'"
     rows = query.query(table_query, dbname, self.screen, None, None,
                        self.username, self.password)
     parsed_table_menu = []
     for datas in rows[1]:
         opts = {'db': dbname, 'table': str(datas[0])}
         lst = (str(datas[0]), self.drop_table, opts)
         parsed_table_menu.append(tuple(lst))
     headeropts = {
         'db': dbname,
         'title': "Select Table to Drop",
         'user': self.username
     }
     table_menu = Menu(parsed_table_menu, self.screen, headeropts)
     table_menu.display()
Ejemplo n.º 13
0
    def createTable(self, dbname):
        self.screen_manager.set_cursor_visible()
        curses.echo()
        self.screen_manager.display_mid(
            "Please enter a name for the new table: ")
        new_table_name = self.screen_manager.screen.getstr()
        self.screen.clear()

        table_creation_query = "CREATE TABLE IF NOT EXISTS " + new_table_name + "(ID INT PRIMARY KEY      NOT NULL);"
        if query.query(table_creation_query, dbname, self.screen, 0, None,
                       self.username, self.password) == -1:
            ScreenManager.throw(self.screen,
                                "An error prevented table creation.")
        else:
            self.screen_manager.display_mid("Table successfully created!")
            self.screen_manager.screen.getstr()
        self.screen.clear()
Ejemplo n.º 14
0
 def copy_database(self, database):
     db_name = database[0]
     
     self.screen_manager.set_cursor_visible()
     curses.echo()
     self.screen_manager.display_mid("Please enter a name for the new database: ")
     new_db_name = self.screen_manager.screen.getstr()
     self.screen.clear()
     
     db_copy_query = "CREATE DATABASE " + new_db_name + " WITH TEMPLATE " + db_name
     if query.query(db_copy_query, 'postgres', self.screen, 0, None, self.username, self.password) == -1:
         ScreenManager.throw(self.screen, "An error prevented database creation.")
     else:
         self.screen_manager.display_mid("The database " + new_db_name + " has been copied from " + db_name)
         self.screen.getstr()
     self.screen.clear()
     self.screen_manager.set_cursor_invisible()
Ejemplo n.º 15
0
 def drop_database(self, database):
     db_name = database[0]
     
     self.screen_manager.set_cursor_visible()
     curses.echo()
     self.screen_manager.display_mid("Are you sure you want to delete " + db_name + "? (Y/N): ")
     confirmation = self.screen_manager.screen.getstr()
     if confirmation == 'Y':
         db_delete_query = "DROP DATABASE " + db_name
         if query.query(db_delete_query, 'postgres', self.screen, 0, None, self.username, self.password) == -1:
             ScreenManager.throw(self.screen, "An error prevented database creation.")
         else:
             self.screen_manager.display_mid("The database " + db_name + " has been deleted")
             self.screen.getstr()
     else:
         self.screen_manager.display_mid(db_name + " will not be deleted")
         self.screen_manager.screen.getstr()
     self.screen.clear()
     self.screen_manager.set_cursor_invisible()            
Ejemplo n.º 16
0
    def login(self):
        self.screen_manager.display_mid('Please enter your Username: '******'Please enter your Password: '******'root\'"
        rows = query.query(to_query, 'postgres', None, None, None, self.username, self.password)
        
        if rows != -1 and rows != -2:
            return True
        elif rows == -1:
            ScreenManager.throw(self.screen, "Couldn't sign in. Please ensure your system is set up correctly.")
            return False
        else:
            ScreenManager.throw(self.screen, "Incorrect Username or Password.")
            return False
Ejemplo n.º 17
0
 def drop_table(self, options):
     table = options['table']
     db = options['db'] 
     self.screen_manager.display_mid("Are you sure you want to delete "+ table + "? (y/n)")
     confirmation = self.screen_manager.screen.getstr()
     if confirmation == 'y' or confirmation == "Y":
         tbl_delete_query = "DROP TABLE " + table + " CASCADE"
         if query.query(tbl_delete_query, db, self.screen, 0) == -1:
             self.screen_manager.display_mid("ERROR deleting table")
             self.screen.getch()
             self.screen.clear()
         else:
             self.screen_manager.display_mid("Table " + table + " deleted.")
             self.screen.getch()
             self.screen.clear()
     else:
         self.screen_manager.display_mid("Table " + table + " will not be deleted.")
         self.screen.getch()
         self.screen.clear()
     self.screen.clear()
Ejemplo n.º 18
0
 def drop_table(self, options):
     table = options['table']
     db = options['db']
     self.screen_manager.display_mid("Are you sure you want to delete " +
                                     table + "? (y/n)")
     confirmation = self.screen_manager.screen.getstr()
     if confirmation == 'y' or confirmation == "Y":
         tbl_delete_query = "DROP TABLE " + table + " CASCADE"
         if query.query(tbl_delete_query, db, self.screen, 0) == -1:
             self.screen_manager.display_mid("ERROR deleting table")
             self.screen.getch()
             self.screen.clear()
         else:
             self.screen_manager.display_mid("Table " + table + " deleted.")
             self.screen.getch()
             self.screen.clear()
     else:
         self.screen_manager.display_mid("Table " + table +
                                         " will not be deleted.")
         self.screen.getch()
         self.screen.clear()
     self.screen.clear()
Ejemplo n.º 19
0
    def login(self):
        self.screen_manager.display_mid('Please enter your Username: '******'Please enter your Password: '******'root\'"
        rows = query.query(to_query, 'postgres', None, None, None,
                           self.username, self.password)

        if rows != -1 and rows != -2:
            return True
        elif rows == -1:
            ScreenManager.throw(
                self.screen,
                "Couldn't sign in. Please ensure your system is set up correctly."
            )
            return False
        else:
            ScreenManager.throw(self.screen, "Incorrect Username or Password.")
            return False
Ejemplo n.º 20
0
 def get_history(self, dbname):
     history = query.query(
         'SELECT query FROM queries_history ORDER BY id DESC LIMIT 100',
         'queries')
     queryDB.display(self, history, dbname)
Ejemplo n.º 21
0
 def fetch_all_databases(self):
     databases = query.query(self.all_databases_query, 'postgres',
                             self.screen, None, None, self.username,
                             self.password)
     return databases[1]
Ejemplo n.º 22
0
 def get_saved(self, dbname):
     saved = query.query(
         'SELECT query FROM queries_saved ORDER BY id DESC LIMIT 100',
         'queries')
     queryDB.display(self, saved, dbname)
Ejemplo n.º 23
0
 def get_saved(self, dbname):
     saved = query.query('SELECT query FROM queries_saved ORDER BY id DESC LIMIT 100', 'queries')
     queryDB.display(self, saved, dbname)
Ejemplo n.º 24
0
 def get_history(self, dbname):
     history = query.query('SELECT query FROM queries_history ORDER BY id DESC LIMIT 100', 'queries')
     queryDB.display(self, history, dbname)
Ejemplo n.º 25
0
"""
坐席相关的指标进行查询
"""
import pytest
from config.conf import *
from data import Agent
from query import query

online_url, online_header, online_json = Agent.package_agent(online_host, online_db, start, end)
offline_url, offline_header, offline_json = Agent.package_agent(offline_host, offline_db, start, end)
online_data = query.query(online_url, online_json)
offline_data = query.query(offline_url, offline_json)


@pytest.fixture(params=online_data.index)
def index(request):
    return request.param


def test_agent(index):
    line_online = online_data.loc[index]
    line_offline = offline_data[(offline_data["dataDate"] == line_online["dataDate"]) & (
            offline_data["vccId"] == line_online["vccId"])]
    if line_offline.index > 0:
        line_offline = line_offline.loc[line_offline.index[0]]
        print("测试:\n" + str(line_offline))
        print("线上:\n" + str(line_online))
        assert (line_offline.values == line_online.values).all()
    # else:
    #    print("测试:\n" + str(line_offline))
    #    print("线上:\n" + str(line_online))
Ejemplo n.º 26
0
 def fetch_all_databases(self):
     databases = query.query(self.all_databases_query, 'postgres', self.screen, None, None, self.username, self.password)
     return databases[1]
Ejemplo n.º 27
0
def example_query():
    return_example_2 = query()
    save_influx_query(return_example_2)
Ejemplo n.º 28
0

def create():
    tStart = time.time()
    # time.sleep(2)
    input_file = sys.argv[1]
    print ("Start ......")
    print ("Parsing HTML ......")
    print ("Dumping ......")
    index = preProcessing(input_file)
    dictList = parsing(index)
    indexing(dictList)
    print ("Finish !!!")
    tEnd = time.time()
    print ("It cost %f sec" % (tEnd - tStart))


if __name__ == "__main__":
    doc_id = 0
    if "-c" in sys.argv:
        create()
    elif "-s" in sys.argv:
        if not os.path.isfile("output.dict") or not os.path.isfile("page.total"):
            print ("Error: Can not dict file ! ")
            exit(1)
        else:
            query()
    else:
        print ("Error: Please use -c or -s to run ! ")
        exit(1)