A utility package with various file and directory management features.
Project description
Multipurpose Resource Automation(MPRA) Package
Overview
The mpra package offers a variety of utility functions to manage files and directories, such as checking disk usage, organizing files by extension, monitoring directories, and more.
Features
Disk Usage Checker
Function: disk_stats(directory_path)
Description: This function takes a directory path as input and returns the total, used, and free disk space in gigabytes.
Parameters:
directory_path(str): The path of the directory to check.
Returns:
- Total disk space, used space, and free space in gigabytes.
Example:
mpra.disk_stats('/path/to/directory')
File Organizer
Function: organize_files(directory_path)
Description: This function organizes files in the specified directory into subdirectories based on file extensions.
Parameters:
directory_path(str): The path of the directory to organize.
Example:
mpra.organize_files('/path/to/directory')
Auto Categorize Files
Function: auto_categorize_files(directory_path)
Description: This function automatically organizes uncategorized files into an 'Others' folder. Files that match known categories (Images, Videos, Audio, Documents, Spreadsheets, Presentations, Archives, Data, 3D Models, Fonts) are left in place. Directories remain completely intact.
Parameters:
directory_path(str): The path of the directory to auto-categorize.
Example:
mpra.auto_categorize_files('/path/to/directory')
Directory Monitor
Function: monitor_directory(directory_path)
Description: This function monitors a directory for new files and prints a message each time a new file is added.
Parameters:
directory_path(str): The directory to monitor.
Example:
mpra.monitor_directory('/path/to/directory')
File Backup
Function: backup_files(source_directory, destination_directory)
Description: This function copies all files from the source directory to the destination directory.
Parameters:
source_directory(str): The path of the directory to copy files from.destination_directory(str): The path of the directory to copy files to.
Example:
mpra.backup_files('/source/directory', '/destination/directory')
Batch Rename Files
Function: batch_rename(directory_path, prefix=None, suffix=None)
Description: This function renames all files in a directory by adding a prefix or suffix.
Parameters:
directory_path(str): The path of the directory containing the files.prefix(str, optional): The prefix to add to each file name.suffix(str, optional): The suffix to add to each file name.
Example:
mpra.batch_rename('/path/to/directory', prefix='backup_')
System Command Runner
Function: run_command(command)
Description: This function takes a system command as input and executes it. It returns the command's output.
Parameters:
command(str): The system command to execute.
Example:
mpra.run_command('ls -la')
Delete Empty Directories
Function: delete_empty_dirs(directory_path)
Description: This function recursively searches through a directory and deletes all empty subdirectories.
Parameters:
directory_path(str): The directory to clean up.
Example:
mpra.delete_empty_dirs('/path/to/directory')
File Size Filter
Function: filter_files_by_size(directory_path, min_size_bytes)
Description: This function lists all files in a directory that are larger than a specified size.
Parameters:
directory_path(str): The path of the directory to search.min_size_bytes(int): The minimum file size (in bytes) to filter.
Example:
mpra.filter_files_by_size('/path/to/directory', min_size_bytes=1000000)
Log File Creator
Function: create_log(directory_path)
Description: This function generates a log file in the specified directory, logging the current date and time each time the script runs.
Parameters:
directory_path(str): The directory where the log file will be created.
Example:
mpra.create_log('/path/to/directory')
Generate Comprehensive File Report
Function: generate_file_report(directory_path, output_path=None, recursive=False)
Description: This function extracts comprehensive metadata from all files in a directory and generates a professional Excel report with detailed information including file properties, EXIF data, audio metadata, and more.
Parameters:
directory_path(str): The directory to scan for files.output_path(str, optional): Path for the output Excel file. Default:directory_path/file_report.xlsxrecursive(bool, optional): If True, scan subdirectories recursively. Default: False
Report Contents:
- File Report Sheet: 35+ columns including:
- Basic Info: File name, extension, category, MIME type, size, dates, file attributes
- File Hash: MD5 hash for integrity checking and duplicate detection
- Image Metadata: Width, height, color mode, DPI (requires
Pillow) - EXIF Data: Camera make/model, date taken, ISO, aperture, shutter speed, focal length
- GPS Data: Latitude, longitude coordinates (extracted from EXIF)
- Audio Metadata: Duration, bitrate, sample rate, channels, artist, album, title (requires
mutagen) - Clickable hyperlinks to files and full paths
- Summary Sheet: Directory statistics, file count, category breakdown with counts and sizes
Examples:
import mpraGenerate report in the same directory
mpra.generate_file_report(r'C:\Users\Pictures')
Custom output path
mpra.generate_file_report(r'C:\Users\Pictures', output_path=r'C:\Reports\my_report.xlsx')
Include subdirectories
mpra.generate_file_report(r'D:\Data', recursive=True)
<p><strong>Optional Dependencies for Full Metadata:</strong></p>
<pre><code># For image EXIF data extraction
pip install Pillow
For audio metadata extraction
pip install mutagen
Or install both at once
pip install mpra[excel]
© 2024 MPRA Documentation. All rights reserved.
Usage
import mpra
# ===== Basic File Operations =====
# Check disk usage
mpra.disk_stats("/path/to/directory")
# Organize files by extension (.jpg, .txt, .pdf, etc.)
mpra.organize_files("/path/to/directory")
# Auto-categorize uncategorized files only (leaves known categories intact)
mpra.auto_categorize_files("/path/to/directory")
# ===== Directory Monitoring =====
# Monitor directory for new files
mpra.monitor_directory("/path/to/directory")
# ===== File Management =====
# Backup files
mpra.backup_files("/source", "/destination")
# Batch rename files with prefix/suffix
mpra.batch_rename("/path/to/directory", prefix="backup_")
# Delete empty subdirectories
mpra.delete_empty_dirs("/path/to/directory")
# Filter files by size (list files larger than 1MB)
mpra.filter_files_by_size("/path/to/directory", min_size_bytes=1000000)
# Create a log file in directory
mpra.create_log("/path/to/directory")
# ===== Advanced: Generate Comprehensive File Report =====
# Generate Excel report with all file metadata
mpra.generate_file_report(r"C:\Users\Pictures")
# Generate with custom output path
mpra.generate_file_report(r"C:\Data", output_path=r"C:\Reports\report.xlsx")
# Include subdirectories in the scan
mpra.generate_file_report(r"D:\Projects", recursive=True)
# Run a system command
mpra.run_command("dir /s")
Installation
# Basic installation
pip install mpra
# With Excel report support
pip install mpra[excel]
# With full metadata extraction (images and audio)
pip install openpyxl Pillow mutagen
File Categories
The auto_categorize_files() function supports these categories:
- Images: JPG, PNG, GIF, BMP, SVG, WEBP, HEIC, RAW, PSD, AI, EPS, AVIF, and 20+ more
- Videos: MP4, AVI, MKV, MOV, FLV, WMV, WEBM, 3GP, MTS, and more
- Audio: MP3, WAV, FLAC, AAC, OGG, WMA, M4A, OPUS, DSD, and more
- Documents: PDF, DOC, DOCX, TXT, RTF, ODT, LaTeX, Markdown, and more
- Spreadsheets: XLSX, XLS, CSV, TSV, ODS, NUMBERS
- Presentations: PPT, PPTX, ODP, KEY
- Archives: ZIP, RAR, 7Z, TAR, GZ, BZ2, ISO, XZ, and more
- Data: JSON, XML, YAML, TOML, SQL, SQLite, Parquet, HDF5, and more
- 3D Models: OBJ, FBX, GLTF, BLEND, STL, STEP, IGES, USDZ, and more
- Fonts: TTF, OTF, WOFF, EOT, PFM, and more
- Others: Any unrecognized file types
Requirements
- Python 3.6+
- openpyxl (for Excel report generation)
- Pillow (optional, for image EXIF metadata extraction)
- mutagen (optional, for audio metadata extraction)
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mpra-0.2.1.tar.gz.
File metadata
- Download URL: mpra-0.2.1.tar.gz
- Upload date:
- Size: 15.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
af846d556a0db017fa1b6079be6e09e7d18ce504f72b2ee60858e0411ee17238
|
|
| MD5 |
726329ee1e343f33a26da04e7a33d867
|
|
| BLAKE2b-256 |
5ef241a0ca1688c7bad912811520d268e58ff7671eaf551f355a7a8a8c7a52c7
|
Provenance
The following attestation bundles were made for mpra-0.2.1.tar.gz:
Publisher:
main.yml on ManojPennada/mpra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mpra-0.2.1.tar.gz -
Subject digest:
af846d556a0db017fa1b6079be6e09e7d18ce504f72b2ee60858e0411ee17238 - Sigstore transparency entry: 942026714
- Sigstore integration time:
-
Permalink:
ManojPennada/mpra@7744e97c5a8a35584f1aa0632ff17d516811fd30 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/ManojPennada
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@7744e97c5a8a35584f1aa0632ff17d516811fd30 -
Trigger Event:
push
-
Statement type:
File details
Details for the file mpra-0.2.1-py3-none-any.whl.
File metadata
- Download URL: mpra-0.2.1-py3-none-any.whl
- Upload date:
- Size: 12.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d095929501c6798b18335ff82cc14a6b0d9e145c8470d07995c21781fce5b2a8
|
|
| MD5 |
3afd18b4ccb38bf151616362d1d97ca8
|
|
| BLAKE2b-256 |
8b7a3644552419c31d1384374b0419fb2f52ab9e6e28dd021480bb727a32e2a7
|
Provenance
The following attestation bundles were made for mpra-0.2.1-py3-none-any.whl:
Publisher:
main.yml on ManojPennada/mpra
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mpra-0.2.1-py3-none-any.whl -
Subject digest:
d095929501c6798b18335ff82cc14a6b0d9e145c8470d07995c21781fce5b2a8 - Sigstore transparency entry: 942026719
- Sigstore integration time:
-
Permalink:
ManojPennada/mpra@7744e97c5a8a35584f1aa0632ff17d516811fd30 -
Branch / Tag:
refs/tags/v0.2.1 - Owner: https://github.com/ManojPennada
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
main.yml@7744e97c5a8a35584f1aa0632ff17d516811fd30 -
Trigger Event:
push
-
Statement type: