Skip to content

Commit a05c24e

Browse files
committed
Now using Waitress as WSGI server, as it is much faster. Requries pip install -r requirements.txt
1 parent d8581fa commit a05c24e

File tree

20 files changed

+353
-225
lines changed

20 files changed

+353
-225
lines changed

CHANGELOG.md

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,25 @@
22

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

5+
## 210217 (0.7.6.4)
6+
7+
*This update requires a requirements upgrade*
8+
9+
### Changes
10+
11+
* 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.
12+
It is started in a slightly different way. I have changed the startup so generally you will now start YAPO by executing:
13+
`python yapo.py`
14+
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.
15+
* On startup, YAPO now checks if there is a database present, and one is generated if not.
16+
* 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.
17+
518
## 210215 (0.7.6.3)
619

720
### Changes
821

922
* 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).
10-
A warning about duplicates now fires in the startup sequence if there are any.
23+
A warning about duplicates is now displayed in the startup-sequence (Hail Amiga!) if there are any.
1124
Also, I have implemented a further check so the duplicate checker only deletes files with identical hashes as well as identical filesizes.
1225

1326

README.md

Lines changed: 69 additions & 50 deletions
Large diffs are not rendered by default.

VERSION.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.6.3
1+
0.7.6.4

YAPO/settings.py

Lines changed: 50 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import json
22
import os
3+
import re
34
import sys
45
from configuration import Config, Constants
56
from utils.printing import Logger
@@ -8,6 +9,8 @@
89
import shutil
910
import colorama
1011
log = Logger()
12+
import _locale
13+
_locale._getdefaultlocale = (lambda *args: ['en_US', 'utf8'])
1114

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

1821
# SECURITY WARNING: don't run with debug turned on in production!
19-
DEBUG = True
22+
DEBUG = False
2023
LOGGING_CONFIG = None
2124
# SILENCED_SYSTEM_CHECKS = ["fields.W340"]
2225
ALLOWED_HOSTS = ['*']
@@ -38,63 +41,6 @@
3841
}
3942
}
4043

41-
42-
# First of all, check if the db is located in the old folder (root)
43-
44-
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.
45-
src = Config().root_path
46-
dest = os.path.join(Config().database_dir)
47-
okmoved = True
48-
49-
try:
50-
if sys.frozen or sys.importers:
51-
compiled = True
52-
except AttributeError:
53-
compiled = False
54-
55-
if not os.path.isfile(os.path.join(src, "db.sqlite3")) and not os.path.isfile(os.path.join(dest, "db.sqlite3")):
56-
print("\n")
57-
print("No database")
58-
print(f"There is no database installed at: {os.path.join(dest, 'db.sqlite3')}")
59-
print(
60-
"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.")
61-
print("\nCOMMAND(S) TO RUN:\n")
62-
if not compiled:
63-
print("python manage.py makemigrations")
64-
print("python manage.py migrate\n")
65-
else:
66-
print('migrate.exe (or \"migrate\"\n')
67-
print("Please follow the directions provided.")
68-
input("\nPress enter to exit YAPO and take care of the above. >")
69-
sys.exit()
70-
71-
if os.path.isfile(os.path.join(src, "db.sqlite3")):
72-
if not os.path.isfile(os.path.join(dest, "db.sqlite3")):
73-
try:
74-
shutil.move(src, dest)
75-
okmoved = True
76-
except:
77-
print("Error moving the database")
78-
print("There was an error moving the database to it's new location:")
79-
print(f"{src} -> {dest}")
80-
input("Please check the source and destination. Press enter to exit YAPO. >")
81-
sys.exit()
82-
else:
83-
print("Databases at two locations")
84-
print(f"There is a database file at both the below listed locations. You need to delete the one")
85-
print("you don't wish to use and make sure the other is in the listed destination directory.")
86-
print("This is a check because we have moved the database to a subdirectory.")
87-
print("")
88-
print(f"SOURCE: {src}")
89-
print(f"DESTINATION: {src}")
90-
input("Press enter to exit YAPO, and start it again when the above is taken care of. >")
91-
sys.exit()
92-
if okmoved:
93-
print(f"The database was moved to {dest}.")
94-
95-
96-
97-
9844
# Application definition
9945

