Initial commit

This commit is contained in:
xixu-me committed 2025-07-08 18:03:18 +08:00
commit 7bf2b23738
10 files changed
+945

No files matched your search

+101
View File
@@ -0,0 +1,101 @@
# Examples
This directory contains example scripts demonstrating various ways to use the Linux ISO downloader.
## Available Examples
### 1. `download_specific.py`
Download only specific distributions (Ubuntu and Fedora in this example).
```bash
python examples/download_specific.py
```
**Features:**
- Downloads only Ubuntu and Fedora ISOs
- Uses fewer parallel workers (2) for demonstration
- Saves files to `./examples_output/`
### 2. `create_custom_categories.py`
Demonstrates how to create custom URL files for different categories of Linux distributions.
```bash
# Create category files and download lightweight distributions
python examples/create_custom_categories.py
# Download enterprise distributions
python examples/create_custom_categories.py --enterprise
# Show help
python examples/create_custom_categories.py --help
```
**Features:**
- Creates custom URL files for different distribution categories
- Lightweight distributions (Arch-based): Arch Linux, EndeavourOS, Manjaro
- Enterprise distributions (RHEL-based): AlmaLinux, Rocky Linux, Oracle Linux
- Organizes downloads into category-specific subdirectories
## Output Structure
When running examples, files are organized as follows:
```text
examples_output/
├── lightweight/ # From create_custom_categories.py
│ ├── archlinux-x86_64.iso
│ ├── EndeavourOS-Mercury-Neo-2025.03.19.iso
│ └── manjaro-gnome-25.0.4-250623-linux612.iso
├── enterprise/ # From create_custom_categories.py --enterprise
│ ├── AlmaLinux-10.0-x86_64-dvd.iso
│ ├── Rocky-10.0-x86_64-dvd1.iso
│ └── OracleLinux-R10-U0-x86_64-dvd.iso
└── ubuntu-24.04.2-desktop-amd64.iso # From download_specific.py
└── Fedora-Workstation-Live-42-1.1.x86_64.iso
```
## Custom URL Files
The `create_custom_categories.py` script generates these URL files:
- `examples/lightweight_distros.txt` - Arch-based distributions
- `examples/enterprise_distros.txt` - Enterprise Linux distributions
You can modify these files or create your own custom URL files to download specific sets of distributions.
## Tips
1. **Start Small**: Begin with the `download_specific.py` example to understand the basic usage
2. **Custom Categories**: Use `create_custom_categories.py` as a template for your own categorization needs
3. **Modify URLs**: Edit the generated URL files in the `examples/` directory to customize which distributions to download
4. **Output Directories**: Each example uses different output directories to keep downloads organized
## Creating Your Own Examples
Use these examples as templates to create your own custom download scripts:
1. Import the `ISODownloader` class from `download_isos`
2. Define your list of URLs
3. Create a downloader instance with your preferred settings
4. Call `download_all()` with your URLs
```python
from download_isos import ISODownloader
# Your custom URLs
urls = ["https://example.com/distro.iso"]
# Create downloader
downloader = ISODownloader(
output_dir="./my_downloads",
max_workers=3,
retry_attempts=5
)
# Download
successful, failed, results = downloader.download_all(urls)
```
+115
View File
@@ -0,0 +1,115 @@
#!/usr/bin/env python3
"""
Example script demonstrating how to create custom URL files and download
specific sets of distributions.
This example shows how to create different categories of Linux distributions.
"""
import os
from download_isos import ISODownloader
def create_lightweight_distros():
"""Create a URL file for lightweight Linux distributions."""
lightweight_urls = [
"https://geo.mirror.pkgbuild.com/iso/2025.07.01/archlinux-x86_64.iso",
"https://mirrors.gigenet.com/endeavouros/iso/EndeavourOS_Mercury-Neo-2025.03.19.iso",
"https://download.manjaro.org/gnome/25.0.4/manjaro-gnome-25.0.4-250623-linux612.iso",
]
with open("examples/lightweight_distros.txt", "w") as f:
for url in lightweight_urls:
f.write(url + "\n")
print("✅ Created lightweight_distros.txt")
def create_enterprise_distros():
"""Create a URL file for enterprise Linux distributions."""
enterprise_urls = [
"https://repo.almalinux.org/almalinux/10/isos/x86_64/AlmaLinux-10.0-x86_64-dvd.iso",
"https://download.rockylinux.org/pub/rocky/10/isos/x86_64/Rocky-10.0-x86_64-dvd1.iso",
"https://yum.oracle.com/ISOS/OracleLinux/OL10/u0/x86_64/OracleLinux-R10-U0-x86_64-dvd.iso",
]
with open("examples/enterprise_distros.txt", "w") as f:
for url in enterprise_urls:
f.write(url + "\n")
print("✅ Created enterprise_distros.txt")
def download_category(url_file, category_name):
"""Download ISOs from a specific category URL file."""
print(f"\n🐧 Downloading {category_name} distributions...")
# Read URLs from the category file
try:
with open(url_file) as f:
urls = [line.strip() for line in f if line.strip()]
except FileNotFoundError:
print(f"❌ Error: {url_file} not found!")
return
if not urls:
print(f"❌ No URLs found in {url_file}")
return
print(f"📋 Found {len(urls)} URLs to download")
# Create output directory based on category
output_dir = f"./examples_output/{category_name.lower().replace(' ', '_')}"
# Create downloader instance
downloader = ISODownloader(output_dir=output_dir, max_workers=3, retry_attempts=3)
# Download the files
successful, failed, results = downloader.download_all(urls)
print(f"\n✅ Successfully downloaded: {successful} files")
if failed > 0:
print(f"❌ Failed downloads: {failed}")
for result in results:
print(f" - {result}")
print(f"\n📂 Files saved to: {os.path.abspath(output_dir)}")
def main():
"""Main function to demonstrate custom URL file creation and usage."""
print("🔧 Creating custom URL files for different distribution categories...")
# Create the examples directory if it doesn't exist
os.makedirs("examples", exist_ok=True)
# Create category-specific URL files
create_lightweight_distros()
create_enterprise_distros()
print("\n📋 Available categories:")
print(" 1. Lightweight distributions (Arch-based)")
print(" 2. Enterprise distributions (RHEL-based)")
# Example: Download lightweight distributions
print("\n" + "=" * 50)
download_category("examples/lightweight_distros.txt", "Lightweight")
print("\n" + "=" * 50)
print("💡 To download enterprise distributions, run:")
print(" python examples/create_custom_categories.py --enterprise")
if __name__ == "__main__":
import sys
if "--enterprise" in sys.argv:
download_category("examples/enterprise_distros.txt", "Enterprise")
elif "--help" in sys.argv or "-h" in sys.argv:
print("Usage:")
print(" python examples/create_custom_categories.py")
print(" # Create files and download lightweight")
print(" python examples/create_custom_categories.py --enterprise")
print(" # Download enterprise distributions")
else:
main()
+42
View File
@@ -0,0 +1,42 @@
#!/usr/bin/env python3
"""
Example script demonstrating how to use the ISO downloader for specific distributions.
This script shows how to download only Ubuntu and Fedora ISOs.
"""
import os
from download_isos import ISODownloader
def main():
# Define specific URLs for Ubuntu and Fedora
ubuntu_fedora_urls = [
"https://releases.ubuntu.com/noble/ubuntu-24.04.2-desktop-amd64.iso",
"https://download.fedoraproject.org/pub/fedora/linux/releases/42/Workstation/x86_64/iso/Fedora-Workstation-Live-42-1.1.x86_64.iso",
]
print("🐧 Downloading Ubuntu and Fedora ISOs...")
print("📁 Output directory: ./examples_output")
# Create downloader instance
downloader = ISODownloader(
output_dir="./examples_output",
max_workers=2, # Use fewer workers for this example
retry_attempts=3,
)
# Download the files
successful, failed, results = downloader.download_all(ubuntu_fedora_urls)
print(f"\n✅ Successfully downloaded: {successful} files")
if failed > 0:
print(f"❌ Failed downloads: {failed}")
for result in results:
print(f" - {result}")
print(f"\n📂 Files saved to: {os.path.abspath('./examples_output')}")
if __name__ == "__main__":
main()