From 09a64ec5d887c8f9f09a835df7b3c376f7b19de2 Mon Sep 17 00:00:00 2001 From: ajurna Date: Tue, 26 May 2020 10:34:29 +0100 Subject: [PATCH] added console output to scan_comics.py options. --- Pipfile | 1 + Pipfile.lock | 26 +++++++++++++++++++++++- comic/management/commands/scan_comics.py | 22 +++++++++++++++++--- 3 files changed, 45 insertions(+), 4 deletions(-) diff --git a/Pipfile b/Pipfile index 9c830b6..1f3c24f 100644 --- a/Pipfile +++ b/Pipfile @@ -16,6 +16,7 @@ django-bootstrap4 = "*" dj-database-url = "*" pypdf4 = "*" python-dotenv = "*" +loguru = "*" [requires] python_version = "3.8" diff --git a/Pipfile.lock b/Pipfile.lock index 5d9443a..2998088 100644 --- a/Pipfile.lock +++ b/Pipfile.lock @@ -1,7 +1,7 @@ { "_meta": { "hash": { - "sha256": "24dc60dfd360e3b070182ba6e7d35553ca1714d613d316a3b04f7ca6b1415ee4" + "sha256": "25036caa93a668b5386d54417c22afd2bb42bbdf6d8fcb9828a278eefd381269" }, "pipfile-spec": 6, "requires": { @@ -45,6 +45,14 @@ ], "version": "==3.0.4" }, + "colorama": { + "hashes": [ + "sha256:7d73d2a99753107a36ac6b455ee49046802e59d9d076ef8e47b61499fa29afff", + "sha256:e96da0d330793e2cb9485e9ddfd918d456036c7149416295932478192f4436a1" + ], + "markers": "sys_platform == 'win32'", + "version": "==0.4.3" + }, "dj-database-url": { "hashes": [ "sha256:4aeaeb1f573c74835b0686a2b46b85990571159ffc21aa57ecd4d1e1cb334163", @@ -92,6 +100,14 @@ ], "version": "==2.9" }, + "loguru": { + "hashes": [ + "sha256:1e0e6ff59be5e22f863d909ca989e34bb14c21b374f6af45281e603d003dbb96", + "sha256:4688d9e1f31d70e1ec7ccce5305967bc28f377eb1048d009108c11faebe05bcf" + ], + "index": "pypi", + "version": "==0.5.0" + }, "pypdf4": { "hashes": [ "sha256:7c932441146d205572f96254d53c79ea2c30c9e11df55a5cf87e056c7b3d7f89" @@ -141,6 +157,14 @@ "sha256:88206b0eb87e6d677d424843ac5209e3fb9d0190d0ee169599165ec25e9d9115" ], "version": "==1.25.9" + }, + "win32-setctime": { + "hashes": [ + "sha256:568fd636c68350bcc54755213fe01966fe0a6c90b386c0776425944a0382abef", + "sha256:b47e5023ec7f0b4962950902b15bc56464a380d869f59d27dbf9ab423b23e8f9" + ], + "markers": "sys_platform == 'win32'", + "version": "==1.0.1" } }, "develop": { diff --git a/comic/management/commands/scan_comics.py b/comic/management/commands/scan_comics.py index d2df2ca..691a975 100644 --- a/comic/management/commands/scan_comics.py +++ b/comic/management/commands/scan_comics.py @@ -1,5 +1,6 @@ import os from os.path import isdir +from loguru import logger from django.core.management.base import BaseCommand @@ -13,10 +14,21 @@ class Command(BaseCommand): super().__init__() self.base_dir = Setting.objects.get(name="BASE_DIR").value - def handle(self, *args, **options): - self.scan_directory() + def add_arguments(self, parser): + # Positional arguments + parser.add_argument('poll_ids', nargs='+', type=int) - def scan_directory(self, directory=False): + # Named (optional) arguments + parser.add_argument( + '--out', + action='store_true', + help='Output to console', + ) + + def handle(self, *args, **options): + self.scan_directory(options=options) + + def scan_directory(self, directory=False, **options): """ @@ -35,6 +47,8 @@ class Command(BaseCommand): book.delete() for file in os.listdir(comic_dir): if isdir(os.path.join(comic_dir, file)): + if options['out']: + logger.info(f"Scanning Directory {file}") if directory: next_directory, created = Directory.objects.get_or_create(name=file, parent=directory) else: @@ -43,6 +57,8 @@ class Command(BaseCommand): next_directory.save() self.scan_directory(next_directory) else: + if options['out']: + logger.info(f"Scanning File {file}") try: if directory: book = ComicBook.objects.get(file_name=file, directory=directory)