From e0eac77e511023ea531dd3a50b5a0b935adc5760 Mon Sep 17 00:00:00 2001 From: Nick Sergeant Date: Wed, 6 Nov 2013 14:10:04 -0500 Subject: [PATCH] Removing some old Gunicorn stuff and refactors for Django 1.6. --- LICENSE | 2 +- debug_wsgi.py | 28 ------ gk | 3 - gs | 3 - gunicorn.conf.py | 28 ------ manage.py | 15 ++- migrate.py | 235 ----------------------------------------------- requirements.txt | 1 + settings.py | 2 +- 9 files changed, 10 insertions(+), 307 deletions(-) delete mode 100755 debug_wsgi.py delete mode 100755 gk delete mode 100755 gs delete mode 100644 gunicorn.conf.py delete mode 100644 migrate.py diff --git a/LICENSE b/LICENSE index e864446..0118dbc 100644 --- a/LICENSE +++ b/LICENSE @@ -1,4 +1,4 @@ -Copyright (c) 2012 Nick Sergeant +Copyright (c) 2009-2013 Nick Sergeant Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal diff --git a/debug_wsgi.py b/debug_wsgi.py deleted file mode 100755 index 1ae5ee2..0000000 --- a/debug_wsgi.py +++ /dev/null @@ -1,28 +0,0 @@ -import os -import sys -import site - -parent = os.path.dirname -site_dir = parent(os.path.abspath(__file__)) -project_dir = parent(parent(os.path.abspath(__file__))) - -sys.path.insert(0, project_dir) -sys.path.insert(0, site_dir) - -import settings -site.addsitedir(settings.VIRTUALENV_PATH) - -from django.core.management import setup_environ -import settings -setup_environ(settings) - -import django.core.handlers.wsgi -application = django.core.handlers.wsgi.WSGIHandler() - -from werkzeug.debug import DebuggedApplication -application = DebuggedApplication(application, evalex=True) - -def null_technical_500_response(request, exc_type, exc_value, tb): - raise exc_type, exc_value, tb -from django.views import debug -debug.technical_500_response = null_technical_500_response diff --git a/gk b/gk deleted file mode 100755 index 9f4307d..0000000 --- a/gk +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -kill `cat .gunicorn.pid` diff --git a/gs b/gs deleted file mode 100755 index 6617189..0000000 --- a/gs +++ /dev/null @@ -1,3 +0,0 @@ -#!/bin/bash - -gunicorn -c gunicorn.conf.py debug_wsgi:application diff --git a/gunicorn.conf.py b/gunicorn.conf.py deleted file mode 100644 index dae08a6..0000000 --- a/gunicorn.conf.py +++ /dev/null @@ -1,28 +0,0 @@ -import os -import sys - -sys.path.insert(1, os.path.dirname(os.path.realpath(__file__))) - -import monitor -import settings - - -bind = "unix:/tmp/gunicorn.snipt.sock" -daemon = False # Whether work in the background -debug = False # Some extra logging -logfile = ".gunicorn.log" # Name of the log file -loglevel = "info" # The level at which to log -pidfile = ".gunicorn.pid" # Path to a PID file -workers = 1 # Number of workers to initialize -umask = 0 # Umask to set when daemonizing -user = None # Change process owner to user -group = None # Change process group to group -proc_name = "gunicorn-snipt" # Change the process name -tmp_upload_dir = None # Set path used to store temporary uploads - - -def post_fork(server, worker): - server.log.info("Worker spawned (pid: %s)" % worker.pid) - if settings.DEBUG: - server.log.info("Starting change monitor.") - monitor.start(interval=1.0) diff --git a/manage.py b/manage.py index 5e78ea9..f9726f9 100755 --- a/manage.py +++ b/manage.py @@ -1,11 +1,10 @@ #!/usr/bin/env python -from django.core.management import execute_manager -try: - import settings # Assumed to be in the same directory. -except ImportError: - import sys - sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__) - sys.exit(1) +import os +import sys if __name__ == "__main__": - execute_manager(settings) + os.environ.setdefault("DJANGO_SETTINGS_MODULE", "settings") + + from django.core.management import execute_from_command_line + + execute_from_command_line(sys.argv) diff --git a/migrate.py b/migrate.py deleted file mode 100644 index 62d2999..0000000 --- a/migrate.py +++ /dev/null @@ -1,235 +0,0 @@ -#!/usr/bin/python - -from django.utils.encoding import force_unicode - -import MySQLdb - -from django.contrib.auth.models import User - -from snipts.models import Favorite, Snipt -from taggit.models import Tag -from tastypie.models import ApiKey - -conn = MySQLdb.connect(host='localhost', user='root', passwd='', db='sniptold') -cursor = conn.cursor() - -def i(): - users() - create_api_keys() - snipts() - favs() - -def users(): - - print "Deleting existing users" - users = User.objects.all() - for u in users: - u.delete() - - cursor.execute("SELECT * FROM auth_user") - rows = cursor.fetchall() - - print "Adding users" - - for row in rows: - user_id = row[0] - username = row[1] - first_name = row[2] - last_name = row[3] - email = row[4] - password = row[5] - is_staff = row[6] - is_active = row[7] - is_superuser = row[8] - last_login = row[9] - date_joined = row[10] - - user = User( - id=user_id, - username=username, - first_name=first_name, - last_name=last_name, - email=email, - password=password, - is_staff=is_staff, - is_active=is_active, - is_superuser=is_superuser, - last_login=last_login, - date_joined=date_joined, - ) - - print 'Saving user ' + user.username - user.save() - - print "Done with users" - -def snipts(): - - print "Deleting existing snipts" - snipts = Snipt.objects.all() - for s in snipts: - s.delete() - - print "Deleting existing tags" - existing_tags = Tag.objects.all() - existing_tagged_items = Tag.objects.all() - - for t in existing_tags: - t.delete() - - for t in existing_tagged_items: - t.delete() - - cursor.execute("SELECT * FROM snippet_snippet") - rows = cursor.fetchall() - - print "Adding snipts" - - for row in rows: - snipt_id = row[0] - code = row[1] - title = row[2] - created = row[3] - user_id = row[4] - tags = row[5] - lexer = row[6] - public = row[7] - key = row[8] - slug = row[9] - - title = title[:255] - - snipt = Snipt( - id=snipt_id, - code=code, - title=title, - slug=slug, - lexer=lexer, - key=key, - user=User.objects.get(id=user_id), - public=public, - created=created, - modified=created, - ) - for t in parse_tag_input(tags): - snipt.tags.add(t) - - print 'Saving snipt ' + snipt.title - snipt.save() - - print 'Done with snipts' - -def favs(): - - print "Deleting existing favorites" - favs = Favorite.objects.all() - for f in favs: - f.delete() - - cursor.execute("SELECT * FROM favsnipt_favsnipt") - rows = cursor.fetchall() - - print "Adding favorites" - - for row in rows: - fav_id = row[0] - snipt_id = row[1] - user_id = row[2] - created = row[3] - - fav = Favorite( - id=fav_id, - snipt_id=snipt_id, - user_id=user_id, - created=created, - modified=created, - ) - print 'Saving favorite ' + str(fav.id) - fav.save() - - print 'Done with favorites' - -def parse_tag_input(input): - """ - Parses tag input, with multiple word input being activated and - delineated by commas and double quotes. Quotes take precedence, so - they may contain commas. - - Returns a sorted list of unique tag names. - """ - if not input: - return [] - - input = force_unicode(input) - - # Special case - if there are no commas or double quotes in the - # input, we don't *do* a recall... I mean, we know we only need to - # split on spaces. - if u',' not in input and u'"' not in input: - words = list(set(split_strip(input, u' '))) - words.sort() - return words - - words = [] - buffer = [] - # Defer splitting of non-quoted sections until we know if there are - # any unquoted commas. - to_be_split = [] - saw_loose_comma = False - open_quote = False - i = iter(input) - try: - while 1: - c = i.next() - if c == u'"': - if buffer: - to_be_split.append(u''.join(buffer)) - buffer = [] - # Find the matching quote - open_quote = True - c = i.next() - while c != u'"': - buffer.append(c) - c = i.next() - if buffer: - word = u''.join(buffer).strip() - if word: - words.append(word) - buffer = [] - open_quote = False - else: - if not saw_loose_comma and c == u',': - saw_loose_comma = True - buffer.append(c) - except StopIteration: - # If we were parsing an open quote which was never closed treat - # the buffer as unquoted. - if buffer: - if open_quote and u',' in buffer: - saw_loose_comma = True - to_be_split.append(u''.join(buffer)) - if to_be_split: - if saw_loose_comma: - delimiter = u',' - else: - delimiter = u' ' - for chunk in to_be_split: - words.extend(split_strip(chunk, delimiter)) - words = list(set(words)) - words.sort() - return words - -def split_strip(input, delimiter=u','): - """ - Splits ``input`` on ``delimiter``, stripping each resulting string - and returning a list of non-empty strings. - """ - if not input: - return [] - - words = [w.strip() for w in input.split(delimiter)] - return [w for w in words if w] - -def create_api_keys(): - for user in User.objects.all(): - ApiKey.objects.create(user=user) diff --git a/requirements.txt b/requirements.txt index e5a9853..9d909d9 100644 --- a/requirements.txt +++ b/requirements.txt @@ -17,6 +17,7 @@ parsedatetime psycopg2 pyelasticsearch==0.3 python-memcached +python-mimeparse python-postmark pyyaml raven diff --git a/settings.py b/settings.py index ace080a..cd3831a 100644 --- a/settings.py +++ b/settings.py @@ -138,7 +138,7 @@ AUTHENTICATION_BACKENDS = ( 'utils.backends.EmailOrUsernameModelBackend', ) -ROOT_URLCONF = 'snipt.urls' +ROOT_URLCONF = 'urls' PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))