Download ORCASat/Different/structure_tree_generator.py from 5PACE/5PACE3Dmodelsatellites: direct link, hf CLI and curl.
- Browser
- Download file 6.34 kB
-
https://huggingface.co/datasets/5PACE/5PACE3Dmodelsatellites/resolve/main/ORCASat/Different/structure_tree_generator.py
- Command line
-
hf download hf://datasets/5PACE/5PACE3Dmodelsatellites/ORCASat/Different/structure_tree_generator.py
-
curl -L -o structure_tree_generator.py https://huggingface.co/datasets/5PACE/5PACE3Dmodelsatellites/resolve/main/ORCASat/Different/structure_tree_generator.py
6.34 kB
| from pathlib import Path | |
| from datetime import datetime | |
| import os | |
| # ========================================== | |
| # KONFIGURACJA | |
| # ========================================== | |
| DEFAULT_FOLDER = r"C:\Users\Mateusz\Desktop\ORCASat" | |
| OUTPUT_NAME = "structure_tree_output.txt" | |
| def format_size(size): | |
| return f"{size:,}".replace(",", " ") + " B" | |
| def get_extension(path): | |
| extensions = "".join(path.suffixes) | |
| return extensions if extensions else "(brak rozszerzenia)" | |
| def get_date(timestamp): | |
| return datetime.fromtimestamp(timestamp).strftime( | |
| "%Y-%m-%d %H:%M:%S" | |
| ) | |
| def generate_report(folder_path): | |
| root = Path(folder_path).expanduser().absolute() | |
| if not root.is_dir(): | |
| print(f"BLAD: Folder nie istnieje: {root}") | |
| return | |
| output_file = root / OUTPUT_NAME | |
| tree = [f"{root.name}/"] | |
| details = [] | |
| errors = [] | |
| stats = { | |
| "directories": 0, | |
| "files": 0, | |
| "links": 0, | |
| "other": 0, | |
| "total_bytes": 0 | |
| } | |
| def sort_key(path): | |
| try: | |
| is_directory = path.is_dir() and not path.is_symlink() | |
| except OSError: | |
| is_directory = False | |
| return (not is_directory, path.name.casefold()) | |
| def scan_directory(current, prefix=""): | |
| try: | |
| entries = sorted( | |
| [ | |
| p for p in current.iterdir() | |
| if p != output_file | |
| ], | |
| key=sort_key | |
| ) | |
| except OSError as exc: | |
| message = f"Nie mozna odczytac: {current} ({exc})" | |
| errors.append(message) | |
| tree.append(prefix + "[BLAD ODCZYTU]") | |
| return | |
| for index, entry in enumerate(entries): | |
| is_last = index == len(entries) - 1 | |
| connector = "└── " if is_last else "├── " | |
| next_prefix = prefix + ( | |
| " " if is_last else "│ " | |
| ) | |
| try: | |
| metadata = entry.lstat() | |
| is_link = entry.is_symlink() | |
| is_directory = ( | |
| entry.is_dir() and not is_link | |
| ) | |
| is_file = ( | |
| entry.is_file() and not is_link | |
| ) | |
| relative = entry.relative_to(root) | |
| full_path = entry.absolute() | |
| size = metadata.st_size | |
| modified = get_date(metadata.st_mtime) | |
| if is_directory: | |
| element_type = "KATALOG" | |
| extension = "(nie dotyczy)" | |
| description = "[KATALOG]" | |
| stats["directories"] += 1 | |
| elif is_file: | |
| element_type = "PLIK" | |
| extension = get_extension(entry) | |
| description = ( | |
| f"[PLIK | {extension} | " | |
| f"{format_size(size)}]" | |
| ) | |
| stats["files"] += 1 | |
| stats["total_bytes"] += size | |
| elif is_link: | |
| element_type = "DOWIAZANIE" | |
| extension = get_extension(entry) | |
| description = "[DOWIAZANIE]" | |
| stats["links"] += 1 | |
| else: | |
| element_type = "INNY" | |
| extension = get_extension(entry) | |
| description = "[INNY]" | |
| stats["other"] += 1 | |
| tree.append( | |
| f"{prefix}{connector}" | |
| f"{entry.name} {description}" | |
| ) | |
| record = [ | |
| "=" * 75, | |
| f"Nazwa: {entry.name}", | |
| f"Typ: {element_type}", | |
| f"Rozszerzenie: {extension}", | |
| f"Sciezka pelna: {full_path}", | |
| f"Sciezka wzgledna:{relative}", | |
| f"Ostatnia zmiana: {modified}" | |
| ] | |
| if is_file: | |
| record.append( | |
| f"Rozmiar: {format_size(size)}" | |
| ) | |
| if is_link: | |
| record.append( | |
| f"Cel dowiazania: {os.readlink(entry)}" | |
| ) | |
| details.extend(record) | |
| details.append("") | |
| if is_directory: | |
| scan_directory(entry, next_prefix) | |
| except OSError as exc: | |
| message = f"{entry}: {exc}" | |
| errors.append(message) | |
| tree.append( | |
| f"{prefix}{connector}" | |
| f"{entry.name} [BLAD]" | |
| ) | |
| print("Analizowanie struktury folderu...") | |
| scan_directory(root) | |
| report = [ | |
| "RAPORT STRUKTURY KATALOGU", | |
| "=" * 75, | |
| f"Folder glowny: {root}", | |
| f"Data raportu: {datetime.now():%Y-%m-%d %H:%M:%S}", | |
| "", | |
| "PODSUMOWANIE", | |
| "-" * 75, | |
| f"Liczba katalogow: {stats['directories']}", | |
| f"Liczba plikow: {stats['files']}", | |
| f"Liczba dowiazan: {stats['links']}", | |
| f"Inne elementy: {stats['other']}", | |
| f"Laczny rozmiar: {format_size(stats['total_bytes'])}", | |
| "", | |
| "DRZEWO KATALOGOW", | |
| "=" * 75, | |
| *tree, | |
| "", | |
| "SZCZEGOLOWY WYKAZ ELEMENTOW", | |
| "=" * 75, | |
| *details, | |
| "", | |
| "BLEDY ODCZYTU", | |
| "=" * 75, | |
| *(errors if errors else ["Brak bledow."]), | |
| "" | |
| ] | |
| # Zapis w trybie nadpisywania. | |
| # UTF-8 BOM zapewnia poprawne otwieranie w Notatniku. | |
| with output_file.open("w", encoding="utf-8-sig") as file: | |
| file.write("\n".join(report)) | |
| print("\nZAKONCZONO") | |
| print(f"Zapisano: {output_file}") | |
| print(f"Katalogi: {stats['directories']}") | |
| print(f"Pliki: {stats['files']}") | |
| print(f"Bledy: {len(errors)}") | |
| if __name__ == "__main__": | |
| folder = input( | |
| f"Podaj sciezke folderu [{DEFAULT_FOLDER}]: " | |
| ).strip().strip('"') | |
| if not folder: | |
| folder = DEFAULT_FOLDER | |
| generate_report(folder) | |