|
10 | 10 | import logging |
11 | 11 | import os |
12 | 12 |
|
13 | | -__version__ = "Beta 0.1" |
| 13 | +__version__: str = "Beta 0.1" |
14 | 14 |
|
15 | 15 |
|
16 | 16 | def main() -> int: |
17 | | - console = Console() |
18 | | - panel = Panel(Text("Welcome to the Python Tools application!", |
19 | | - justify="center"), |
20 | | - title="PTools", subtitle="Enjoy your using!", |
21 | | - style="bold green") |
| 17 | + console: Console = Console() |
| 18 | + panel: Panel = Panel( |
| 19 | + Text("Welcome to the Python Tools application!", justify="center"), |
| 20 | + title="PTools", |
| 21 | + subtitle="Enjoy your using!", |
| 22 | + style="bold green", |
| 23 | + ) |
22 | 24 | console.print(panel) |
23 | | - logging.basicConfig(level=logging.DEBUG, format="%(message)s", |
24 | | - handlers=[RichHandler()]) |
| 25 | + logging.basicConfig( |
| 26 | + level=logging.DEBUG, format="%(message)s", handlers=[RichHandler()] |
| 27 | + ) |
25 | 28 | logging.info("Starting main process.") |
26 | 29 | logging.debug(f"Platform: {platform.platform()}") |
27 | 30 | logging.debug(f"Python version: {platform.python_version()}") |
28 | 31 | logging.debug(f"markdown module version: {markdown.__version__}") |
29 | 32 | logging.debug(f"rich module version: {importlib.metadata.version('rich')}") |
30 | 33 | logging.debug(f"PTools module version: {__version__}") |
31 | | - paths = console.input("Input your markdown file [bold]path[/bold] " |
32 | | - '("|" to split): ') |
33 | | - paths = paths.split("|") |
34 | | - logging.debug(f"Input paths: {paths}") |
| 34 | + input_paths: set[str] = set(console.input( |
| 35 | + "Input your markdown file [bold]path[/bold] " '("|" to split): ' |
| 36 | + ).split("|")) |
| 37 | + logging.debug(f"Input paths: {input_paths}") |
35 | 38 | # Does the file exist? Is it a file? |
36 | | - vpaths = [] |
37 | | - for path in paths: |
| 39 | + vinput_paths: list[str] = [] |
| 40 | + for path in input_paths: |
38 | 41 | if not os.path.exists(path): |
39 | 42 | logging.warning(f"File not found: {path}") |
40 | 43 | elif not os.path.isfile(path): |
41 | 44 | logging.warning(f"Path is not a file: {path}") |
| 45 | + elif not (path.endswith(".md") or path.endswith(".markdown")): |
| 46 | + logging.warning(f"Path is not a markdown file: {path}") |
42 | 47 | else: |
43 | | - vpaths.append(path) |
44 | | - logging.debug(f"Valid paths: {vpaths}") |
| 48 | + vinput_paths.append(path) |
| 49 | + logging.debug(f"Valid paths: {vinput_paths}") |
| 50 | + if not vinput_paths: |
| 51 | + logging.error("No valid input files.") |
| 52 | + return 1 |
| 53 | + del input_paths |
| 54 | + output_dir: str = console.input( |
| 55 | + "Input your output directory [bold]path[/bold]: " |
| 56 | + ) |
| 57 | + if not os.path.exists(output_dir): |
| 58 | + logging.error(f"Output directory not found: {output_dir}") |
| 59 | + return 1 |
| 60 | + elif not os.path.isdir(output_dir): |
| 61 | + logging.error(f"Output path is not a directory: {output_dir}") |
| 62 | + return 1 |
45 | 63 | logging.info("Finished main process.") |
46 | 64 | return 0 |
47 | 65 |
|
48 | 66 |
|
49 | | -if __name__ == '__main__': |
| 67 | +if __name__ == "__main__": |
50 | 68 | exit(main()) |
0 commit comments