nehajiya8 commited on
Commit
d1e23c5
·
verified ·
1 Parent(s): 8b58bde

Update utils/repo_converter.py

Browse files
Files changed (1) hide show
  1. utils/repo_converter.py +22 -3
utils/repo_converter.py CHANGED
@@ -7,7 +7,7 @@ class SimpleRepoConverter:
7
  """Initialize the converter with ignored directories and extensions."""
8
  self.ignored_dirs = {'node_modules', '__pycache__', '.git', '.next', 'dist', 'build'}
9
  self.ignored_extensions = {'.pyc', '.pyo', '.mo', '.db', '.sqlite', '.mov', 'lock', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico'}
10
-
11
  def should_process_file(self, file_path: str) -> bool:
12
  _, ext = os.path.splitext(file_path.lower())
13
  path_parts = Path(file_path).parts
@@ -28,12 +28,24 @@ class SimpleRepoConverter:
28
  os.makedirs(output_dir, exist_ok=True)
29
 
30
  all_files_content = ["Complete Repository Contents\n", "=" * 40 + "\n\n"]
 
31
 
32
  for root, dirs, files in os.walk(input_dir):
33
  # Skip ignored directories
34
  dirs[:] = [d for d in dirs if d not in self.ignored_dirs]
35
 
36
- for file in files:
 
 
 
 
 
 
 
 
 
 
 
37
  input_path = os.path.join(root, file)
38
 
39
  if not self.should_process_file(input_path):
@@ -45,14 +57,21 @@ class SimpleRepoConverter:
45
  with open(input_path, 'r', encoding='utf-8') as f:
46
  content = f.read()
47
  all_files_content.extend([
48
- f"File: {rel_path}\n",
49
  "=" * 40 + "\n",
50
  content + "\n\n"
51
  ])
52
  except UnicodeDecodeError:
53
  print(f"Skipping binary file: {rel_path}")
 
 
 
54
  except Exception as e:
55
  print(f"Error processing {rel_path}: {e}")
 
 
 
56
 
 
57
  with open(os.path.join(output_dir, '_all_files.txt'), 'w', encoding='utf-8') as f:
58
  f.writelines(all_files_content)
 
7
  """Initialize the converter with ignored directories and extensions."""
8
  self.ignored_dirs = {'node_modules', '__pycache__', '.git', '.next', 'dist', 'build'}
9
  self.ignored_extensions = {'.pyc', '.pyo', '.mo', '.db', '.sqlite', '.mov', 'lock', '.png', '.jpg', '.jpeg', '.gif', '.svg', '.ico'}
10
+
11
  def should_process_file(self, file_path: str) -> bool:
12
  _, ext = os.path.splitext(file_path.lower())
13
  path_parts = Path(file_path).parts
 
28
  os.makedirs(output_dir, exist_ok=True)
29
 
30
  all_files_content = ["Complete Repository Contents\n", "=" * 40 + "\n\n"]
31
+ current_dir = None
32
 
33
  for root, dirs, files in os.walk(input_dir):
34
  # Skip ignored directories
35
  dirs[:] = [d for d in dirs if d not in self.ignored_dirs]
36
 
37
+ # Add directory context
38
+ rel_dir = os.path.relpath(root, input_dir)
39
+ if rel_dir != '.' and rel_dir != current_dir:
40
+ current_dir = rel_dir
41
+ all_files_content.extend([
42
+ f"\nDirectory: {rel_dir}\n",
43
+ "-" * 40 + "\n",
44
+ "Contents:\n"
45
+ ])
46
+
47
+ # Process files in current directory
48
+ for file in sorted(files):
49
  input_path = os.path.join(root, file)
50
 
51
  if not self.should_process_file(input_path):
 
57
  with open(input_path, 'r', encoding='utf-8') as f:
58
  content = f.read()
59
  all_files_content.extend([
60
+ f"\nFile: {rel_path}\n",
61
  "=" * 40 + "\n",
62
  content + "\n\n"
63
  ])
64
  except UnicodeDecodeError:
65
  print(f"Skipping binary file: {rel_path}")
66
+ all_files_content.extend([
67
+ f"[Binary file skipped: {rel_path}]\n"
68
+ ])
69
  except Exception as e:
70
  print(f"Error processing {rel_path}: {e}")
71
+ all_files_content.extend([
72
+ f"[Error processing file: {rel_path} - {str(e)}]\n"
73
+ ])
74
 
75
+ # Write the processed content
76
  with open(os.path.join(output_dir, '_all_files.txt'), 'w', encoding='utf-8') as f:
77
  f.writelines(all_files_content)