def test_get_file_path(self): result = command_store_lib.get_file_path('my_dir/path') self.assertEqual('my_dir/path/' + command_store_lib.PICKLE_FILE_NAME, result) result = command_store_lib.get_file_path('my_dir/path', True) self.assertEqual('my_dir/path/' + command_store_lib.JSON_FILE_NAME, result) result = command_store_lib.get_file_path('my_dir/path', False, True) self.assertEqual( 'my_dir/path/' + command_store_lib.REMEMBER_DB_FILE_NAME, result)
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: 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 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 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 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 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_simple_assert_default_pickle_file_exists(self): file_path = command_store_lib.get_file_path(TEST_FILES_PATH, False) assert os.path.isfile(file_path)
def test_get_file_path(self) -> None: result = command_store_lib.get_file_path('my_dir/path') self.assertEqual('my_dir/path/' + command_store_lib.REMEMBER_DB_FILE_NAME, result)
def test_simple_assert_default_json_file_exists(self) -> None: file_path = command_store_lib.get_file_path(TEST_FILES_PATH) assert os.path.isfile(file_path)
def create_db_if_doesnt_exist(save_dir: str) -> None: store_file_path = get_file_path(save_dir) conn = sqlite3.connect(store_file_path) conn.close()