Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

added rapidsms-admin.py script to spawn projects.

this script _mostly_ uses the django management system, but performs a
bit of monkey-patching to dodge some hard-coded paths within django.
it doesn't affect django-admin.py, just makes it easier to start with
the rapidsms defaults intact. (less pasting to get started.)
  • Loading branch information...
commit d23a7a2201645ce2d257ec5d01294205327ba797 1 parent 52bfea9
@adammck adammck authored
View
5 .gitignore
@@ -1,8 +1,11 @@
+*~
*.pyc
+*.pyo
*.swp
-*~
*.mo
core.*
.project
.pydevproject
+*.egg-info
*.sqlite3
+dist
View
26 bin/rapidsms-admin.py
@@ -0,0 +1,26 @@
+#!/usr/bin/env python
+# vim: ai ts=4 sts=4 et sw=4
+
+
+# for most commands we will drop straight through this script into the
+# standard django-admin.py -- but if we're creating a project, we are
+# going to... (wait for it...) monkeypatch our command into sys.modules,
+# and trick django into calling it instead of its own! hahaha!
+#
+# ...but seriously, django provides no way of doing this via management
+# commands, since we're spawning a new project here, and django doesn't
+# know to look in the rapidsms package for commands yet.
+
+import sys
+import rapidsms.management.commands.startproject
+import django.core.management.commands.startproject
+
+sys.modules['django.core.management.commands.startproject'] =\
+ rapidsms.management.commands.startproject
+
+
+# straight from the django-admin.py script.
+
+if __name__ == "__main__":
+ from django.core import management
+ management.execute_from_command_line()
View
31 lib/rapidsms/management/commands/startproject.py
@@ -0,0 +1,31 @@
+#!/usr/bin/env python
+# vim: ai ts=4 sts=4 et sw=4
+
+
+import os
+import shutil
+from django.core.management.base import CommandError, LabelCommand
+from rapidsms.utils.modules import try_import
+import rapidsms
+
+
+
+# this is mostly copy/pasted from django. unfortunately, the copy
+# mechanism had to be replaced, since django hard-codes some paths.
+
+class Command(LabelCommand):
+ help = "Creates a RapidSMS project in the current directory."
+ args = "[projectname]"
+ label = 'project name'
+
+ requires_model_validation = False
+ can_import_settings = False
+
+ def handle_label(self, project_name, **options):
+ if try_import(project_name) is not None:
+ raise CommandError(
+ "%r conflicts with the name of an existing Python module and cannot be used as a project name. Please try another name." %
+ project_name)
+
+ src_dir = os.path.join(rapidsms.__path__[0], "skeleton", "project")
+ shutil.copytree(src_dir, project_name)
View
0  lib/rapidsms/skeleton/project/__init__.py
No changes.
View
10 lib/rapidsms/skeleton/project/manage.py
@@ -0,0 +1,10 @@
+#!/usr/bin/env python
+# vim: ai ts=4 sts=4 et sw=4
+
+
+from django.core.management import execute_manager
+import settings
+
+
+if __name__ == "__main__":
+ execute_manager(settings)
View
172 settings.py → lib/rapidsms/skeleton/project/settings.py
@@ -1,18 +1,50 @@
#!/usr/bin/env python
# vim: ai ts=4 sts=4 et sw=4
-import os, tempfile
-DEBUG = True
-TEMPLATE_DEBUG = DEBUG
+# -------------------------------------------------------------------- #
+# MAIN CONFIGURATION #
+# -------------------------------------------------------------------- #
+
+
+# you should configure your database here before doing any real work.
+# see: http://docs.djangoproject.com/en/dev/ref/settings/#databases
+DATABASES = {
+ "default": {
+ "ENGINE": "django.db.backends.sqlite3",
+ "NAME": "rapidsms.sqlite3"
+ }
+}
+
-DATABASE_ENGINE = "sqlite3"
-DATABASE_NAME = "/tmp/rapidsms.sqlite3"
+# the rapidsms backend configuration is designed to resemble django's
+# database configuration, as a nested dict of (name, configuration).
+#
+# the ENGINE option specifies the module of the backend; the most common
+# backend types (for a GSM modem or an SMPP server) are bundled with
+# rapidsms, but you may choose to write your own.
+#
+# all other options are passed to the Backend when it is instantiated,
+# to configure it. see the documentation in those modules for a list of
+# the valid options for each.
+INSTALLED_BACKENDS = {
+ #"att": {
+ # "ENGINE": "rapidsms.backends.gsm",
+ # "PORT": "/dev/ttyUSB0"
+ #},
+ #"verizon": {
+ # "ENGINE": "rapidsms.backends.gsm,
+ # "PORT": "/dev/ttyUSB1"
+ #},
+ "message_tester": {
+ "ENGINE": "rapidsms.backends.bucket"
+ }
+}
-# to get up and running quickly with a minimal rapidsms project, start
-# with these apps. just prepend them to your INSTALLED_APPS.
-RAPIDSMS_BASE_APPS = [
+# to help you get started quickly, many django/rapidsms apps are enabled
+# by default. you may wish to remove some and/or add your own.
+INSTALLED_APPS = [
# the essentials.
"django_nose",
@@ -31,13 +63,9 @@
"django.contrib.admin",
"django.contrib.sessions",
"django.contrib.contenttypes",
- "rapidsms.contrib.djangoadmin"
-]
+ "rapidsms.contrib.djangoadmin",
-# INSTALL APPS BY APPENDING THEM TO THIS LIST
-# alternatively, start with ALL of the contrib apps, for a useful system
-# out of the box. (don't forget RAPIDSMS_TABS, or they'll be invisible.)
-INSTALLED_APPS = RAPIDSMS_BASE_APPS + [
+ # the rapidsms contrib apps.
"rapidsms.contrib.default",
"rapidsms.contrib.export",
"rapidsms.contrib.httptester",
@@ -51,14 +79,11 @@
]
-# the tabs for RAPISMS_BASE_APPS.
-RAPIDSMS_BASE_TABS = [
- ("rapidsms.views.dashboard", "Dashboard")
-]
-
-# REVEAL TABS BY APPENDING THEM TO THIS LIST
-# the tabs for RAPIDSMS_APPS.
-TABS = RAPIDSMS_BASE_TABS + [
+# this rapidsms-specific setting defines which views are linked by the
+# tabbed navigation. when adding an app to INSTALLED_APPS, you may wish
+# to add it here, also, to expose it in the rapidsms ui.
+RAPIDSMS_TABS = [
+ ("rapidsms.views.dashboard", "Dashboard"),
("rapidsms.contrib.messagelog.views.message_log", "Message Log"),
("rapidsms.contrib.registration.views.registration", "Registration"),
("rapidsms.contrib.messaging.views.messaging", "Messaging"),
@@ -67,54 +92,31 @@
("rapidsms.contrib.httptester.views.generate_identity", "Message Tester"),
]
-# ACTIVATE BACKENDS BY APPENDING THEM TO THIS DICTIONARY
-# the INSTALLED_BACKENDS setting is intended to resemble django 1.2's
-# DATABASE: http://docs.djangoproject.com/en/dev/ref/settings/#databases
-INSTALLED_BACKENDS = {
- #"AT&T": {
- # "ENGINE": "rapidsms.backends.gsm",
- # "PORT": "/dev/ttyUSB0"
- #},
- #"Verizon": {
- # "ENGINE": "rapidsms.backends.gsm,
- # "PORT": "/dev/ttyUSB1"
- #},
- "message_tester": {
- "ENGINE": "rapidsms.backends.bucket"
- }
-}
+# -------------------------------------------------------------------- #
+# BORING CONFIGURATION #
+# -------------------------------------------------------------------- #
-"""
-The following default settings are sufficient for most RapidSMS development
-"""
+# debug mode is turned on as default, since rapidsms is under heavy
+# development at the moment, and full stack traces are very useful
+# when reporting bugs. don't forget to turn this off in production.
+DEBUG = TEMPLATE_DEBUG = True
-# these apps should not be started by rapidsms in your tests, however,
-# the models and bootstrap will still be available through django.
-TEST_EXCLUDED_APPS = (
- "django.contrib.sessions",
- "django.contrib.contenttypes",
- "django.contrib.auth",
- "rapidsms",
- "rapidsms.contrib.ajax",
- "rapidsms.contrib.httptester",
-)
# after login (which is handled by django.contrib.auth), redirect to the
# dashboard rather than 'accounts/profile' (the default).
LOGIN_REDIRECT_URL = "/"
-# the default ROOT_URLCONF module, bundled with rapidsms, detects and
-# maps the urls.py module of each app into a single project urlconf.
-# this is handy, but too magical for the taste of some. (remove it?)
-ROOT_URLCONF = "rapidsms.djangoproject.urls"
+# use django-nose to run tests. rapidsms contains lots of packages and
+# modules which django does not find automatically, and importing them
+# all manually is tiresome and error-prone.
+TEST_RUNNER = "django_nose.NoseTestSuiteRunner"
-# for some reason, this setting is blank in django's global_settings.py,
-# so i'm setting it to something sane here, just to avoid having to do
-# it per-project.
+# for some reason this setting is blank in django's global_settings.py,
+# but it is needed for static assets to be linkable.
MEDIA_URL = "/static/"
@@ -124,30 +126,16 @@
SITE_ID = 1
-# use django-nose to run tests. rapidsms contains lots of packages and
-# modules which django does not find automatically, and importing them
-# all manually is tiresome and error-prone.
-TEST_RUNNER = "django_nose.NoseTestSuiteRunner"
-
-
-# since we might hit the database from any thread during testing, the
-# in-memory sqlite database isn't sufficient. it spawns a separate
-# virtual database for each thread, and syncdb is only called for the
-# first. this leads to confusing "no such table" errors. so i'm
-# defaulting to a temporary file instead.
-TEST_DATABASE_NAME = os.path.join(tempfile.gettempdir(), "rapidsms.test.sqlite3")
-
-
# the default log settings are very noisy.
LOG_LEVEL = "DEBUG"
-LOG_FILE = "/tmp/rapidsms.log"
+LOG_FILE = "rapidsms.log"
LOG_FORMAT = "[%(name)s]: %(message)s"
LOG_SIZE = 8192 # 8192 bytes = 64 kb
LOG_BACKUPS = 256 # number of logs to keep
-# ugh. this is why django is garbage. these weird dependencies should be
-# handled by their respective apps, but they're not, so here they are.
+# these weird dependencies should be handled by their respective apps,
+# but they're not, so here they are. most of them are for django admin.
TEMPLATE_CONTEXT_PROCESSORS = [
"django.core.context_processors.auth",
"django.core.context_processors.debug",
@@ -156,3 +144,37 @@
"django.core.context_processors.request"
]
+
+# -------------------------------------------------------------------- #
+# HERE BE DRAGONS! #
+# these settings are pure hackery, and will go away soon #
+# -------------------------------------------------------------------- #
+
+
+# these apps should not be started by rapidsms in your tests, however,
+# the models and bootstrap will still be available through django.
+TEST_EXCLUDED_APPS = [
+ "django.contrib.sessions",
+ "django.contrib.contenttypes",
+ "django.contrib.auth",
+ "rapidsms",
+ "rapidsms.contrib.ajax",
+ "rapidsms.contrib.httptester",
+]
+
+
+# the default ROOT_URLCONF module, bundled with rapidsms, detects and
+# maps the urls.py module of each app into a single project urlconf.
+# this is handy, but too magical for the taste of some. (remove it?)
+ROOT_URLCONF = "rapidsms.djangoproject.urls"
+
+
+# since we might hit the database from any thread during testing, the
+# in-memory sqlite database isn't sufficient. it spawns a separate
+# virtual database for each thread, and syncdb is only called for the
+# first. this leads to confusing "no such table" errors. so i'm
+# defaulting to a temporary file instead.
+import os, tempfile
+TEST_DATABASE_NAME = os.path.join(
+ tempfile.gettempdir(),
+ "rapidsms.test.sqlite3")
View
15 lib/rapidsms/skeleton/project/urls.py
@@ -0,0 +1,15 @@
+#!/usr/bin/env python
+# vim: ai ts=4 sts=4 et sw=4
+
+
+# i'm afraid that url routing within rapidsms is a bit of a mess, right
+# now. the rapidsms.djangoproject.urls module reveals artifacts of an
+# earlier, more magical framework. you can add your urls here, but the
+# urls of the contrib apps are bundled within them, making them rather
+# difficult to change. fixing this (removing the magic) is a priority.
+
+
+from django.conf.urls.defaults import *
+urlpatterns = patterns("",
+
+)
View
2  setup.py
@@ -17,6 +17,8 @@
"djappsettings"
],
+ scripts = ["bin/rapidsms-admin.py"],
+
author="RapidSMS development community",
author_email="rapidsms@googlegroups.com",
Please sign in to comment.
Something went wrong with that request. Please try again.