updated main
Gitea Actions For Tree-Structurer / Explore-Gitea-Actions (push) Successful in 22s
Details
Gitea Actions For Tree-Structurer / Explore-Gitea-Actions (push) Successful in 22s
Details
This commit is contained in:
parent
2a5a652638
commit
40e55ca55a
|
@ -34,4 +34,4 @@ jobs:
|
||||||
VECTORDB_TOKEN: ${{ secrets.VECTORDB_TOKEN }}
|
VECTORDB_TOKEN: ${{ secrets.VECTORDB_TOKEN }}
|
||||||
run: |
|
run: |
|
||||||
cd VectorLoader
|
cd VectorLoader
|
||||||
python -m src.run --full
|
python -m src.run
|
||||||
|
|
2
setup.py
2
setup.py
|
@ -20,7 +20,7 @@ tree_structurer_module = Extension(
|
||||||
|
|
||||||
setup(
|
setup(
|
||||||
name='prodir',
|
name='prodir',
|
||||||
version='0.0.8',
|
version='0.0.9',
|
||||||
description='A module for analyzing directory structures',
|
description='A module for analyzing directory structures',
|
||||||
ext_modules=[tree_structurer_module],
|
ext_modules=[tree_structurer_module],
|
||||||
packages=find_packages(where="src"),
|
packages=find_packages(where="src"),
|
||||||
|
|
|
@ -8,15 +8,19 @@ from prodir import (
|
||||||
)
|
)
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# Create the main parser
|
||||||
parser = argparse.ArgumentParser(
|
parser = argparse.ArgumentParser(
|
||||||
|
prog='prodir', # Set program name to prodir
|
||||||
description='Directory structure tool: Display and create directory structures'
|
description='Directory structure tool: Display and create directory structures'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create subparsers for different commands
|
# Create subparsers for different commands
|
||||||
subparsers = parser.add_subparsers(dest='command', help='Available commands')
|
subparsers = parser.add_subparsers(dest='command', help='Available commands')
|
||||||
|
|
||||||
# Display command
|
# Display command
|
||||||
display_parser = subparsers.add_parser('display', help='Display directory structure')
|
display_parser = subparsers.add_parser('display',
|
||||||
|
prog='prodir display', # Set display command name
|
||||||
|
help='Display directory structure')
|
||||||
display_parser.add_argument(
|
display_parser.add_argument(
|
||||||
'path',
|
'path',
|
||||||
nargs='?',
|
nargs='?',
|
||||||
|
@ -28,9 +32,11 @@ def main():
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Show more detailed output'
|
help='Show more detailed output'
|
||||||
)
|
)
|
||||||
|
|
||||||
# Create command
|
# Create command
|
||||||
create_parser = subparsers.add_parser('create', help='Create directory structure')
|
create_parser = subparsers.add_parser('create',
|
||||||
|
prog='prodir create', # Set create command name
|
||||||
|
help='Create directory structure')
|
||||||
create_parser.add_argument(
|
create_parser.add_argument(
|
||||||
'file',
|
'file',
|
||||||
help='File containing the directory structure'
|
help='File containing the directory structure'
|
||||||
|
@ -45,58 +51,68 @@ def main():
|
||||||
action='store_true',
|
action='store_true',
|
||||||
help='Show more detailed output'
|
help='Show more detailed output'
|
||||||
)
|
)
|
||||||
|
|
||||||
|
# Check if a direct path was provided
|
||||||
|
if len(sys.argv) > 1 and not sys.argv[1].startswith('-') and not sys.argv[1] in ['display', 'create']:
|
||||||
|
# Convert to display command with path
|
||||||
|
sys.argv.insert(1, 'display')
|
||||||
|
|
||||||
args = parser.parse_args()
|
args = parser.parse_args()
|
||||||
|
|
||||||
# If no command is specified, default to display
|
# If no command is specified, use display with current directory
|
||||||
if not args.command:
|
if not args.command:
|
||||||
args.command = 'display'
|
args.command = 'display'
|
||||||
args.path = os.getcwd()
|
args.path = os.getcwd()
|
||||||
args.verbose = False
|
args.verbose = False
|
||||||
|
|
||||||
try:
|
try:
|
||||||
create_tree_structurer()
|
create_tree_structurer()
|
||||||
|
|
||||||
if args.command == 'display':
|
if args.command == 'display':
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print(f"Analyzing directory: {args.path}")
|
print(f"Analyzing directory: {args.path}")
|
||||||
|
try:
|
||||||
structure = get_structure(args.path)
|
structure = get_structure(args.path)
|
||||||
for line in structure:
|
for line in structure:
|
||||||
print(line)
|
print(line)
|
||||||
|
except FileNotFoundError:
|
||||||
|
print("Error: Directory does not exist", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {str(e)}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
elif args.command == 'create':
|
elif args.command == 'create':
|
||||||
if args.verbose:
|
if args.verbose:
|
||||||
print(f"Creating directory structure in: {args.output}")
|
print(f"Creating directory structure in: {args.output}")
|
||||||
print(f"Using structure from file: {args.file}")
|
print(f"Using structure from file: {args.file}")
|
||||||
|
|
||||||
create_structure_from_file(args.file, args.output)
|
# Check if the output path exists
|
||||||
|
if not os.path.exists(args.output):
|
||||||
if args.verbose:
|
print(f"Error: The specified output path '{args.output}' does not exist.", file=sys.stderr)
|
||||||
print("Structure created successfully")
|
exit(1)
|
||||||
print("\nResulting structure:")
|
|
||||||
structure = get_structure(args.output)
|
|
||||||
for line in structure:
|
|
||||||
print(line)
|
|
||||||
|
|
||||||
|
try:
|
||||||
|
create_structure_from_file(args.file, args.output)
|
||||||
|
if args.verbose:
|
||||||
|
print("Structure created successfully")
|
||||||
|
print("\nResulting structure:")
|
||||||
|
structure = get_structure(args.output)
|
||||||
|
for line in structure:
|
||||||
|
print(line)
|
||||||
|
except FileNotFoundError as e:
|
||||||
|
if 'structure file' in str(e):
|
||||||
|
print("Error: Unable to open structure file", file=sys.stderr)
|
||||||
|
else:
|
||||||
|
print("Error: Directory does not exist", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
except Exception as e:
|
||||||
|
print(f"Error: {str(e)}", file=sys.stderr)
|
||||||
|
sys.exit(1)
|
||||||
|
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
error_msg = str(e)
|
print(f"Error: {str(e)}", file=sys.stderr)
|
||||||
if "Directory does not exist" in error_msg:
|
|
||||||
print(f"Error: The specified directory does not exist: {args.path if args.command == 'display' else args.output}",
|
|
||||||
file=sys.stderr)
|
|
||||||
elif "Directory is empty" in error_msg:
|
|
||||||
print(f"Error: The specified directory is empty: {args.path if args.command == 'display' else args.output}",
|
|
||||||
file=sys.stderr)
|
|
||||||
elif "Path is not a directory" in error_msg:
|
|
||||||
print(f"Error: The specified path is not a directory: {args.path if args.command == 'display' else args.output}",
|
|
||||||
file=sys.stderr)
|
|
||||||
elif "Unable to open structure file" in error_msg:
|
|
||||||
print(f"Error: Unable to open structure file: {args.file}", file=sys.stderr)
|
|
||||||
elif "Invalid structure format" in error_msg:
|
|
||||||
print(f"Error: Invalid structure format in {'file' if args.file else 'string'}", file=sys.stderr)
|
|
||||||
else:
|
|
||||||
print(f"Error: {error_msg}", file=sys.stderr)
|
|
||||||
sys.exit(1)
|
sys.exit(1)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in New Issue