diff mbox

[V3] New module to set appropriate sys.path for scripts

Message ID 20110415181317.22565.47566.stgit@localhost6.localdomain6
State Superseded
Headers show

Commit Message

Guilherme Salgado April 15, 2011, 6:13 p.m. UTC
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 +++++++++++++++
 apps/patchwork/bin/parsemail-batch.sh |    2 +-
 apps/patchwork/bin/parsemail.py       |    1 +
 apps/patchwork/bin/parsemail.sh       |   29 -----------------------------
 4 files changed, 17 insertions(+), 30 deletions(-)
 create mode 100644 apps/patchwork/bin/_pythonpath.py
 delete mode 100755 apps/patchwork/bin/parsemail.sh
diff mbox

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'
diff --git a/apps/patchwork/bin/parsemail-batch.sh b/apps/patchwork/bin/parsemail-batch.sh
index 31ef4f0..59fe408 100755
--- a/apps/patchwork/bin/parsemail-batch.sh
+++ b/apps/patchwork/bin/parsemail-batch.sh
@@ -41,5 +41,5 @@  ls -1rt "$mail_dir" |
 while read line;
 do
 	echo $line
-	$PATCHWORK_BINDIR/parsemail.sh < "$mail_dir/$line"
+	$PATCHWORK_BINDIR/parsemail.py < "$mail_dir/$line"
 done
diff --git a/apps/patchwork/bin/parsemail.py b/apps/patchwork/bin/parsemail.py
index 2e93e0a..79d4fe5 100755
--- a/apps/patchwork/bin/parsemail.py
+++ b/apps/patchwork/bin/parsemail.py
@@ -19,6 +19,7 @@ 
 # along with Patchwork; if not, write to the Free Software
 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
+import _pythonpath
 import sys
 import re
 import datetime
diff --git a/apps/patchwork/bin/parsemail.sh b/apps/patchwork/bin/parsemail.sh
deleted file mode 100755
index 6cac166..0000000
--- a/apps/patchwork/bin/parsemail.sh
+++ /dev/null
@@ -1,29 +0,0 @@ 
-#!/bin/sh
-#
-# Patchwork - automated patch tracking system
-# Copyright (C) 2008 Jeremy Kerr <jk@ozlabs.org>
-#
-# This file is part of the Patchwork package.
-#
-# Patchwork is free software; you can redistribute it and/or modify
-# it under the terms of the GNU General Public License as published by
-# the Free Software Foundation; either version 2 of the License, or
-# (at your option) any later version.
-#
-# Patchwork is distributed in the hope that it will be useful,
-# but WITHOUT ANY WARRANTY; without even the implied warranty of
-# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
-# GNU General Public License for more details.
-#
-# You should have received a copy of the GNU General Public License
-# along with Patchwork; if not, write to the Free Software
-# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
-
-BIN_DIR=`dirname $0`
-PATCHWORK_BASE=`readlink -e $BIN_DIR/../../..`
-
-PYTHONPATH="$PATCHWORK_BASE/apps":"$PATCHWORK_BASE/lib/python" \
-        DJANGO_SETTINGS_MODULE=settings \
-        "$PATCHWORK_BASE/apps/patchwork/bin/parsemail.py"
-
-exit 0