source: branches/testScripts/NBosCommand.py @ 657

Last change on this file since 657 was 657, checked in by jpfasano, 13 years ago

Updated nightlyBuild to get 3rd party code, if the script for getting the
3rd party code has been updated since the 3rd party code had previously
been obtained.

  • Property svn:executable set to *
File size: 2.6 KB
Line 
1#! /usr/bin/env python
2
3from socket import gethostname
4import sys
5import os
6import re
7
8#------------------------------------------------------------------------
9# newer(source, target)
10# Return true if source exists and is more recently modified than target,
11# or if source exists and target doesn't.
12# Return false if both exist and target is the same age or newer than source.
13# Raise DistutilsFileError if source does not exist.
14#------------------------------------------------------------------------
15def newer(source,target) :
16  if sys.version[:6]<'2.5.0' :
17    # Version of python being used does not have distutils
18    if not os.path.isfile(source) : sys.exit(1)
19    if os.name!="posix" :
20      # Always assume target is out of date
21      return True
22    else :
23      # running on posix so should be able to use ls command
24      if not os.path.isfile(target) : return True
25      lsSource=run("ls --full-time "+source)
26      lsTarget=run("ls --full-time "+target)
27      #-rwxrwxrwx 1 jpf4 None 12309 2007-10-21 16:13:47.395793600 -0400 nightlyBuild.py
28      rexBase=r"(-|r|w|x){10} . (.+) (.+) (.+) (\d\d\d\d-\d\d-\d\d .+) "
29      rexSource=rexBase+source
30      rexTarget=rexBase+target
31      timeSource=(re.findall(rexSource,lsSource['stdout']))[0][4]
32      timeTarget=(re.findall(rexTarget,lsTarget['stdout']))[0][4]
33      return timeSource > timeTarget
34     
35  else :
36    import distutils.dep_util 
37    return distutils.dep_util.newer(source,target)
38
39
40#------------------------------------------------------------------------
41# Run an OS command in another process.
42# Examples might be 'svn checkout', 'make test'.
43# Return: command's return code, stdout messages, & stderr messages
44#------------------------------------------------------------------------
45def run(cmd) :
46
47  if sys.version[:6]<'2.4.0' :
48
49    # this machine has a back level of python, so must use an older
50    # techniques to implement this function.  This implementation
51    # runs the command in the same process as the script.
52    # This has the problem that if the command crashes, it will bring
53    # down the script. Another problem is that stderr and stdout are
54    # mingled together
55
56    import commands
57    result = commands.getstatusoutput(cmd)
58    retVal = { 'returnCode':result[0], 'stdout':result[1], 'stderr':'' }
59    return retVal
60
61  else :
62
63    import subprocess
64 
65    p=subprocess.Popen(cmd,shell=True,\
66                       stdout=subprocess.PIPE,\
67                       stderr=subprocess.PIPE)
68    cmdStdout,cmdStderr=p.communicate()
69    cmdRc=p.returncode
70    retVal = { 'returnCode':cmdRc, 'stdout':cmdStdout, 'stderr':cmdStderr }
71    return retVal
72
73
74
75
Note: See TracBrowser for help on using the repository browser.