Merge pull request #4 from lgibelli/main

minor fixes
This commit is contained in:
Kirill Markin 2024-06-14 20:19:19 +02:00 committed by GitHub
commit 8bde83f9f1
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1,17 +1,31 @@
import os import os
import subprocess import subprocess
import pathspec import shutil
import logging import logging
import argparse import argparse
import yaml import yaml
from datetime import datetime from datetime import datetime
import pyperclip
# Importing the missing pathspec module
import pathspec
def setup_logging(debug=False): def setup_logging(debug=False):
logging_level = logging.DEBUG if debug else logging.INFO logging_level = logging.DEBUG if debug else logging.INFO
logging.basicConfig(level=logging_level, format='%(asctime)s - %(levelname)s - %(message)s') logging.basicConfig(level=logging_level, format='%(asctime)s - %(levelname)s - %(message)s')
def check_tree_command():
"""Check if the `tree` command is available, and suggest installation if not."""
if shutil.which('tree') is None:
print("The 'tree' command is not found. Please install it using one of the following commands:")
print("For Debian-based systems (e.g., Ubuntu): sudo apt-get install tree")
print("For Red Hat-based systems (e.g., Fedora, CentOS): sudo yum install tree")
return False
return True
def get_tree_structure(path='.', gitignore_spec=None, tree_and_content_ignore_spec=None) -> str: def get_tree_structure(path='.', gitignore_spec=None, tree_and_content_ignore_spec=None) -> str:
if not check_tree_command():
return ""
logging.debug(f'Generating tree structure for path: {path}') logging.debug(f'Generating tree structure for path: {path}')
result = subprocess.run(['tree', '-a', '-f', '--noreport', path], stdout=subprocess.PIPE) result = subprocess.run(['tree', '-a', '-f', '--noreport', path], stdout=subprocess.PIPE)
tree_output = result.stdout.decode('utf-8') tree_output = result.stdout.decode('utf-8')
@ -172,8 +186,13 @@ def save_repo_to_text(path='.', output_dir=None) -> str:
repo_text = file.read() repo_text = file.read()
# Copy the contents to the clipboard # Copy the contents to the clipboard
pyperclip.copy(repo_text) try:
logging.debug('Repository structure and contents copied to clipboard') import pyperclip
pyperclip.copy(repo_text)
logging.debug('Repository structure and contents copied to clipboard')
except Exception as e:
logging.warning('Could not copy to clipboard. You might be running this script over SSH or without clipboard support.')
logging.debug(f'Clipboard copy error: {e}')
return output_file return output_file