Permalink
Browse files

Removing some old Gunicorn stuff and refactors for Django 1.6.

  • Loading branch information...
nicksergeant committed Nov 6, 2013
1 parent 95f56ab commit e0eac77e511023ea531dd3a50b5a0b935adc5760
Showing with 10 additions and 307 deletions.
  1. +1 βˆ’1 LICENSE
  2. +0 βˆ’28 debug_wsgi.py
  3. +0 βˆ’3 gk
  4. +0 βˆ’3 gs
  5. +0 βˆ’28 gunicorn.conf.py
  6. +7 βˆ’8 manage.py
  7. +0 βˆ’235 migrate.py
  8. +1 βˆ’0 requirements.txt
  9. +1 βˆ’1 settings.py
View
@@ -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
View
@@ -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
View
3 gk
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-kill `cat .gunicorn.pid`
View
3 gs
@@ -1,3 +0,0 @@
-#!/bin/bash
-
-gunicorn -c gunicorn.conf.py debug_wsgi:application
View
@@ -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)
View
@@ -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)
View
@@ -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)
View
@@ -17,6 +17,7 @@ parsedatetime
psycopg2
pyelasticsearch==0.3
python-memcached
+python-mimeparse
python-postmark
pyyaml
raven
View
@@ -138,7 +138,7 @@
'utils.backends.EmailOrUsernameModelBackend',
)
-ROOT_URLCONF = 'snipt.urls'
+ROOT_URLCONF = 'urls'
PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))

0 comments on commit e0eac77

Please sign in to comment.