From ef64100d8f78f0f6efdcd002c4f4fed538c25fe8 Mon Sep 17 00:00:00 2001 From: simon Date: Sat, 18 Sep 2021 20:02:54 +0700 Subject: [PATCH] flake8 and isort linting --- tubearchivist/config/settings.py | 10 +++---- tubearchivist/config/urls.py | 2 +- tubearchivist/home/src/download.py | 8 +++--- tubearchivist/home/src/helper.py | 2 +- tubearchivist/home/src/index.py | 7 ++--- tubearchivist/home/src/index_management.py | 3 --- tubearchivist/home/src/reindex.py | 26 ++++++------------ tubearchivist/home/src/searching.py | 5 +--- tubearchivist/home/tasks.py | 13 +++------ tubearchivist/home/urls.py | 17 +++++------- tubearchivist/home/views.py | 31 +++++++--------------- tubearchivist/manage.py | 1 + version_check.py | 5 ++-- 13 files changed, 44 insertions(+), 86 deletions(-) diff --git a/tubearchivist/config/settings.py b/tubearchivist/config/settings.py index ef4c910..15b1c8c 100644 --- a/tubearchivist/config/settings.py +++ b/tubearchivist/config/settings.py @@ -10,8 +10,8 @@ For the full list of settings and their values, see https://docs.djangoproject.com/en/3.2/ref/settings/ """ -from pathlib import Path from os import environ +from pathlib import Path # Build paths inside the project like this: BASE_DIR / 'subdir'. BASE_DIR = Path(__file__).resolve().parent.parent @@ -91,16 +91,16 @@ DATABASES = { AUTH_PASSWORD_VALIDATORS = [ { - 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', + 'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator', # noqa: E501 }, { - 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', + 'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator', # noqa: E501 }, { - 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', + 'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator', # noqa: E501 }, { - 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', + 'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator', # noqa: E501 }, ] diff --git a/tubearchivist/config/urls.py b/tubearchivist/config/urls.py index 97f4892..ed6423e 100644 --- a/tubearchivist/config/urls.py +++ b/tubearchivist/config/urls.py @@ -14,7 +14,7 @@ Including another URLconf 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ from django.contrib import admin -from django.urls import path, include +from django.urls import include, path urlpatterns = [ path('', include('home.urls')), diff --git a/tubearchivist/home/src/download.py b/tubearchivist/home/src/download.py index 12d35f4..0387953 100644 --- a/tubearchivist/home/src/download.py +++ b/tubearchivist/home/src/download.py @@ -6,18 +6,16 @@ Functionality: """ import json -import shutil import os - +import shutil from datetime import datetime from time import sleep import requests import yt_dlp as youtube_dl - -from home.src.index import YoutubeChannel, index_new_video from home.src.config import AppConfig -from home.src.helper import clean_string, DurationConverter, set_message +from home.src.helper import DurationConverter, clean_string, set_message +from home.src.index import YoutubeChannel, index_new_video class PendingList: diff --git a/tubearchivist/home/src/helper.py b/tubearchivist/home/src/helper.py index a4b8abb..195507f 100644 --- a/tubearchivist/home/src/helper.py +++ b/tubearchivist/home/src/helper.py @@ -10,8 +10,8 @@ import string import subprocess import unicodedata -import requests import redis +import requests REDIS_HOST = os.environ.get('REDIS_HOST') diff --git a/tubearchivist/home/src/index.py b/tubearchivist/home/src/index.py index 6793480..796e606 100644 --- a/tubearchivist/home/src/index.py +++ b/tubearchivist/home/src/index.py @@ -6,19 +6,16 @@ Functionality: """ import json +import os import re - from datetime import datetime from time import sleep -import os import requests import yt_dlp as youtube_dl - from bs4 import BeautifulSoup - from home.src.config import AppConfig -from home.src.helper import clean_string, DurationConverter +from home.src.helper import DurationConverter, clean_string class YoutubeChannel: diff --git a/tubearchivist/home/src/index_management.py b/tubearchivist/home/src/index_management.py index e093228..ffff651 100644 --- a/tubearchivist/home/src/index_management.py +++ b/tubearchivist/home/src/index_management.py @@ -9,14 +9,11 @@ Functionality: import json import os import zipfile - from datetime import datetime import requests - from home.src.config import AppConfig - # expected mapping and settings INDEX_CONFIG = [ { diff --git a/tubearchivist/home/src/reindex.py b/tubearchivist/home/src/reindex.py index 4d4c5c4..11af35c 100644 --- a/tubearchivist/home/src/reindex.py +++ b/tubearchivist/home/src/reindex.py @@ -8,28 +8,18 @@ Functionality: import json import os import re -import subprocess import shutil - +import subprocess from datetime import datetime -from time import sleep from math import ceil +from time import sleep import requests - -from home.src.download import ChannelSubscription, PendingList, VideoDownloader from home.src.config import AppConfig -from home.src.index import ( - YoutubeChannel, - YoutubeVideo, - index_new_video -) -from home.src.helper import ( - get_total_hits, - clean_string, - set_message, - get_message -) +from home.src.download import ChannelSubscription, PendingList, VideoDownloader +from home.src.helper import (clean_string, get_message, get_total_hits, + set_message) +from home.src.index import YoutubeChannel, YoutubeVideo, index_new_video class Reindex: @@ -430,7 +420,7 @@ class ManualImport: video_file, ext = os.path.splitext(file_name) # make sure youtube_id is in filename - if not youtube_id in video_file: + if youtube_id not in video_file: video_file = f'{video_file}_{youtube_id}' # move, convert if needed @@ -444,7 +434,7 @@ class ManualImport: dest_path = os.path.join(self.CACHE_DIR, 'download', new_file) subprocess.run( ["ffmpeg", "-i", video_path, dest_path, - "-loglevel", "warning", "-stats"], check=True + "-loglevel", "warning", "-stats"], check=True ) diff --git a/tubearchivist/home/src/searching.py b/tubearchivist/home/src/searching.py index 9e28408..3dcddb6 100644 --- a/tubearchivist/home/src/searching.py +++ b/tubearchivist/home/src/searching.py @@ -9,14 +9,11 @@ Functionality: import math import os import urllib.parse - from datetime import datetime import requests - -from PIL import Image - from home.src.config import AppConfig +from PIL import Image class SearchHandler: diff --git a/tubearchivist/home/tasks.py b/tubearchivist/home/tasks.py index ed6a6f3..17f9a67 100644 --- a/tubearchivist/home/tasks.py +++ b/tubearchivist/home/tasks.py @@ -7,17 +7,11 @@ Functionality: import os from celery import Celery, shared_task - -from home.src.download import ( - PendingList, - ChannelSubscription, - VideoDownloader -) from home.src.config import AppConfig -from home.src.reindex import reindex_old_documents, ManualImport -from home.src.index_management import backup_all_indexes +from home.src.download import ChannelSubscription, PendingList, VideoDownloader from home.src.helper import get_lock - +from home.src.index_management import backup_all_indexes +from home.src.reindex import ManualImport, reindex_old_documents CONFIG = AppConfig().config REDIS_HOST = CONFIG['application']['REDIS_HOST'] @@ -94,6 +88,7 @@ def run_manual_import(): if have_lock: my_lock.release() + @shared_task def run_backup(): """ called from settings page, dump backup to zip file """ diff --git a/tubearchivist/home/urls.py b/tubearchivist/home/urls.py index bd16c72..70d482f 100644 --- a/tubearchivist/home/urls.py +++ b/tubearchivist/home/urls.py @@ -1,16 +1,8 @@ """ all home app urls """ from django.urls import path - -from home.views import ( - HomeView, - DownloadView, - ChannelView, - ChannelIdView, - VideoView, - SettingsView, - AboutView -) +from home.views import (AboutView, ChannelIdView, ChannelView, DownloadView, + HomeView, SettingsView, VideoView) from . import views @@ -22,6 +14,9 @@ urlpatterns = [ path('process/', views.process, name='process'), path('downloads/progress', views.progress, name='progress'), path('channel/', ChannelView.as_view(), name='channel'), - path('channel//', ChannelIdView.as_view(), name='channel_id'), + path( + 'channel//', + ChannelIdView.as_view(), name='channel_id' + ), path('video//', VideoView.as_view(), name='video') ] diff --git a/tubearchivist/home/views.py b/tubearchivist/home/views.py index feb919b..d0231b4 100644 --- a/tubearchivist/home/views.py +++ b/tubearchivist/home/views.py @@ -4,36 +4,23 @@ Functionality: - process post data received from frontend via ajax """ -import urllib.parse import json - +import urllib.parse from datetime import datetime from time import sleep import requests - -from django.shortcuts import render, redirect from django.http import JsonResponse -from django.views import View +from django.shortcuts import redirect, render from django.utils.http import urlencode - -from home.src.download import PendingList, ChannelSubscription -from home.src.searching import SearchHandler, Pagination +from django.views import View from home.src.config import AppConfig -from home.src.helper import ( - process_url_list, - get_dl_message, - get_message, - set_message -) -from home.tasks import ( - update_subscribed, - download_pending, - extrac_dl, - download_single, - run_manual_import, - run_backup -) +from home.src.download import ChannelSubscription, PendingList +from home.src.helper import (get_dl_message, get_message, process_url_list, + set_message) +from home.src.searching import Pagination, SearchHandler +from home.tasks import (download_pending, download_single, extrac_dl, + run_backup, run_manual_import, update_subscribed) class HomeView(View): diff --git a/tubearchivist/manage.py b/tubearchivist/manage.py index 8e7ac79..78679b3 100755 --- a/tubearchivist/manage.py +++ b/tubearchivist/manage.py @@ -5,6 +5,7 @@ import sys def main(): + # pylint: disable=import-outside-toplevel """Run administrative tasks.""" os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'config.settings') try: diff --git a/version_check.py b/version_check.py index 1a7a06b..cac5e4b 100755 --- a/version_check.py +++ b/version_check.py @@ -1,8 +1,8 @@ #!/usr/bin/env python """ check requirements.txt for outdated packages """ -import sys import pathlib +import sys import requests @@ -39,7 +39,7 @@ class Requirements: package, version = dependency.split('==') all_requirements.append((package, version.strip())) - all_requirements.sort(key = lambda x: x[0].lower()) + all_requirements.sort(key=lambda x: x[0].lower()) return all_requirements @@ -113,5 +113,6 @@ def main(): print('cancle update...') sys.exit(1) + if __name__ == "__main__": main()