gst-qa-system: web/settings.py: Allow daemon to be run from anywhere

Tim Müller tpm at kemper.freedesktop.org
Thu Sep 8 08:34:26 PDT 2011


Module: gst-qa-system
Branch: master
Commit: c68d67950e04bbd992ce9a17b7f0f596a60efd1f
URL:    http://cgit.freedesktop.org/gstreamer/gst-qa-system/commit/?id=c68d67950e04bbd992ce9a17b7f0f596a60efd1f

Author: David Laban <david.laban at collabora.co.uk>
Date:   Thu Sep  8 13:09:07 2011 +0100

web/settings.py: Allow daemon to be run from anywhere

* Fallback if PROJECT_PATH/.. is not writable
 * Uses PROJECT_PATH/.. or xdg.BaseDirectory.save_data_path() if possible,
   or $PWD as a last resort.
* cd from within daemon.py, so that users don't have to.

---

 README                                        |    7 +++----
 web/insanityweb/management/commands/daemon.py |    1 +
 web/settings.py                               |   18 ++++++++++++++++--
 3 files changed, 20 insertions(+), 6 deletions(-)

diff --git a/README b/README
index 27e1349..452c380 100644
--- a/README
+++ b/README
@@ -70,11 +70,10 @@ To configure the Django frontend:
 
   * configure the test folders in settings.py (see below for syntax)
 
-  The hybrid django+gtk server needs to be run from the web/ directory
-using the 'daemon' management command:
+  The hybrid django+gtk server needs to be run using the 'daemon'
+management command:
 
-  > cd /usr/share/insanity/web/
-  > python manage.py daemon
+  > python /usr/share/insanity/web/manage.py daemon
 
   The daemon command behaves like 'runserver --noreload', and can take
 any additional arguments that runserver can. So, for example, IP and
diff --git a/web/insanityweb/management/commands/daemon.py b/web/insanityweb/management/commands/daemon.py
index 918c0b8..d8cb00c 100644
--- a/web/insanityweb/management/commands/daemon.py
+++ b/web/insanityweb/management/commands/daemon.py
@@ -18,6 +18,7 @@ class Command(BaseRunserverCommand):
     help = 'Start the Insanity integrated web + test runner'
 
     def run(self, *args, **options):
+        os.chdir(DATA_PATH)
         runner = get_runner()
         try:
             server = WSGIServer((self.addr, int(self.port)), WSGIRequestHandler)
diff --git a/web/settings.py b/web/settings.py
index f3bf903..e048bf6 100644
--- a/web/settings.py
+++ b/web/settings.py
@@ -1,5 +1,19 @@
 import os
+import sys
+
 PROJECT_PATH = os.path.abspath(os.path.dirname(__file__))
+DATA_PATH = os.path.join(PROJECT_PATH, '..')
+
+if not os.access(DATA_PATH, os.W_OK):
+    sys.stderr.write("%s is not writable. Trying xdg-data-path.\n" %
+            DATA_PATH)
+    try:
+        import xdg.BaseDirectory
+        DATA_PATH = xdg.BaseDirectory.save_data_path("insanity")
+    except (ImportError, OSError):
+        sys.stderr.write("xdg.BaseDirectory doesn't exist or doesn't work.\n")
+        DATA_PATH = os.getcwd()
+    sys.stderr.write("Data will be saved to %s.\n" % DATA_PATH)
 
 # Django settings for web project.
 
@@ -15,7 +29,7 @@ MANAGERS = ADMINS
 DATABASES = {
     'default': {
         'ENGINE': 'django.db.backends.sqlite3',
-        'NAME': os.path.join(PROJECT_PATH, '..', 'testrun.db'),
+        'NAME': os.path.join(DATA_PATH, 'testrun.db'),
         'USER': '',
         'PASSWORD': '',
         'HOST': '',
@@ -85,7 +99,7 @@ INSTALLED_APPS = (
     'django.contrib.sessions',
     'django.contrib.sites',
     'django.contrib.admin',
-    'web.insanityweb'
+    'insanityweb'
 )
 
 # A map of folders that the tests can be run in, with any extra arguments that



More information about the gstreamer-commits mailing list