From d26b956c157775265ce89104bec4499b8313d4d5 Mon Sep 17 00:00:00 2001 From: Falko Habel Date: Sun, 19 Jan 2025 12:14:53 +0100 Subject: [PATCH] python code --- setup.py | 27 +++++++++++++++++++++++++++ tree_structurer/__init__.py | 1 + tree_structurer/__main__.py | 31 +++++++++++++++++++++++++++++++ 3 files changed, 59 insertions(+) create mode 100644 setup.py create mode 100644 tree_structurer/__init__.py create mode 100644 tree_structurer/__main__.py diff --git a/setup.py b/setup.py new file mode 100644 index 0000000..2b98270 --- /dev/null +++ b/setup.py @@ -0,0 +1,27 @@ +from setuptools import setup, Extension +import platform + +extra_compile_args = [] +extra_link_args = [] + +# Set C++17 flag based on the compiler +if platform.system() == "Windows": + extra_compile_args.append('/std:c++17') +else: + extra_compile_args.append('-std=c++17') + +tree_structurer_module = Extension( + 'tree_structurer._tree_structurer', + sources=['tree_structurer/cpp/bindings.cpp', 'tree_structurer/cpp/tree_structurer.cpp'], + include_dirs=['tree_structurer/cpp'], + extra_compile_args=extra_compile_args, + extra_link_args=extra_link_args, +) + +setup( + name='tree_structurer', + version='0.0.2', + description='A module for analyzing directory structures', + ext_modules=[tree_structurer_module], + packages=['tree_structurer'], +) \ No newline at end of file diff --git a/tree_structurer/__init__.py b/tree_structurer/__init__.py new file mode 100644 index 0000000..d99440a --- /dev/null +++ b/tree_structurer/__init__.py @@ -0,0 +1 @@ +from tree_structurer._tree_structurer import create_tree_structurer, get_structure \ No newline at end of file diff --git a/tree_structurer/__main__.py b/tree_structurer/__main__.py new file mode 100644 index 0000000..3407a6e --- /dev/null +++ b/tree_structurer/__main__.py @@ -0,0 +1,31 @@ +import os +import sys +import argparse +from tree_structurer import create_tree_structurer, get_structure + +def main(): + parser = argparse.ArgumentParser(description='Display directory structure in a tree-like format') + parser.add_argument('path', nargs='?', default=os.getcwd(), + help='Path to analyze (default: current directory)') + parser.add_argument('-v', '--verbose', action='store_true', + help='Show more detailed output') + args = parser.parse_args() + + try: + if args.verbose: + print(f"Analyzing directory: {args.path}") + + # Create tree structurer instance + create_tree_structurer() + + # Get and print structure + structure = get_structure(args.path) + for line in structure: + print(line) + + except Exception as e: + print(f"Error: {e}", file=sys.stderr) + sys.exit(1) + +if __name__ == "__main__": + main() \ No newline at end of file