From d5cc239e64304355a3cefa5ac050630c4fa4b9ab Mon Sep 17 00:00:00 2001 From: Luca Gibelli <1923603+lgibelli@users.noreply.github.com> Date: Fri, 14 Jun 2024 20:04:54 +0200 Subject: [PATCH 1/2] detect if tree is missing --- repo_to_text/main.py | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/repo_to_text/main.py b/repo_to_text/main.py index f531253..2f0ad06 100644 --- a/repo_to_text/main.py +++ b/repo_to_text/main.py @@ -6,12 +6,25 @@ import argparse import yaml from datetime import datetime import pyperclip +import shutil def setup_logging(debug=False): logging_level = logging.DEBUG if debug else logging.INFO 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: + if not check_tree_command(): + return "" + logging.debug(f'Generating tree structure for path: {path}') result = subprocess.run(['tree', '-a', '-f', '--noreport', path], stdout=subprocess.PIPE) tree_output = result.stdout.decode('utf-8') From d75e2f9f72262eb618200f8141182f8f16a74dd6 Mon Sep 17 00:00:00 2001 From: Luca Gibelli <1923603+lgibelli@users.noreply.github.com> Date: Fri, 14 Jun 2024 20:07:47 +0200 Subject: [PATCH 2/2] fail softly if clipboard not available --- repo_to_text/main.py | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/repo_to_text/main.py b/repo_to_text/main.py index 2f0ad06..79c094e 100644 --- a/repo_to_text/main.py +++ b/repo_to_text/main.py @@ -1,19 +1,20 @@ import os import subprocess -import pathspec +import shutil import logging import argparse import yaml from datetime import datetime -import pyperclip -import shutil + +# Importing the missing pathspec module +import pathspec def setup_logging(debug=False): logging_level = logging.DEBUG if debug else logging.INFO 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. """ + """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") @@ -185,8 +186,13 @@ def save_repo_to_text(path='.', output_dir=None) -> str: repo_text = file.read() # Copy the contents to the clipboard - pyperclip.copy(repo_text) - logging.debug('Repository structure and contents copied to clipboard') + try: + 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