Patchwork New module to set appropriate sys.path for scripts.

login
register
mail settings
Submitter Guilherme Salgado
Date March 21, 2011, 5:33 p.m.
Message ID <20110321173329.6569.61360.stgit@localhost6.localdomain6>
Download mbox | patch
Permalink /patch/87804/
State Superseded
Headers show

Comments

Guilherme Salgado - March 21, 2011, 5:33 p.m.
This is so that we don't have to write a wrapper shell script for every python
script we have in app/patchwork/bin/.

Signed-off-by: Guilherme Salgado <guilherme.salgado@linaro.org>
---
 apps/patchwork/bin/_pythonpath.py |   15 +++++++++++++++
 1 files changed, 15 insertions(+), 0 deletions(-)
 create mode 100644 apps/patchwork/bin/_pythonpath.py

Patch

diff --git a/apps/patchwork/bin/_pythonpath.py b/apps/patchwork/bin/_pythonpath.py
new file mode 100644
index 0000000..0d8845d
--- /dev/null
+++ b/apps/patchwork/bin/_pythonpath.py
@@ -0,0 +1,15 @@ 
+"""Add the <patchwork>/apps and <patchwork>/lib/python directories to
+sys.path.
+
+Also sets the DJANGO_SETTINGS_MODULE environment variable to 'settings'.
+"""
+import os
+import sys
+
+
+patchwork_bin = os.path.dirname(__file__)
+patchwork_base = os.path.abspath(
+    os.path.join(patchwork_bin, '..', '..', '..'))
+sys.path.insert(0, '%s/lib/python' % patchwork_base)
+sys.path.insert(0, '%s/apps' % patchwork_base)
+os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'