Spaces:
Sleeping
Sleeping
Gnanashri Kota Venkatesh commited on
Update helper.py
Browse files
helper.py
CHANGED
|
@@ -18,12 +18,21 @@ from reportlab.platypus import (
|
|
| 18 |
)
|
| 19 |
import openpyxl
|
| 20 |
|
| 21 |
-
|
| 22 |
-
ALLOWED_IMAGE_EXTENSIONS = {'.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff', '.webp'}
|
| 23 |
-
ALLOWED_TEXT_EXTENSIONS = {'.txt', '.md', '.csv'}
|
| 24 |
-
ALLOWED_VIDEO_EXTENSIONS = {'.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv', '.webm', '.m4v', '.3gp', '.ogv'}
|
| 25 |
-
ALLOWED_AUDIO_EXTENSIONS = {'.mp3', '.wav', '.aac', '.flac', '.ogg', '.m4a', '.wma'}
|
| 26 |
-
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 27 |
|
| 28 |
# Helper functions from both files
|
| 29 |
def extract_zip_to_temp(uploaded_file):
|
|
@@ -146,14 +155,29 @@ def process_files(input_folder, marken_index, output_root):
|
|
| 146 |
|
| 147 |
return renamed_files_by_folder_and_marke, file_to_factorgroup
|
| 148 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 149 |
def generate_excel_report(output_folder: Path, marken_index: dict, file_to_factorgroup: dict):
|
|
|
|
| 150 |
final_excel_path = output_folder / "IcAt_Overview_Final.xlsx"
|
| 151 |
|
| 152 |
nummer_zu_marke = {v: k for k, v in marken_index.items()}
|
| 153 |
data = []
|
|
|
|
| 154 |
for file in sorted(output_folder.iterdir()):
|
| 155 |
-
|
|
|
|
| 156 |
name = file.stem
|
|
|
|
|
|
|
|
|
|
| 157 |
match = re.match(r"(\d{2})B(\d{2})([a-z0-9]+)", name, re.IGNORECASE)
|
| 158 |
if match:
|
| 159 |
markennummer, blocknummer, marke = match.groups()
|
|
@@ -163,10 +187,13 @@ def generate_excel_report(output_folder: Path, marken_index: dict, file_to_facto
|
|
| 163 |
factorgroup = file_to_factorgroup.get(file.name, f"{blocknummer}Unknown")
|
| 164 |
factorgroup = factorgroup.replace('_', '') # Remove all underscores
|
| 165 |
|
|
|
|
|
|
|
|
|
|
| 166 |
data.append({
|
| 167 |
"factor": factor,
|
| 168 |
"factorgroup": factorgroup,
|
| 169 |
-
"ID":
|
| 170 |
})
|
| 171 |
|
| 172 |
df_assets = pd.DataFrame(data, columns=["factor", "factorgroup", "ID"])
|
|
@@ -193,6 +220,7 @@ def generate_excel_report(output_folder: Path, marken_index: dict, file_to_facto
|
|
| 193 |
|
| 194 |
df_reordered = pd.DataFrame(reordered_data, columns=["Group", "factor", "factorgroup", "ID"])
|
| 195 |
df_reordered = df_reordered.sort_values(by='Group', ascending=True).reset_index(drop=True)
|
|
|
|
| 196 |
with pd.ExcelWriter(final_excel_path, engine='openpyxl') as writer:
|
| 197 |
df_assets.to_excel(writer, index=False, sheet_name="Assets")
|
| 198 |
df_reordered.to_excel(writer, index=False, sheet_name="Reordered")
|
|
@@ -1126,4 +1154,4 @@ def generate_two_section_pdf_report(input_folder, erste_marke=None):
|
|
| 1126 |
pdf_buffer.seek(0)
|
| 1127 |
return pdf_buffer, None
|
| 1128 |
except Exception as e:
|
| 1129 |
-
return None, f"Error generating PDF: {str(e)}"
|
|
|
|
| 18 |
)
|
| 19 |
import openpyxl
|
| 20 |
|
| 21 |
+
|
| 22 |
+
ALLOWED_IMAGE_EXTENSIONS = {'.jpg', '.jpeg', '.png', '.bmp', '.gif', '.tiff', '.tif', '.webp', '.svg', '.ico', '.heic', '.heif', '.raw'}
|
| 23 |
+
ALLOWED_TEXT_EXTENSIONS = {'.txt', '.md', '.csv', '.doc', '.docx', '.pdf', '.rtf', '.odt', '.tex'}
|
| 24 |
+
ALLOWED_VIDEO_EXTENSIONS = {'.mp4', '.avi', '.mov', '.wmv', '.flv', '.mkv', '.webm', '.m4v', '.3gp', '.ogv', '.mpg', '.mpeg', '.vob', '.mts', '.m2ts'}
|
| 25 |
+
ALLOWED_AUDIO_EXTENSIONS = {'.mp3', '.wav', '.aac', '.flac', '.ogg', '.m4a', '.wma', '.opus', '.aiff', '.ape', '.alac'}
|
| 26 |
+
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 |
|
| 34 |
+
ALLOWED_ARCHIVE_EXTENSIONS | ALLOWED_CODE_EXTENSIONS |
|
| 35 |
+
ALLOWED_DATA_EXTENSIONS | ALLOWED_OTHER_EXTENSIONS)
|
| 36 |
|
| 37 |
# Helper functions from both files
|
| 38 |
def extract_zip_to_temp(uploaded_file):
|
|
|
|
| 155 |
|
| 156 |
return renamed_files_by_folder_and_marke, file_to_factorgroup
|
| 157 |
|
| 158 |
+
def is_valid_file(file_path):
|
| 159 |
+
"""Check if file should be processed - accept ALL files except hidden/system files"""
|
| 160 |
+
filename = Path(file_path).name
|
| 161 |
+
# Skip hidden files and system files
|
| 162 |
+
if filename.startswith('.') or filename.startswith('~') or filename == 'Thumbs.db':
|
| 163 |
+
return False
|
| 164 |
+
# Accept all other files
|
| 165 |
+
return True
|
| 166 |
+
|
| 167 |
def generate_excel_report(output_folder: Path, marken_index: dict, file_to_factorgroup: dict):
|
| 168 |
+
"""Generate Excel report - ACCEPT ALL FILE TYPES"""
|
| 169 |
final_excel_path = output_folder / "IcAt_Overview_Final.xlsx"
|
| 170 |
|
| 171 |
nummer_zu_marke = {v: k for k, v in marken_index.items()}
|
| 172 |
data = []
|
| 173 |
+
|
| 174 |
for file in sorted(output_folder.iterdir()):
|
| 175 |
+
# Process ALL files, not just specific extensions
|
| 176 |
+
if file.is_file() and is_valid_file(file):
|
| 177 |
name = file.stem
|
| 178 |
+
# Get file extension for display
|
| 179 |
+
file_ext = file.suffix.lower() if file.suffix else ''
|
| 180 |
+
|
| 181 |
match = re.match(r"(\d{2})B(\d{2})([a-z0-9]+)", name, re.IGNORECASE)
|
| 182 |
if match:
|
| 183 |
markennummer, blocknummer, marke = match.groups()
|
|
|
|
| 187 |
factorgroup = file_to_factorgroup.get(file.name, f"{blocknummer}Unknown")
|
| 188 |
factorgroup = factorgroup.replace('_', '') # Remove all underscores
|
| 189 |
|
| 190 |
+
# Include file extension in the ID column
|
| 191 |
+
id_with_ext = name
|
| 192 |
+
|
| 193 |
data.append({
|
| 194 |
"factor": factor,
|
| 195 |
"factorgroup": factorgroup,
|
| 196 |
+
"ID": id_with_ext # Now includes extension
|
| 197 |
})
|
| 198 |
|
| 199 |
df_assets = pd.DataFrame(data, columns=["factor", "factorgroup", "ID"])
|
|
|
|
| 220 |
|
| 221 |
df_reordered = pd.DataFrame(reordered_data, columns=["Group", "factor", "factorgroup", "ID"])
|
| 222 |
df_reordered = df_reordered.sort_values(by='Group', ascending=True).reset_index(drop=True)
|
| 223 |
+
|
| 224 |
with pd.ExcelWriter(final_excel_path, engine='openpyxl') as writer:
|
| 225 |
df_assets.to_excel(writer, index=False, sheet_name="Assets")
|
| 226 |
df_reordered.to_excel(writer, index=False, sheet_name="Reordered")
|
|
|
|
| 1154 |
pdf_buffer.seek(0)
|
| 1155 |
return pdf_buffer, None
|
| 1156 |
except Exception as e:
|
| 1157 |
+
return None, f"Error generating PDF: {str(e)}"
|