From: Ian Campbell Subject: [PATCH OSSTEST v2 1/2] tcl: Handle environment variables which are unset. Date: Tue, 31 Mar 2015 16:06:46 +0100 Message-ID: <1427814407-28551-1-git-send-email-ian.campbell@citrix.com> References: <1427814392.2115.165.camel@citrix.com> Mime-Version: 1.0 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Return-path: In-Reply-To: <1427814392.2115.165.camel@citrix.com> List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org To: ian.jackson@eu.citrix.com Cc: Ian Campbell , xen-devel@lists.xen.org List-Id: xen-devel@lists.xenproject.org This allows wrappers such as the standalone wrapper to do OSSTEST_SIMULATE=$foo ./sg-run-job and not worry if $foo is unset. Do likewise for OSSTEST_TCL_JOBDB_DEBUG. Signed-off-by: Ian Campbell Signed-off-by: Ian Jackson --- v2: - Was: "sg-run-job: Only consider $OSSTEST_SIMULATE > 0" - Insert before "standalone: Add --dry-run option for run-job." - Use var-or-default from Ian J --- sg-run-job | 2 +- tcl/JobDB-Executive.tcl | 2 +- tcl/osstestlib.tcl | 6 ++++++ 3 files changed, 8 insertions(+), 2 deletions(-) diff --git a/sg-run-job b/sg-run-job index 0ec314f..eae159d 100755 --- a/sg-run-job +++ b/sg-run-job @@ -159,7 +159,7 @@ proc spawn-ts {iffail testid args} { jobdb::spawn-step-commit $flight $jobinfo(job) $stepno $testid set xprefix {} - if {[info exists env(OSSTEST_SIMULATE)]} { set xprefix echo } + if {[var-or-default env(OSSTEST_SIMULATE) 0]} { set xprefix echo } set log [jobdb::step-log-filename $flight $jobinfo(job) $stepno $ts] set redirects {< /dev/null} diff --git a/tcl/JobDB-Executive.tcl b/tcl/JobDB-Executive.tcl index 430ea84..7228712 100644 --- a/tcl/JobDB-Executive.tcl +++ b/tcl/JobDB-Executive.tcl @@ -117,7 +117,7 @@ proc db-update-1 {stmt} { } proc db-execute-debug {stmt} { - if {[info exists env(OSSTEST_TCL_JOBDB_DEBUG)]} { + if {[var-or-default env(OSSTEST_TCL_JOBDB_DEBUG) 0]} { puts stderr "EXECUTING >$stmt<" } } diff --git a/tcl/osstestlib.tcl b/tcl/osstestlib.tcl index a0413c4..61a6a09 100644 --- a/tcl/osstestlib.tcl +++ b/tcl/osstestlib.tcl @@ -74,3 +74,9 @@ proc lshift {listvar} { set list [lrange $list 1 end] return $head } + +proc var-or-default {varname {default {}}} { + upvar 1 $varname var + if {[info exists var]} { return $var } + return $default +} -- 2.1.4