Spaces:
Sleeping
Sleeping
venkatesh commited on
Commit ·
de092c8
1
Parent(s): 289f379
added folder names in pdf and highlights non image extensions
Browse files- __pycache__/helper.cpython-313.pyc +0 -0
- __pycache__/tab8.cpython-313.pyc +0 -0
- helper.py +19 -12
- tab8.py +96 -28
__pycache__/helper.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/helper.cpython-313.pyc and b/__pycache__/helper.cpython-313.pyc differ
|
|
|
__pycache__/tab8.cpython-313.pyc
CHANGED
|
Binary files a/__pycache__/tab8.cpython-313.pyc and b/__pycache__/tab8.cpython-313.pyc differ
|
|
|
helper.py
CHANGED
|
@@ -27,7 +27,10 @@ ALLOWED_ARCHIVE_EXTENSIONS = {'.zip', '.rar', '.7z', '.tar', '.gz', '.bz2', '.xz
|
|
| 27 |
ALLOWED_CODE_EXTENSIONS = {'.py', '.js', '.html', '.css', '.java', '.cpp', '.c', '.h', '.php', '.rb', '.go', '.rs', '.swift', '.kt'}
|
| 28 |
ALLOWED_DATA_EXTENSIONS = {'.json', '.xml', '.yaml', '.yml', '.sql', '.db', '.sqlite', '.xlsx', '.xls'}
|
| 29 |
ALLOWED_OTHER_EXTENSIONS = {'.psd', '.ai', '.sketch', '.fig', '.eps', '.indd', '.dwg', '.stl', '.obj', '.fbx', '.blend'}
|
| 30 |
-
|
|
|
|
|
|
|
|
|
|
| 31 |
# Combine all extensions - if a file has ANY extension or NO extension, process it
|
| 32 |
ALL_ALLOWED_EXTENSIONS = (ALLOWED_IMAGE_EXTENSIONS | ALLOWED_TEXT_EXTENSIONS |
|
| 33 |
ALLOWED_VIDEO_EXTENSIONS | ALLOWED_AUDIO_EXTENSIONS |
|
|
@@ -197,20 +200,25 @@ def generate_excel_report(output_folder: Path, marken_index: dict, file_to_facto
|
|
| 197 |
factorgroup = factorgroup.replace('_', '') # Remove all underscores
|
| 198 |
|
| 199 |
only_id = name
|
| 200 |
-
is_text_file = False
|
| 201 |
is_b20_id = False
|
|
|
|
| 202 |
|
| 203 |
if "B20" in only_id.upper():
|
| 204 |
is_b20_id = True
|
| 205 |
language_value = only_id + file_ext
|
| 206 |
-
|
| 207 |
-
|
| 208 |
-
|
| 209 |
-
|
| 210 |
-
|
| 211 |
-
|
| 212 |
-
|
| 213 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 214 |
else:
|
| 215 |
language_value = name + file_ext
|
| 216 |
|
|
@@ -219,10 +227,9 @@ def generate_excel_report(output_folder: Path, marken_index: dict, file_to_facto
|
|
| 219 |
"factorgroup": factorgroup,
|
| 220 |
"ID": only_id,
|
| 221 |
"Language": language_value,
|
| 222 |
-
"highlight_yellow":
|
| 223 |
})
|
| 224 |
|
| 225 |
-
|
| 226 |
df_assets = pd.DataFrame(data, columns=["factor", "factorgroup", "ID", "Language"])
|
| 227 |
|
| 228 |
reordered_data = []
|
|
|
|
| 27 |
ALLOWED_CODE_EXTENSIONS = {'.py', '.js', '.html', '.css', '.java', '.cpp', '.c', '.h', '.php', '.rb', '.go', '.rs', '.swift', '.kt'}
|
| 28 |
ALLOWED_DATA_EXTENSIONS = {'.json', '.xml', '.yaml', '.yml', '.sql', '.db', '.sqlite', '.xlsx', '.xls'}
|
| 29 |
ALLOWED_OTHER_EXTENSIONS = {'.psd', '.ai', '.sketch', '.fig', '.eps', '.indd', '.dwg', '.stl', '.obj', '.fbx', '.blend'}
|
| 30 |
+
# Non-image extensions (for highlighting)
|
| 31 |
+
NON_IMAGE_EXTENSIONS = (ALLOWED_VIDEO_EXTENSIONS | ALLOWED_AUDIO_EXTENSIONS |
|
| 32 |
+
ALLOWED_TEXT_EXTENSIONS | ALLOWED_ARCHIVE_EXTENSIONS |
|
| 33 |
+
ALLOWED_CODE_EXTENSIONS | ALLOWED_DATA_EXTENSIONS | ALLOWED_OTHER_EXTENSIONS)
|
| 34 |
# Combine all extensions - if a file has ANY extension or NO extension, process it
|
| 35 |
ALL_ALLOWED_EXTENSIONS = (ALLOWED_IMAGE_EXTENSIONS | ALLOWED_TEXT_EXTENSIONS |
|
| 36 |
ALLOWED_VIDEO_EXTENSIONS | ALLOWED_AUDIO_EXTENSIONS |
|
|
|
|
| 200 |
factorgroup = factorgroup.replace('_', '') # Remove all underscores
|
| 201 |
|
| 202 |
only_id = name
|
|
|
|
| 203 |
is_b20_id = False
|
| 204 |
+
is_non_image_file = False # INITIALIZE HERE
|
| 205 |
|
| 206 |
if "B20" in only_id.upper():
|
| 207 |
is_b20_id = True
|
| 208 |
language_value = only_id + file_ext
|
| 209 |
+
# Highlight ALL non-image formats (not just .txt)
|
| 210 |
+
elif file_ext in NON_IMAGE_EXTENSIONS:
|
| 211 |
+
is_non_image_file = True
|
| 212 |
+
if file_ext == '.txt':
|
| 213 |
+
try:
|
| 214 |
+
with open(file, 'r', encoding='utf-8', errors='ignore') as txt_file:
|
| 215 |
+
txt_content = txt_file.read().strip()
|
| 216 |
+
language_value = txt_content if txt_content else "[Empty file]"
|
| 217 |
+
except Exception as e:
|
| 218 |
+
language_value = f"[Error reading file: {str(e)}]"
|
| 219 |
+
else:
|
| 220 |
+
# For non-image, non-txt files, show the full filename with extension
|
| 221 |
+
language_value = name + file_ext
|
| 222 |
else:
|
| 223 |
language_value = name + file_ext
|
| 224 |
|
|
|
|
| 227 |
"factorgroup": factorgroup,
|
| 228 |
"ID": only_id,
|
| 229 |
"Language": language_value,
|
| 230 |
+
"highlight_yellow": is_non_image_file or is_b20_id # Highlight non-images
|
| 231 |
})
|
| 232 |
|
|
|
|
| 233 |
df_assets = pd.DataFrame(data, columns=["factor", "factorgroup", "ID", "Language"])
|
| 234 |
|
| 235 |
reordered_data = []
|
tab8.py
CHANGED
|
@@ -12,7 +12,8 @@ from helper import (
|
|
| 12 |
generate_excel_report,
|
| 13 |
generate_filename_based_pdf_report_with_extensions,
|
| 14 |
ALL_ALLOWED_EXTENSIONS,
|
| 15 |
-
is_valid_file
|
|
|
|
| 16 |
)
|
| 17 |
|
| 18 |
|
|
@@ -63,19 +64,43 @@ def get_base_filename_without_ext(filename):
|
|
| 63 |
return Path(filename).stem
|
| 64 |
|
| 65 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 66 |
def reconstruct_folder_structure(files_folder):
|
| 67 |
"""
|
| 68 |
Reconstruct the folder structure from parsed filenames.
|
| 69 |
Groups files by blocknummer (folder) and marke (brand).
|
| 70 |
-
Handles duplicate base filenames
|
| 71 |
"""
|
| 72 |
marken_set = set()
|
| 73 |
marken_index = {}
|
| 74 |
renamed_files_by_folder_and_marke = defaultdict(lambda: defaultdict(list))
|
| 75 |
file_to_factorgroup = {}
|
|
|
|
| 76 |
|
| 77 |
-
# Track unique base filenames for counting
|
| 78 |
-
unique_base_files = defaultdict(
|
| 79 |
|
| 80 |
# Collect all valid files
|
| 81 |
parsed_files = []
|
|
@@ -106,12 +131,19 @@ def reconstruct_folder_structure(files_folder):
|
|
| 106 |
else:
|
| 107 |
skipped_files.append(f"{file_path.name} (doesn't match naming convention)")
|
| 108 |
|
| 109 |
-
#
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 110 |
for parsed in parsed_files:
|
| 111 |
marke = parsed['marke']
|
| 112 |
markennummer = parsed['markennummer']
|
| 113 |
blocknummer = parsed['blocknummer']
|
| 114 |
file_path = parsed['file_path']
|
|
|
|
| 115 |
|
| 116 |
# Add to marken_set
|
| 117 |
marken_set.add(marke)
|
|
@@ -120,27 +152,61 @@ def reconstruct_folder_structure(files_folder):
|
|
| 120 |
if marke not in marken_index:
|
| 121 |
marken_index[marke] = markennummer
|
| 122 |
|
| 123 |
-
#
|
| 124 |
-
folder_name = f"{blocknummer}Folder"
|
| 125 |
|
| 126 |
-
# Track
|
| 127 |
base_filename = get_base_filename_without_ext(file_path.name)
|
| 128 |
-
|
| 129 |
-
|
| 130 |
-
|
| 131 |
-
|
| 132 |
-
|
| 133 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 134 |
|
| 135 |
-
|
| 136 |
-
|
| 137 |
|
| 138 |
# Prepare debug info
|
| 139 |
debug_info = {
|
| 140 |
'total_files': total_files,
|
| 141 |
'parsed_files': len(parsed_files),
|
| 142 |
'skipped_files': skipped_files,
|
| 143 |
-
'unique_counts':
|
| 144 |
}
|
| 145 |
|
| 146 |
return marken_set, renamed_files_by_folder_and_marke, marken_index, file_to_factorgroup, debug_info
|
|
@@ -205,7 +271,7 @@ def regenerate_reports_from_folder(files_folder):
|
|
| 205 |
except Exception as e:
|
| 206 |
return None, None, f"Error reading existing Excel file: {str(e)}"
|
| 207 |
|
| 208 |
-
# Reconstruct structure from filenames
|
| 209 |
marken_set, renamed_files_by_folder_and_marke, marken_index, _, debug_info = reconstruct_folder_structure(files_folder)
|
| 210 |
|
| 211 |
if not marken_set:
|
|
@@ -233,7 +299,8 @@ def regenerate_reports_from_folder(files_folder):
|
|
| 233 |
# Parse to get blocknummer for new files
|
| 234 |
parsed = parse_filename(file_path.name)
|
| 235 |
if parsed:
|
| 236 |
-
|
|
|
|
| 237 |
file_to_factorgroup[file_path.name] = folder_name
|
| 238 |
new_files_added += 1
|
| 239 |
print(f" ✨ NEW: {file_path.name} -> {folder_name}")
|
|
@@ -527,6 +594,12 @@ def regenerate_reports_tool():
|
|
| 527 |
|
| 528 |
This tool regenerates PDF and Excel reports from a Tab 5 output folder that may contain manually added images.
|
| 529 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 530 |
**Use Case:**
|
| 531 |
1. You ran Tab 5 and got an output folder with images, PDF, and Excel reports
|
| 532 |
2. You manually added new images to that folder (following the same naming convention)
|
|
@@ -554,15 +627,10 @@ def regenerate_reports_tool():
|
|
| 554 |
|
| 555 |
**Important Notes:**
|
| 556 |
- The tool preserves any manual folder structure changes you made in the Excel file
|
| 557 |
-
- Files with the same name but different extensions
|
| 558 |
-
|
|
|
|
|
|
|
| 559 |
- Report files are automatically named with the current date (YYYYMMDD format)
|
| 560 |
- The tool will skip any existing report files when processing
|
| 561 |
-
|
| 562 |
-
**Multiple File Formats:**
|
| 563 |
-
If you have files like:
|
| 564 |
-
- `01B17nivea47appvideo.mp4`
|
| 565 |
-
- `01B17nivea47appvideo.png`
|
| 566 |
-
|
| 567 |
-
Both will be included in the reports, but counted as 1 asset (not 2) in the summary statistics.
|
| 568 |
""")
|
|
|
|
| 12 |
generate_excel_report,
|
| 13 |
generate_filename_based_pdf_report_with_extensions,
|
| 14 |
ALL_ALLOWED_EXTENSIONS,
|
| 15 |
+
is_valid_file,
|
| 16 |
+
ALLOWED_IMAGE_EXTENSIONS
|
| 17 |
)
|
| 18 |
|
| 19 |
|
|
|
|
| 64 |
return Path(filename).stem
|
| 65 |
|
| 66 |
|
| 67 |
+
def get_original_folder_name(blocknummer, processed_files_folder):
|
| 68 |
+
"""Try to find the original folder name from Excel or folder structure"""
|
| 69 |
+
# Look for the Excel file to extract original folder names
|
| 70 |
+
excel_files = list(Path(processed_files_folder).glob("*IcAt*Overview*.xlsx"))
|
| 71 |
+
|
| 72 |
+
if excel_files:
|
| 73 |
+
try:
|
| 74 |
+
import pandas as pd
|
| 75 |
+
df = pd.read_excel(excel_files[0], sheet_name='Reordered')
|
| 76 |
+
# Find rows matching this blocknummer
|
| 77 |
+
matching_rows = df[df['Group'].astype(str) == blocknummer.lstrip('0')]
|
| 78 |
+
if not matching_rows.empty:
|
| 79 |
+
# Get the factorgroup value which contains the original folder name
|
| 80 |
+
factorgroup = str(matching_rows.iloc[0]['factor'])
|
| 81 |
+
# Extract folder name (remove blocknummer prefix if present)
|
| 82 |
+
folder_name = re.sub(r'^\d+', '', factorgroup)
|
| 83 |
+
return folder_name if folder_name else f"{blocknummer}Folder"
|
| 84 |
+
except Exception as e:
|
| 85 |
+
print(f"Could not extract folder name from Excel: {e}")
|
| 86 |
+
|
| 87 |
+
return f"{blocknummer}Folder"
|
| 88 |
+
|
| 89 |
+
|
| 90 |
def reconstruct_folder_structure(files_folder):
|
| 91 |
"""
|
| 92 |
Reconstruct the folder structure from parsed filenames.
|
| 93 |
Groups files by blocknummer (folder) and marke (brand).
|
| 94 |
+
Handles duplicate base filenames - keeps non-image format over image format.
|
| 95 |
"""
|
| 96 |
marken_set = set()
|
| 97 |
marken_index = {}
|
| 98 |
renamed_files_by_folder_and_marke = defaultdict(lambda: defaultdict(list))
|
| 99 |
file_to_factorgroup = {}
|
| 100 |
+
original_folder_names = {} # Map blocknummer to original folder name
|
| 101 |
|
| 102 |
+
# Track unique base filenames for counting and duplicate detection
|
| 103 |
+
unique_base_files = defaultdict(lambda: defaultdict(dict)) # folder -> base_filename -> {ext: file_path}
|
| 104 |
|
| 105 |
# Collect all valid files
|
| 106 |
parsed_files = []
|
|
|
|
| 131 |
else:
|
| 132 |
skipped_files.append(f"{file_path.name} (doesn't match naming convention)")
|
| 133 |
|
| 134 |
+
# Try to get original folder names
|
| 135 |
+
for parsed in parsed_files:
|
| 136 |
+
blocknummer = parsed['blocknummer']
|
| 137 |
+
if blocknummer not in original_folder_names:
|
| 138 |
+
original_folder_names[blocknummer] = get_original_folder_name(blocknummer, files_folder)
|
| 139 |
+
|
| 140 |
+
# Build structure with duplicate handling
|
| 141 |
for parsed in parsed_files:
|
| 142 |
marke = parsed['marke']
|
| 143 |
markennummer = parsed['markennummer']
|
| 144 |
blocknummer = parsed['blocknummer']
|
| 145 |
file_path = parsed['file_path']
|
| 146 |
+
ext = parsed['ext']
|
| 147 |
|
| 148 |
# Add to marken_set
|
| 149 |
marken_set.add(marke)
|
|
|
|
| 152 |
if marke not in marken_index:
|
| 153 |
marken_index[marke] = markennummer
|
| 154 |
|
| 155 |
+
# Use original folder name if found, otherwise use blocknummer
|
| 156 |
+
folder_name = original_folder_names.get(blocknummer, f"{blocknummer}Folder")
|
| 157 |
|
| 158 |
+
# Track files by base filename for duplicate detection
|
| 159 |
base_filename = get_base_filename_without_ext(file_path.name)
|
| 160 |
+
|
| 161 |
+
# Store file with its extension
|
| 162 |
+
unique_base_files[folder_name][base_filename][ext] = file_path
|
| 163 |
+
|
| 164 |
+
# Now process the deduplicated files
|
| 165 |
+
for folder_name in unique_base_files:
|
| 166 |
+
for base_filename, extensions_dict in unique_base_files[folder_name].items():
|
| 167 |
+
# If multiple extensions exist for same base filename
|
| 168 |
+
if len(extensions_dict) > 1:
|
| 169 |
+
# Priority: non-image formats over image formats
|
| 170 |
+
non_image_files = {ext: path for ext, path in extensions_dict.items()
|
| 171 |
+
if ext not in ALLOWED_IMAGE_EXTENSIONS}
|
| 172 |
+
|
| 173 |
+
if non_image_files:
|
| 174 |
+
# Use non-image format(s)
|
| 175 |
+
for ext, file_path in non_image_files.items():
|
| 176 |
+
parsed = parse_filename(file_path.name)
|
| 177 |
+
marke = parsed['marke']
|
| 178 |
+
renamed_files_by_folder_and_marke[folder_name][marke].append(
|
| 179 |
+
(file_path, file_path.name)
|
| 180 |
+
)
|
| 181 |
+
file_to_factorgroup[file_path.name] = folder_name
|
| 182 |
+
else:
|
| 183 |
+
# All are images, just pick one (first one)
|
| 184 |
+
ext, file_path = list(extensions_dict.items())[0]
|
| 185 |
+
parsed = parse_filename(file_path.name)
|
| 186 |
+
marke = parsed['marke']
|
| 187 |
+
renamed_files_by_folder_and_marke[folder_name][marke].append(
|
| 188 |
+
(file_path, file_path.name)
|
| 189 |
+
)
|
| 190 |
+
file_to_factorgroup[file_path.name] = folder_name
|
| 191 |
+
else:
|
| 192 |
+
# Only one extension, add it
|
| 193 |
+
ext, file_path = list(extensions_dict.items())[0]
|
| 194 |
+
parsed = parse_filename(file_path.name)
|
| 195 |
+
marke = parsed['marke']
|
| 196 |
+
renamed_files_by_folder_and_marke[folder_name][marke].append(
|
| 197 |
+
(file_path, file_path.name)
|
| 198 |
+
)
|
| 199 |
+
file_to_factorgroup[file_path.name] = folder_name
|
| 200 |
|
| 201 |
+
# Calculate unique counts after deduplication
|
| 202 |
+
unique_counts = {folder: len(unique_base_files[folder]) for folder in unique_base_files}
|
| 203 |
|
| 204 |
# Prepare debug info
|
| 205 |
debug_info = {
|
| 206 |
'total_files': total_files,
|
| 207 |
'parsed_files': len(parsed_files),
|
| 208 |
'skipped_files': skipped_files,
|
| 209 |
+
'unique_counts': unique_counts
|
| 210 |
}
|
| 211 |
|
| 212 |
return marken_set, renamed_files_by_folder_and_marke, marken_index, file_to_factorgroup, debug_info
|
|
|
|
| 271 |
except Exception as e:
|
| 272 |
return None, None, f"Error reading existing Excel file: {str(e)}"
|
| 273 |
|
| 274 |
+
# Reconstruct structure from filenames (with deduplication)
|
| 275 |
marken_set, renamed_files_by_folder_and_marke, marken_index, _, debug_info = reconstruct_folder_structure(files_folder)
|
| 276 |
|
| 277 |
if not marken_set:
|
|
|
|
| 299 |
# Parse to get blocknummer for new files
|
| 300 |
parsed = parse_filename(file_path.name)
|
| 301 |
if parsed:
|
| 302 |
+
blocknummer = parsed['blocknummer']
|
| 303 |
+
folder_name = get_original_folder_name(blocknummer, files_folder)
|
| 304 |
file_to_factorgroup[file_path.name] = folder_name
|
| 305 |
new_files_added += 1
|
| 306 |
print(f" ✨ NEW: {file_path.name} -> {folder_name}")
|
|
|
|
| 594 |
|
| 595 |
This tool regenerates PDF and Excel reports from a Tab 5 output folder that may contain manually added images.
|
| 596 |
|
| 597 |
+
**Key Features:**
|
| 598 |
+
- **Deduplication**: Files with same name but different extensions (e.g., video.png + video.mp4) are counted only ONCE
|
| 599 |
+
- **Priority**: Non-image formats (mp4, mov, gif, etc.) take priority over image formats when duplicates exist
|
| 600 |
+
- **Highlighting**: Non-image formats are highlighted in yellow in the Excel output
|
| 601 |
+
- **Original Folder Names**: Preserves actual folder names from your input, not just "17Folder"
|
| 602 |
+
|
| 603 |
**Use Case:**
|
| 604 |
1. You ran Tab 5 and got an output folder with images, PDF, and Excel reports
|
| 605 |
2. You manually added new images to that folder (following the same naming convention)
|
|
|
|
| 627 |
|
| 628 |
**Important Notes:**
|
| 629 |
- The tool preserves any manual folder structure changes you made in the Excel file
|
| 630 |
+
- Files with the same name but different extensions are handled intelligently:
|
| 631 |
+
- Non-image formats (mp4, mov, gif, etc.) take priority over images
|
| 632 |
+
- Only ONE file is counted and displayed (no duplicates)
|
| 633 |
+
- Non-image formats are highlighted in yellow in the Excel
|
| 634 |
- Report files are automatically named with the current date (YYYYMMDD format)
|
| 635 |
- The tool will skip any existing report files when processing
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 636 |
""")
|