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