From patchwork Fri Apr 15 18:13:26 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Guilherme Salgado X-Patchwork-Id: 91428 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from ozlabs.org (localhost [IPv6:::1]) by ozlabs.org (Postfix) with ESMTP id EE80C1007E5 for ; Sat, 16 Apr 2011 04:13:33 +1000 (EST) Received: from adelie.canonical.com (adelie.canonical.com [91.189.90.139]) by ozlabs.org (Postfix) with ESMTP id A58281007D1 for ; Sat, 16 Apr 2011 04:13:32 +1000 (EST) Received: from youngberry.canonical.com ([91.189.89.112]) by adelie.canonical.com with esmtp (Exim 4.71 #1 (Debian)) id 1QAnWN-0005qx-9K; Fri, 15 Apr 2011 18:13:31 +0000 Received: from [187.126.166.24] (helo=feioso) by youngberry.canonical.com with esmtpsa (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1QAnWM-0001bW-Go; Fri, 15 Apr 2011 18:13:31 +0000 Received: from localhost6.localdomain6 (localhost.localdomain [127.0.0.1]) by feioso (Postfix) with ESMTP id 2F6314024F; Fri, 15 Apr 2011 15:13:26 -0300 (BRT) Subject: [PATCH V3] New module to set appropriate sys.path for scripts To: patchwork@lists.ozlabs.org From: Guilherme Salgado Date: Fri, 15 Apr 2011 15:13:26 -0300 Message-ID: <20110415181317.22565.47566.stgit@localhost6.localdomain6> In-Reply-To: <20110415173950.21098.98622.stgit@localhost6.localdomain6> References: <20110415173950.21098.98622.stgit@localhost6.localdomain6> User-Agent: StGit/0.15 MIME-Version: 1.0 Cc: patches@linaro.org X-BeenThere: patchwork@lists.ozlabs.org X-Mailman-Version: 2.1.14 Precedence: list List-Id: Patchwork development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: patchwork-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org 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 --- 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 --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 /apps and /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 -# -# 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