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
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
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()
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
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)
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()
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()
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()
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()
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()
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()
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()
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()
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
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()
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()
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
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)
def fetch_all_databases(self): databases = query.query(self.all_databases_query, 'postgres', self.screen, None, None, self.username, self.password) return databases[1]
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)
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)
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)
""" 坐席相关的指标进行查询 """ 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))
def example_query(): return_example_2 = query() save_influx_query(return_example_2)
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)