wpsrt/wpsrt/cli.py

36 lines
929 B
Python
Raw Permalink Normal View History

2022-05-30 08:13:47 +02:00
from pathlib import Path
import click
2022-05-30 09:12:38 +02:00
from .wallpapers import move_wallpaper, scan_directory
2022-05-30 08:13:47 +02:00
@click.command()
@click.argument(
2022-05-30 09:12:38 +02:00
"source",
type=click.Path(exists=True, file_okay=False, dir_okay=True),
default=Path("~/Pictures/wallpapers").expanduser(),
2022-05-30 08:13:47 +02:00
)
2022-05-30 09:12:38 +02:00
@click.argument(
"target",
type=click.Path(exists=False, file_okay=False, dir_okay=True),
default=Path("~/Pictures/wallpapers/by-resolution").expanduser(),
)
def sort(source: Path, target: Path):
2022-05-30 09:13:28 +02:00
source = Path(source)
target = Path(target)
2022-05-30 09:12:38 +02:00
if not target.exists():
target.mkdir()
for wallpaper in scan_directory(source):
filename, (xres, yres) = wallpaper
if filename.is_relative_to(target):
continue
new_filename = move_wallpaper(
filename, target / f"{xres}x{yres}/{filename.name}"
)
click.echo(new_filename)
2022-05-30 08:13:47 +02:00
if __name__ == "__main__":
2022-05-30 09:12:38 +02:00
sort(None, None)