add wsgi foobar
This commit is contained in:
parent
c267b258be
commit
34e5a4a039
5 changed files with 155 additions and 11 deletions
|
@ -24,7 +24,7 @@ def getIds():
|
||||||
if models.MovieId.objects.all().filter(impawards_id=id).count() == 0:
|
if models.MovieId.objects.all().filter(impawards_id=id).count() == 0:
|
||||||
print 'impawards', id
|
print 'impawards', id
|
||||||
data = oxweb.impawards.getData(id)
|
data = oxweb.impawards.getData(id)
|
||||||
if data:
|
if data and 'imdbId' in data:
|
||||||
m = models.getMovieIdByImdbId(data['imdbId'])
|
m = models.getMovieIdByImdbId(data['imdbId'])
|
||||||
if not m.impawards_id:
|
if not m.impawards_id:
|
||||||
m.impawards_id = id
|
m.impawards_id = id
|
||||||
|
@ -32,11 +32,11 @@ def getIds():
|
||||||
for poster in data['posters']:
|
for poster in data['posters']:
|
||||||
addPoster(m, poster, 'impawards.com', m.imdb_id)
|
addPoster(m, poster, 'impawards.com', m.imdb_id)
|
||||||
|
|
||||||
for criterionId in oxweb.criterion.getIds():
|
for id in oxweb.criterion.getIds():
|
||||||
if models.MovieId.objects.all().filter(criterion_id=id).count() == 0:
|
if models.MovieId.objects.all().filter(criterion_id=id).count() == 0:
|
||||||
print 'criterion', id
|
print 'criterion', id
|
||||||
data = oxweb.criterion.getData(criterionId)
|
data = oxweb.criterion.getData(id)
|
||||||
if data:
|
if data and 'imdbId' in data:
|
||||||
m = models.getMovieIdByImdbId(data['imdbId'])
|
m = models.getMovieIdByImdbId(data['imdbId'])
|
||||||
if not m.criterion_id:
|
if not m.criterion_id:
|
||||||
m.criterion_id = id
|
m.criterion_id = id
|
||||||
|
@ -45,18 +45,18 @@ def getIds():
|
||||||
|
|
||||||
#kg
|
#kg
|
||||||
lastId = models.Karagarga.maxId()
|
lastId = models.Karagarga.maxId()
|
||||||
for karagargaId in oxweb.karagarga.getIds(lastId):
|
for id in oxweb.karagarga.getIds(lastId):
|
||||||
if models.Karagarga.objects.filter(karagarga_id=karagargaId).count() == 0:
|
if models.Karagarga.objects.filter(karagarga_id=id).count() == 0:
|
||||||
print 'kg', id
|
print 'kg', id
|
||||||
data = oxweb.karagarga.getData(karagargaId)
|
data = oxweb.karagarga.getData(id)
|
||||||
if data:
|
if data and 'imdbId' in data:
|
||||||
if 'imdbId' in data:
|
if 'imdbId' in data:
|
||||||
m = models.getMovieIdByImdbId(data['imdbId'])
|
m = models.getMovieIdByImdbId(data['imdbId'])
|
||||||
kg = models.Karagarga()
|
kg = models.Karagarga()
|
||||||
kg.movie_id = m
|
kg.movie_id = m
|
||||||
kg.karagarga_id = karagargaId
|
kg.karagarga_id = id
|
||||||
kg.save()
|
kg.save()
|
||||||
#fixme, what to do else?
|
#fixme, what to do else?
|
||||||
for poster in data['posters']:
|
for poster in data['posters']:
|
||||||
addPoster(poster, 'karagarga.net', kg.karagarga_id)
|
addPoster(m, poster, 'karagarga.net', kg.karagarga_id)
|
||||||
|
|
||||||
|
|
|
@ -104,9 +104,10 @@ class MovieId(models.Model):
|
||||||
'director',
|
'director',
|
||||||
'year',
|
'year',
|
||||||
'imdb_id',
|
'imdb_id',
|
||||||
'amg_id',
|
|
||||||
'oxdb_id',
|
'oxdb_id',
|
||||||
|
'amg_id',
|
||||||
'wikipedia_id',
|
'wikipedia_id',
|
||||||
|
'criterion_id',
|
||||||
'impawards_id',
|
'impawards_id',
|
||||||
]
|
]
|
||||||
if self.episode > -1:
|
if self.episode > -1:
|
||||||
|
|
113
monitor.py
Normal file
113
monitor.py
Normal file
|
@ -0,0 +1,113 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
# vi:si:et:sw=4:sts=4:ts=4
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import time
|
||||||
|
import signal
|
||||||
|
import threading
|
||||||
|
import atexit
|
||||||
|
import Queue
|
||||||
|
|
||||||
|
_interval = 1.0
|
||||||
|
_times = {}
|
||||||
|
_files = []
|
||||||
|
|
||||||
|
_running = False
|
||||||
|
_queue = Queue.Queue()
|
||||||
|
_lock = threading.Lock()
|
||||||
|
|
||||||
|
def _restart(path):
|
||||||
|
_queue.put(True)
|
||||||
|
prefix = 'monitor (pid=%d):' % os.getpid()
|
||||||
|
print >> sys.stderr, '%s Change detected to \'%s\'.' % (prefix, path)
|
||||||
|
print >> sys.stderr, '%s Triggering process restart.' % prefix
|
||||||
|
os.kill(os.getpid(), signal.SIGINT)
|
||||||
|
|
||||||
|
def _modified(path):
|
||||||
|
try:
|
||||||
|
# If path doesn't denote a file and were previously
|
||||||
|
# tracking it, then it has been removed or the file type
|
||||||
|
# has changed so force a restart. If not previously
|
||||||
|
# tracking the file then we can ignore it as probably
|
||||||
|
# pseudo reference such as when file extracted from a
|
||||||
|
# collection of modules contained in a zip file.
|
||||||
|
|
||||||
|
if not os.path.isfile(path):
|
||||||
|
return path in _times
|
||||||
|
|
||||||
|
# Check for when file last modified.
|
||||||
|
|
||||||
|
mtime = os.stat(path).st_mtime
|
||||||
|
if path not in _times:
|
||||||
|
_times[path] = mtime
|
||||||
|
|
||||||
|
# Force restart when modification time has changed, even
|
||||||
|
# if time now older, as that could indicate older file
|
||||||
|
# has been restored.
|
||||||
|
|
||||||
|
if mtime != _times[path]:
|
||||||
|
return True
|
||||||
|
except:
|
||||||
|
# If any exception occured, likely that file has been
|
||||||
|
# been removed just before stat(), so force a restart.
|
||||||
|
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
def _monitor():
|
||||||
|
while 1:
|
||||||
|
# Check modification times on all files in sys.modules.
|
||||||
|
|
||||||
|
for module in sys.modules.values():
|
||||||
|
if not hasattr(module, '__file__'):
|
||||||
|
continue
|
||||||
|
path = getattr(module, '__file__')
|
||||||
|
if not path:
|
||||||
|
continue
|
||||||
|
if os.path.splitext(path)[1] in ['.pyc', '.pyo', '.pyd']:
|
||||||
|
path = path[:-1]
|
||||||
|
if _modified(path):
|
||||||
|
return _restart(path)
|
||||||
|
|
||||||
|
# Check modification times on files which have
|
||||||
|
# specifically been registered for monitoring.
|
||||||
|
|
||||||
|
for path in _files:
|
||||||
|
if _modified(path):
|
||||||
|
return _restart(path)
|
||||||
|
|
||||||
|
# Go to sleep for specified interval.
|
||||||
|
|
||||||
|
try:
|
||||||
|
return _queue.get(timeout=_interval)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
|
||||||
|
_thread = threading.Thread(target=_monitor)
|
||||||
|
_thread.setDaemon(True)
|
||||||
|
|
||||||
|
def _exiting():
|
||||||
|
try:
|
||||||
|
_queue.put(True)
|
||||||
|
except:
|
||||||
|
pass
|
||||||
|
_thread.join()
|
||||||
|
|
||||||
|
atexit.register(_exiting)
|
||||||
|
|
||||||
|
def track(path):
|
||||||
|
if not path in _files:
|
||||||
|
_files.append(path)
|
||||||
|
|
||||||
|
def start(interval=1.0):
|
||||||
|
global _interval
|
||||||
|
if interval < _interval:
|
||||||
|
_interval = interval
|
||||||
|
|
||||||
|
global _running
|
||||||
|
_lock.acquire()
|
||||||
|
if not _running:
|
||||||
|
_running = True
|
||||||
|
_thread.start()
|
||||||
|
_lock.release()
|
|
@ -96,6 +96,7 @@ def getPosterUrls(m):
|
||||||
if PosterCache.objects.all().filter(url=poster).count() == 0:
|
if PosterCache.objects.all().filter(url=poster).count() == 0:
|
||||||
addPoster(poster, 'movieposterdb.com', m.imdb_id)
|
addPoster(poster, 'movieposterdb.com', m.imdb_id)
|
||||||
if m.criterion_id:
|
if m.criterion_id:
|
||||||
|
print 'criterion', m.criterion_id
|
||||||
for poster in oxweb.criterion.getData(m.criterion_id)['posters']:
|
for poster in oxweb.criterion.getData(m.criterion_id)['posters']:
|
||||||
if PosterCache.objects.all().filter(url=poster).count() == 0:
|
if PosterCache.objects.all().filter(url=poster).count() == 0:
|
||||||
addPoster(poster, 'criterion.com', m.criterion_id)
|
addPoster(poster, 'criterion.com', m.criterion_id)
|
||||||
|
|
29
wsgi/django.wsgi
Normal file
29
wsgi/django.wsgi
Normal file
|
@ -0,0 +1,29 @@
|
||||||
|
# django.wsgi
|
||||||
|
import os
|
||||||
|
import sys
|
||||||
|
import site
|
||||||
|
|
||||||
|
project_module = 'oxdata'
|
||||||
|
|
||||||
|
# One directory above the project, so project name will be needed for imports
|
||||||
|
root_dir = os.path.normpath(os.path.abspath(os.path.join(os.path.dirname(__file__), '..', '..')))
|
||||||
|
|
||||||
|
# with mod_wsgi >= 2.4, this line will add this path in front of the python path
|
||||||
|
site.addsitedir(os.path.join(root_dir, project_module, 'env', 'lib', 'python2.5', 'site-packages'))
|
||||||
|
|
||||||
|
# add this django project
|
||||||
|
sys.path.append(root_dir)
|
||||||
|
sys.path.append(os.path.join(root_dir, project_module))
|
||||||
|
|
||||||
|
#reload if this django.wsgi gets touched
|
||||||
|
import monitor
|
||||||
|
monitor.start(interval=1.0)
|
||||||
|
|
||||||
|
monitor.track(os.path.abspath(os.path.dirname(__file__)))
|
||||||
|
|
||||||
|
os.environ['DJANGO_SETTINGS_MODULE'] = project_module + '.settings'
|
||||||
|
|
||||||
|
import django.core.handlers.wsgi
|
||||||
|
|
||||||
|
application = django.core.handlers.wsgi.WSGIHandler()
|
||||||
|
|
Loading…
Reference in a new issue