Skip to content

Commit

Permalink
Now using Waitress as WSGI server, as it is much faster. Requries pip…
Browse files Browse the repository at this point in the history
… install -r requirements.txt
  • Loading branch information
cooperdk committed Feb 18, 2021
1 parent d8581fa commit a05c24e
Show file tree
Hide file tree
Showing 20 changed files with 353 additions and 225 deletions.
15 changes: 14 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,25 @@

(WIN) = Windows exclusive, (LIN) = Linux exclusive

## 210217 (0.7.6.4)

*This update requires a requirements upgrade*

### Changes

* YAPO now has a naughty waitress! I switched the webserver part from the built-in Django development server to the Waitress WSGI server, and it's (a lot) faster.
It is started in a slightly different way. I have changed the startup so generally you will now start YAPO by executing:
`python yapo.py`
The old manage.py (which is used to enter the emergency shell, etc) is still available in the Github build. The frozen build will have a companion app instead.
* On startup, YAPO now checks if there is a database present, and one is generated if not.
* I am beginning to adapt the UI and view backends to display various results in the UI alert field on top of the page. For now, it works with the database cleanup utility and the duplicate scanner, among others.

## 210215 (0.7.6.3)

### Changes

* The duplicate checker no longer recurses the entire dataset. I found a way to filter duplicates and designed it so that the first copy is the original, and any subsequent copies are marked as duplicates. Instead of taking about two minutes for a 11,000 scene database, it now completes in less than one tenth of a second (not counting the file deletion and database removal).
A warning about duplicates now fires in the startup sequence if there are any.
A warning about duplicates is now displayed in the startup-sequence (Hail Amiga!) if there are any.
Also, I have implemented a further check so the duplicate checker only deletes files with identical hashes as well as identical filesizes.


Expand Down
119 changes: 69 additions & 50 deletions README.md

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion VERSION.md
Original file line number Diff line number Diff line change
@@ -1 +1 @@
0.7.6.3
0.7.6.4
108 changes: 50 additions & 58 deletions YAPO/settings.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import json
import os
import re
import sys
from configuration import Config, Constants
from utils.printing import Logger
Expand All @@ -8,6 +9,8 @@
import shutil
import colorama
log = Logger()
import _locale
_locale._getdefaultlocale = (lambda *args: ['en_US', 'utf8'])

# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/1.9/howto/deployment/checklist/
Expand All @@ -16,7 +19,7 @@
SECRET_KEY = "0px^lshd1lsf6uq#%90lre3$iqkz9=i7a0ko2_83b$n@=&(*d5"

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
DEBUG = False
LOGGING_CONFIG = None
# SILENCED_SYSTEM_CHECKS = ["fields.W340"]
ALLOWED_HOSTS = ['*']
Expand All @@ -38,63 +41,6 @@
}
}


# First of all, check if the db is located in the old folder (root)

if not 'migrat' or "passcheck" in str(sys.argv[1:]): # Check if the user runs migration. Don't execute this if that's the case.
src = Config().root_path
dest = os.path.join(Config().database_dir)
okmoved = True

try:
if sys.frozen or sys.importers:
compiled = True
except AttributeError:
compiled = False

if not os.path.isfile(os.path.join(src, "db.sqlite3")) and not os.path.isfile(os.path.join(dest, "db.sqlite3")):
print("\n")
print("No database")
print(f"There is no database installed at: {os.path.join(dest, 'db.sqlite3')}")
print(
"Please run the below commands from your YAPO main directory to create the database,\nor place your database at the above location.\n\nConsult the guide or website for help.")
print("\nCOMMAND(S) TO RUN:\n")
if not compiled:
print("python manage.py makemigrations")
print("python manage.py migrate\n")
else:
print('migrate.exe (or \"migrate\"\n')
print("Please follow the directions provided.")
input("\nPress enter to exit YAPO and take care of the above. >")
sys.exit()

