def run_migration(save_dir, use_json): store_file_path = command_store.get_file_path(save_dir, use_json, False) sql_store_file_path = command_store.get_file_path(save_dir, False, True) store = command_store.load_command_store( store_file_path, command_store.get_store_type(True, False)) sql_store = command_store.load_command_store(sql_store_file_path, command_store.SQL_STORE) for command in store.get_all_commands(): sql_store.add_command(command) return True
def main(command_executor): """Entry point for this executable python module.""" args = handle_args.setup_args_for_update() store_file_path = command_store.get_file_path(args.save_dir, args.json, args.sql) store_type = command_store.get_store_type(args.json, args.sql) store = command_store.load_command_store(store_file_path, store_type) print('Looking for all past commands with: ' + ", ".join(args.query)) result = store.search_commands( args.query, args.startswith, ) print("Number of results found: " + str(len(result))) store_updated = False if args.delete and len(result) > 0: print("Delete mode") command_store.print_commands(result, args.query) store_updated = store_updated or command_executor.delete_interaction( store, result) if args.updateinfo and len(result) > 0: print("Updating Info mode") store_updated = store_updated or command_executor.set_command_info( result) if store_updated: print("Updating Command Store...") command_store.save_command_store(store, store_file_path, args.json)
def test_verify_read_sql_file_time(self) -> None: file_name = os.path.join(TEST_FILES_PATH, "test_remember.db") self.assertTrue(os.path.isfile(file_name)) store = command_store_lib.load_command_store(file_name) matches = store.search_commands([""], False) for m in matches: self.assertEqual(0, m.last_used_time())
def main(command_executor: InteractiveCommandExecutor) -> None: """Entry point for this executable python module.""" args = handle_args.setup_args_for_update() store_file_path = command_store.get_file_path(args.save_dir) store = command_store.load_command_store(store_file_path) print('Looking for all past commands with: ' + ", ".join(args.query)) start_time = time.time() search_results = store.search_commands( args.query, args.startswith, ) end_time = time.time() print(f"Search time: {end_time - start_time} seconds") print(f"Number of results found: {str(len(search_results))}") if len(search_results) > args.max: print(f"Results truncated to the first: {args.max}") search_results = search_results[:args.max] if len(search_results) > 0: if args.delete: print("Delete mode") command_store.print_commands(search_results, args.query) command_executor.delete_interaction(store, search_results) if args.updateinfo: print("Updating Info mode") command_executor.command_info_interaction(search_results, store)
def test_verify_read_json_file_time(self): file_name = os.path.join(TEST_FILES_PATH, "test_json.json") self.assertTrue(os.path.isfile(file_name)) store = command_store_lib.load_command_store( file_name, store_type=command_store_lib.JSON_STORE) matches = store.search_commands([""], False) self.assertTrue(len(matches) > 0) for m in matches: self.assertEqual(0, m.last_used_time())
def test_verify_read_sql_file(self) -> None: file_name = os.path.join(TEST_FILES_PATH, "test_remember.db") store = command_store_lib.load_command_store(file_name) matches = store.search_commands([""], False) self.assertTrue(len(matches) > 0) matches = store.search_commands(["rm"], True) self.assertTrue(len(matches) == 1) self.assertEqual(matches[0].get_unique_command_id(), 'rm somefile.txt') self.assertEqual(matches[0].get_count_seen(), 2)
def test_verify_read_json_file(self): file_name = os.path.join(TEST_FILES_PATH, "test_json.json") store = command_store_lib.load_command_store( file_name, store_type=command_store_lib.JSON_STORE) matches = store.search_commands([""], False) self.assertTrue(len(matches) > 0) matches = store.search_commands(["rm"], True) self.assertTrue(len(matches) == 1) self.assertEqual(matches[0].get_unique_command_id(), 'rm somefile.txt') self.assertEqual(matches[0].get_count_seen(), 2)
def test_sqlCommandStore_whenAddingItem_shouldReturnTrueWhenSearching(self) -> None: file_path = '' try: file_path = os.path.join(TEST_PATH_DIR, "delete_test_sql_store.db") command_store = command_store_lib.SqlCommandStore(file_path) command_str = "git branch" command = command_store_lib.Command(command_str) command_store.add_command(command) command_store = command_store_lib.load_command_store(file_path) self.assertTrue(command_store.has_command(command)) finally: if file_path: os.remove(file_path)
def run_remember_command(save_dir: str, history_file_path: str, query: List[str], search_all: bool, search_starts_with: bool, execute: bool, max_return_count: int) -> Optional[str]: store_file_path = command_store.get_file_path(save_dir) store = command_store.load_command_store(store_file_path) command_store.start_history_processing(store, history_file_path, save_dir, 20) print('Looking for all past commands with: ' + ", ".join(query)) start_time = time.time() result = store.search_commands(query, search_starts_with, search_info=search_all) total_time = time.time() - start_time print("Search time %.5f: seconds" % total_time) return display_and_interact_results( result, max_return_count, save_dir, history_file_path, query, execute)
def test_verifySqldb_shouldSaveAndStore_whenCommandIsAdded(self) -> None: file_name = '' try: file_name = os.path.join(TEST_PATH_DIR, "delete_test_pickle.db") command_store = command_store_lib.SqlCommandStore(file_name) command_str = "git branch" command = command_store_lib.Command(command_str) command_store.add_command(command) command_store = command_store_lib.load_command_store(file_name) self.assertTrue(command_store.has_command(command)) finally: if file_name: os.remove(file_name)
def test_verifyPickle_shouldSaveAndStore_whenCommandIsAdded(self): file_path = '' try: file_name = os.path.join(TEST_PATH_DIR, "delete_test_pickle.pickle") command_store = command_store_lib.CommandStore() command_str = "git branch" command = command_store_lib.Command(command_str) command_store.add_command(command) command_store_lib.save_command_store(command_store, file_name) command_store = command_store_lib.load_command_store(file_name) self.assertTrue(command_store.has_command(command)) finally: if file_path: os.remove(file_path)
def generate_store_from_args(history_file_path, save_directory, use_json, use_sql): store_file_path = com_lib.get_file_path(save_directory, use_json, use_sql) commands_file_path = os.path.join(save_directory, com_lib.FILE_STORE_NAME) ignore_rule_file = os.path.join(save_directory, IGNORE_RULE_FILE_NAME) if not os.path.isfile(ignore_rule_file): ignore_rule_file = None else: print('Using ignore rules from ' + ignore_rule_file) store_type = com_lib.get_store_type(use_json, use_sql) store = com_lib.load_command_store(store_file_path, store_type) com_lib.read_history_file(store, history_file_path, commands_file_path, ignore_rule_file) print('Reading ' + history_file_path) if com_lib.save_command_store(store, store_file_path, use_json): print('Writing file out to ' + store_file_path)
def test_jsonSave_shouldLoadCommandStoreFromJson_whenCommandIsAddedAndStoreSaved( self): file_name = '' try: file_name = os.path.join(TEST_PATH_DIR, "delete_test_json.json") command_store = command_store_lib.CommandStore() command_str = "git branch" command = command_store_lib.Command(command_str) command_store.add_command(command) command_store_lib.save_command_store(command_store, file_name, True) command_store = command_store_lib.load_command_store( file_name, command_store_lib.JSON_STORE) self.assertTrue(command_store.has_command(command)) finally: if file_name: os.remove(file_name)
def run_history_command(save_dir: str, history_file_path: str, directory: str, execute: bool, max_results: int, search_term: str) -> Optional[str]: search_term_list = [search_term] if search_term else [] store_file_path = command_store.get_file_path(save_dir) store = command_store.load_command_store(store_file_path) command_store.start_history_processing(store, history_file_path, save_dir, 1) print(f'Looking for all past commands with: {directory}') start_time = time.time() result = store.get_command_with_context(directory, search_term_list) total_time = time.time() - start_time print("Search time %.5f: seconds" % total_time) return display_and_interact_results( result, max_results, save_dir, history_file_path, None, execute)
def test_verifyPickle_withJson(self): use_json = True file_path = '' try: file_path = os.path.join(TEST_PATH_DIR, "delete_test_pickle.pickle") command_store = command_store_lib.CommandStore() command_str = "git branch" command = command_store_lib.Command(command_str) command_store.add_command(command) command_store_lib.save_command_store(command_store, file_path, use_json) command_store = command_store_lib.load_command_store( file_path, command_store_lib.JSON_STORE) self.assertTrue(command_store.has_command(command)) finally: if file_path: os.remove(file_path)
def test_load_file_when_file_not_there(self): command_store = command_store_lib.load_command_store( 'randomNonExistantFile.someextension') self.assertEqual(command_store.get_num_commands(), 0)
def test_load_file_when_file_not_there(self) -> None: with self.assertRaises(Exception): command_store_lib.load_command_store('randomNonExistantFile.someextension')