diff mbox

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

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

Commit Message

Guilherme Salgado April 15, 2011, 5:39 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>
---

This second version just uses the new module in parsemail.py and then removes
parsemail.sh, which is no longer needed.

 apps/patchwork/bin/_pythonpath.py |   15 +++++++++++++++
 apps/patchwork/bin/parsemail.py   |    1 +
 apps/patchwork/bin/parsemail.sh   |   29 -----------------------------
 3 files changed, 16 insertions(+), 29 deletions(-)
 create mode 100644 apps/patchwork/bin/_pythonpath.py
 delete mode 100755 apps/patchwork/bin/parsemail.sh

Comments

Guilherme Salgado April 15, 2011, 6:12 p.m. UTC | #1
On Fri, 2011-04-15 at 14:39 -0300, Guilherme Salgado wrote:
> 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>
> ---
> 
> This second version just uses the new module in parsemail.py and then removes
> parsemail.sh, which is no longer needed.

Aaargh, forgot to update parsemail-batch.sh to use parsemail.py instead
of parsemail.sh.  Sorry about that; sending a new version of the patch
now.
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.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