if os.path.isfile(os.path.join(src, "db.sqlite3")):
if not os.path.isfile(os.path.join(dest, "db.sqlite3")):
try:
shutil.move(src, dest)
okmoved = True
except:
print("Error moving the database")
print("There was an error moving the database to it's new location:")
print(f"{src} -> {dest}")
input("Please check the source and destination. Press enter to exit YAPO. >")
sys.exit()
else:
print("Databases at two locations")
print(f"There is a database file at both the below listed locations. You need to delete the one")
print("you don't wish to use and make sure the other is in the listed destination directory.")
print("This is a check because we have moved the database to a subdirectory.")
print("")
print(f"SOURCE: {src}")
print(f"DESTINATION: {src}")
input("Press enter to exit YAPO, and start it again when the above is taken care of. >")
sys.exit()
if okmoved:
print(f"The database was moved to {dest}.")




# Application definition

INSTALLED_APPS = [
Expand Down Expand Up @@ -191,6 +137,52 @@
MEDIA_ROOT = Config().site_media_path
MEDIA_URL = f"/{Constants().site_media_subdir}/"


IGNORABLE_404_URLS = [
re.compile(r'[^\\s]+(.*?)\\.(jpg|jpeg|png|gif|JPG|JPEG|PNG|GIF)$'),
]

LOGGING_CONFIG = None
LOGGING = {
'version': 1,
'disable_existing_loggers': True,
'formatters': {
},
'filters': {
'require_debug_false': {
'()': 'django.utils.log.RequireDebugFalse'
}
},
'handlers': {
'null': {
'level': 'ERROR',
'class': 'django.utils.log.NullHandler',
},
'mail_admins': {
'level': 'ERROR',
'filters': ['require_debug_false'],
'class': 'django.utils.log.AdminEmailHandler',
},
},
'loggers': {
'django.request': {
'handlers': ['null', 'default'],
'level': 'ERROR',
'propagate': False,
},
# 'requests': {
# # The requests library is too verbose in it's logging, reducing the verbosity in our logs.
# 'handlers': ['null', 'default'],
# 'level': 'WARNING',
# 'propagate': True,
# },
# 'urllib3': {
# 'handers': ['null', 'default'],
# 'level': 'WARNING',
# 'propagate': True
# },
}
}
# APPEND_SLASH = True

REST_FRAMEWORK = {
Expand Down
3 changes: 2 additions & 1 deletion YAPO/urls.py
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,8 @@
url(r'^tag-multiple-items/', views.tag_multiple_items),
url(r'^play/', views.display_video),
url(r'^scan-scene/', views.scanScene.as_view()),
] + static(Config().site_media_url, document_root=Config().site_media_path)
]
urlpatterns += static(Config().site_media_url, document_root=Config().site_media_path)


# urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json'])
11 changes: 7 additions & 4 deletions YAPO/wsgi.py
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
"""
WSGI config for YAPO project.
WSGI config for YAPO.
It exposes the WSGI callable as a module-level variable named ``application``.
It exposes the WSGI callable as a module-level variable named "application".
For more information on this file, see
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
"""

import os
Expand All @@ -13,9 +13,12 @@
from dj_static import Cling, MediaCling
from static_ranges import Ranges


os.environ.setdefault("DJANGO_SETTINGS_MODULE", "YAPO.settings")

application = get_wsgi_application()
application = Ranges(Cling(MediaCling(application)))

print("\nServer ready.")


#print("\nServer ready.")
3 changes: 2 additions & 1 deletion manage.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import os
import sys

from utils import dbcheck
# import settings


Expand Down Expand Up @@ -31,6 +31,7 @@ def get_main_dir ():
# a = pagination
SCRIPT_ROOT = get_main_dir()

