Interactive document selection.
(self)
| 75 | return input(f"{prompt}: ").strip() |
| 76 | |
| 77 | def select_documents(self) -> List[str]: |
| 78 | """Interactive document selection.""" |
| 79 | print("\n๐ Document Selection") |
| 80 | print("=" * 50) |
| 81 | |
| 82 | documents = [] |
| 83 | |
| 84 | while True: |
| 85 | print("\nOptions:") |
| 86 | print("1. Add a single document") |
| 87 | print("2. Add all documents from a directory") |
| 88 | print("3. Finish and proceed with selected documents") |
| 89 | print("4. Show selected documents") |
| 90 | |
| 91 | choice = self.get_user_input("Select an option (1-4)", "1") |
| 92 | |
| 93 | if choice == "1": |
| 94 | doc_path = self.get_user_input("Enter document path") |
| 95 | if os.path.exists(doc_path): |
| 96 | documents.append(os.path.abspath(doc_path)) |
| 97 | print(f"โ Added: {doc_path}") |
| 98 | else: |
| 99 | print(f"โ File not found: {doc_path}") |
| 100 | |
| 101 | elif choice == "2": |
| 102 | dir_path = self.get_user_input("Enter directory path") |
| 103 | if os.path.isdir(dir_path): |
| 104 | supported_extensions = ['.pdf', '.txt', '.docx', '.md', '.html', '.htm'] |
| 105 | found_docs = [] |
| 106 | |
| 107 | for ext in supported_extensions: |
| 108 | found_docs.extend(Path(dir_path).glob(f"*{ext}")) |
| 109 | found_docs.extend(Path(dir_path).glob(f"**/*{ext}")) |
| 110 | |
| 111 | if found_docs: |
| 112 | print(f"Found {len(found_docs)} documents:") |
| 113 | for doc in found_docs: |
| 114 | print(f" - {doc}") |
| 115 | |
| 116 | if self.get_user_input("Add all these documents? (y/n)", "y").lower() == 'y': |
| 117 | documents.extend([str(doc.absolute()) for doc in found_docs]) |
| 118 | print(f"โ Added {len(found_docs)} documents") |
| 119 | else: |
| 120 | print("โ No supported documents found in directory") |
| 121 | else: |
| 122 | print(f"โ Directory not found: {dir_path}") |
| 123 | |
| 124 | elif choice == "3": |
| 125 | if documents: |
| 126 | break |
| 127 | else: |
| 128 | print("โ No documents selected. Please add at least one document.") |
| 129 | |
| 130 | elif choice == "4": |
| 131 | if documents: |
| 132 | print(f"\n๐ Selected documents ({len(documents)}):") |
| 133 | for i, doc in enumerate(documents, 1): |
| 134 | print(f" {i}. {doc}") |
no test coverage detected