10046
INSTALLED_APPS = [
@@ -191,6 +137,52 @@
191137
MEDIA_ROOT = Config().site_media_path
192138
MEDIA_URL = f"/{Constants().site_media_subdir}/"
193139

140+
141+
IGNORABLE_404_URLS = [
142+
re.compile(r'[^\\s]+(.*?)\\.(jpg|jpeg|png|gif|JPG|JPEG|PNG|GIF)$'),
143+
]
144+
145+
LOGGING_CONFIG = None
146+
LOGGING = {
147+
'version': 1,
148+
'disable_existing_loggers': True,
149+
'formatters': {
150+
},
151+
'filters': {
152+
'require_debug_false': {
153+
'()': 'django.utils.log.RequireDebugFalse'
154+
}
155+
},
156+
'handlers': {
157+
'null': {
158+
'level': 'ERROR',
159+
'class': 'django.utils.log.NullHandler',
160+
},
161+
'mail_admins': {
162+
'level': 'ERROR',
163+
'filters': ['require_debug_false'],
164+
'class': 'django.utils.log.AdminEmailHandler',
165+
},
166+
},
167+
'loggers': {
168+
'django.request': {
169+
'handlers': ['null', 'default'],
170+
'level': 'ERROR',
171+
'propagate': False,
172+
},
173+
# 'requests': {
174+
# # The requests library is too verbose in it's logging, reducing the verbosity in our logs.
175+
# 'handlers': ['null', 'default'],
176+
# 'level': 'WARNING',
177+
# 'propagate': True,
178+
# },
179+
# 'urllib3': {
180+
# 'handers': ['null', 'default'],
181+
# 'level': 'WARNING',
182+
# 'propagate': True
183+
# },
184+
}
185+
}
194186
# APPEND_SLASH = True
195187

196188
REST_FRAMEWORK = {

YAPO/urls.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,8 @@
8686
url(r'^tag-multiple-items/', views.tag_multiple_items),
8787
url(r'^play/', views.display_video),
8888
url(r'^scan-scene/', views.scanScene.as_view()),
89-
] + static(Config().site_media_url, document_root=Config().site_media_path)
89+
]
90+
urlpatterns += static(Config().site_media_url, document_root=Config().site_media_path)
9091

9192

9293
# urlpatterns = format_suffix_patterns(urlpatterns, allowed=['json'])

YAPO/wsgi.py

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
"""
2-
WSGI config for YAPO project.
2+
WSGI config for YAPO.
33
4-
It exposes the WSGI callable as a module-level variable named ``application``.
4+
It exposes the WSGI callable as a module-level variable named "application".
55
66
For more information on this file, see
7-
https://docs.djangoproject.com/en/1.9/howto/deployment/wsgi/
7+
https://docs.djangoproject.com/en/3.1/howto/deployment/wsgi/
88
"""
99

1010
import os
@@ -13,9 +13,12 @@
1313
from dj_static import Cling, MediaCling
1414
from static_ranges import Ranges
1515

16+
1617
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "YAPO.settings")
1718

1819
application = get_wsgi_application()
1920
application = Ranges(Cling(MediaCling(application)))
2021

21-
print("\nServer ready.")
22+
23+
24+
#print("\nServer ready.")

manage.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
import os
44
import sys
5-
5+
from utils import dbcheck
66
# import settings
77

88

@@ -31,6 +31,7 @@ def get_main_dir ():
3131
# a = pagination
3232
SCRIPT_ROOT = get_main_dir()
3333

34+
dbcheck.boot()
3435
try:
3536
if sys.frozen or sys.importers:
3637
SCRIPT_ROOT = os.path.dirname(sys.executable)

requirements.txt

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,12 @@ jinja2>=2.11.2
2525
texttable>=1.6.3
2626
psutil>=5.7.2
2727
selenium>=3.141.0
28-
PyYAML~=5.3.1
28+
PyYAML>=5.3.1
2929
zipp>=3.2.0
3030
dload>=0.6
3131
DateTime~=4.3
3232
six~=1.15.0
3333
bs4~=0.0.1
34-
urllib3~=1.25.10
34+
urllib3>=1.25.10
3535
lxml>=4.6.2
36-
setuptools~=50.3.0
36+
setuptools>=50.3.0

setup.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,11 @@
1616
long_description=readme,
1717
description='YAPO - Yet Another Porn Organizer - Extended+',
1818
name='YAPO',
19-
version='0.7.3',
19+
version='0.7.6.4',
2020
packages=['YAPO', 'videos', 'configuration', 'utils'],
2121
package_dir={"YAPO": ""},
2222
package_data={},
23-
scripts=['manage.py'],
23+
scripts=['yapo.py', 'manage.py', 'yapo-maintenance.py'],
2424
python_requires='>=3.7',
25-
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'],
25+
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'],
2626
)

utils/dbcheck.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from configuration import Config
2+
import sys, os, time
3+
from django.core.management import call_command
4+
from YAPO.wsgi import application
5+
6+
# First of all, check if the db is located in the old folder (root)
7+
8+
def boot():
9+
dest = os.path.join(Config().database_dir)
10+
okmoved = True
11+
12+
SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__))
13+
compiled = False
14+
try:
15+
if getattr(sys, 'frozen', False) and hasattr(sys, '_MEIPASS'):
16+
SCRIPT_ROOT = os.path.dirname(sys.executable)
17+
compiled = True
18+
except AttributeError:
19+
SCRIPT_ROOT = os.path.dirname(os.path.realpath(__file__))
20+
compiled = False
21+
22+
if not os.path.isfile(os.path.join(dest, "db.sqlite3")):
23+
print("\n")
24+
print("No database\n===========")
25+
print(f"There is no database installed at: {os.path.join(dest, 'db.sqlite3')}\nGenerating a new database...\n\n")
26+
time.sleep(4)
27+
call_command('makemigrations')
28+
call_command('migrate')
29+
return
30+
31+

0 commit comments

Comments
 (0)