dbcheck.boot()
try:
if sys.frozen or sys.importers:
SCRIPT_ROOT = os.path.dirname(sys.executable)
Expand Down
6 changes: 3 additions & 3 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,12 +25,12 @@ jinja2>=2.11.2
texttable>=1.6.3
psutil>=5.7.2
selenium>=3.141.0
PyYAML~=5.3.1
PyYAML>=5.3.1
zipp>=3.2.0
dload>=0.6
DateTime~=4.3
six~=1.15.0
bs4~=0.0.1
urllib3~=1.25.10
urllib3>=1.25.10
lxml>=4.6.2
setuptools~=50.3.0
setuptools>=50.3.0
6 changes: 3 additions & 3 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,11 +16,11 @@
long_description=readme,
description='YAPO - Yet Another Porn Organizer - Extended+',
name='YAPO',
version='0.7.3',
version='0.7.6.4',
packages=['YAPO', 'videos', 'configuration', 'utils'],
package_dir={"YAPO": ""},
package_data={},
scripts=['manage.py'],
scripts=['yapo.py', 'manage.py', 'yapo-maintenance.py'],
python_requires='>=3.7',
install_requires=['asgiref>=3.2.10', 'beautifulsoup4>=4.9.1', 'colorama>=0.4.3', 'dj-static', 'django==3.0.7', 'django-autocomplete-light==3.5.1', 'django-extensions==3.0.8', 'django-mptt==0.11.0', 'djangorestframework==3.11.1', 'dload>=0.6', 'html5lib>=1.1', 'jinja2>=2.11.2', 'numpy>=1.19.2', 'parsedatetime>=2.6', 'pillow>=7.2.0', 'pillow-pil>=0.1.dev0', 'psutil>=5.7.2', 'pypiwin32>=223; platform_system == "Windows"', 'pywin32>=228; platform_system == "Windows"', 'pywin32-ctypes>=0.2.0; platform_system == "Windows"', 'python-dateutil>=2.8.1', 'pyyaml==5.3.*,>=5.3.1', 'requests>=2.24.0', 'selenium>=3.141.0', 'static-ranges', 'texttable>=1.6.3', 'tmdbsimple==2.6.6', 'waitress==1.4.4', 'webencodings>=0.5.1', 'zipp>=3.1.0'],
install_requires=['asgiref>=3.2.10', 'beautifulsoup4>=4.9.2', 'colorama>=0.4.3', 'dj_static', 'django==3.1.6', 'django-autocomplete-light==3.5.1', 'django-extensions==3.0.9', 'django-mptt==0.11.0', 'djangorestframework==3.12.1', 'dload>=0.6', 'html5lib>=1.1', 'jinja2>=2.11.2', 'numpy>=1.19.2', 'parsedatetime>=2.6', 'pillow>=7.2.0', 'pillow-pil>=0.1.dev0', 'psutil>=5.7.2', 'pypiwin32>=223; platform_system == "Windows"', 'pywin32>=228; platform_system == "Windows"', 'pywin32-ctypes>=0.2.0; platform_system == "Windows"', 'python-dateutil>=2.8.1', 'pyyaml>=5.3.1', 'requests>=2.24.0', 'selenium>=3.141.0', 'static-ranges', 'texttable>=1.6.3', 'tmdbsimple==2.6.6', 'waitress==1.4.4', 'webencodings>=0.5.1', 'zipp>=3.2.0'],
)
31 changes: 31 additions & 0 deletions utils/dbcheck.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from configuration import Config
import sys, os, time
from django.core.management import call_command
from YAPO.wsgi import application

# First of all, check if the db is located in the old folder (root)

def boot():
dest = os.path.join(Config().database_dir)
okmoved = True

SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__))
compiled = False
try:
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
SCRIPT_ROOT = os.path.dirname(sys.executable)
compiled = True
except AttributeError:
SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__))
compiled = False

if not os.path.isfile(os.path.join(dest, "db.sqlite3")):
print("\n")
print("No database\n===========")
print(f"There is no database installed at: {os.path.join(dest, 'db.sqlite3')}\nGenerating a new database...\n\n")
time.sleep(4)
call_command('makemigrations')
call_command('migrate')
return


Loading

0 comments on commit a05c24e

Please sign in to comment.