1 | #! /usr/bin/env python |
---|
2 | |
---|
3 | #------------------------------------------------------------------------ |
---|
4 | # This file is distributed under the Common Public License. |
---|
5 | # It is part of the BuildTools project in COIN-OR (www.coin-or.org) |
---|
6 | #------------------------------------------------------------------------ |
---|
7 | |
---|
8 | import os |
---|
9 | import urllib2 |
---|
10 | import re |
---|
11 | import sys |
---|
12 | |
---|
13 | import NBlogMessages |
---|
14 | import NBemail |
---|
15 | import NBosCommand |
---|
16 | |
---|
17 | #------------------------------------------------------------------------ |
---|
18 | # Function for executing svn commands |
---|
19 | # svnCmd: String representing svn command |
---|
20 | # dir: Directory where command is to be run from |
---|
21 | # project: Coin project running the command (this is used to provide |
---|
22 | # a better message if an error is detected |
---|
23 | # return: the result of the NBosCommand call; |
---|
24 | # return['returnCode'] is the return code of svn |
---|
25 | #------------------------------------------------------------------------ |
---|
26 | def run(svnCmd,dir,project) : |
---|
27 | os.chdir(dir) |
---|
28 | NBlogMessages.writeMessage(' cd '+dir) |
---|
29 | NBlogMessages.writeMessage(' '+svnCmd) |
---|
30 | result = NBosCommand.run(svnCmd) |
---|
31 | if result['returnCode'] != 0 : |
---|
32 | NBemail.sendCmdMsgs(project,result,svnCmd) |
---|
33 | return result |
---|
34 | |
---|
35 | |
---|
36 | #------------------------------------------------------------------------ |
---|
37 | # Function which returns the latest stable version of a project |
---|
38 | #------------------------------------------------------------------------ |
---|
39 | def latestStableVersion(project) : |
---|
40 | url='https://projects.coin-or.org/svn/'+project+'/stable' |
---|
41 | handle=urllib2.urlopen(url) |
---|
42 | html=handle.read() |
---|
43 | handle.close() |
---|
44 | |
---|
45 | # In html code find the latest version number |
---|
46 | # <li><a href="3.2/">3.2/</a></li> |
---|
47 | # <li><a href="3.3/">3.3/</a></li> |
---|
48 | r=r'<li><a href="(\d*\.\d*)/">(\d*\.\d*)/</a></li>' |
---|
49 | findResult=re.findall(r,html) |
---|
50 | if len(findResult)==0: return False |
---|
51 | latestStableVersionRepeated2Times = findResult[-1:][0] |
---|
52 | latestStableVersion=latestStableVersionRepeated2Times[0] |
---|
53 | return latestStableVersion |
---|
54 | |
---|
55 | #------------------------------------------------------------------------ |
---|
56 | # Function which returns the latest release version of a project |
---|
57 | # If there isn't a release version then False is returned |
---|
58 | #------------------------------------------------------------------------ |
---|
59 | def latestReleaseVersion(project) : |
---|
60 | url='https://projects.coin-or.org/svn/'+project+'/releases' |
---|
61 | handle=urllib2.urlopen(url) |
---|
62 | html=handle.read() |
---|
63 | handle.close() |
---|
64 | |
---|
65 | # In html code find the latest version number |
---|
66 | # <li><a href="1.6.0/">1.6.0/</a></li> |
---|
67 | r=r'<li><a href="(\d*\.\d*.\d*)/">(\d*\.\d*.\d*)/</a></li>' |
---|
68 | findResult=re.findall(r,html) |
---|
69 | if len(findResult)==0: return False |
---|
70 | latestReleaseVersionRepeated2Times = findResult[-1:][0] |
---|
71 | latestReleaseVersion=latestReleaseVersionRepeated2Times[0] |
---|
72 | return latestReleaseVersion |
---|
73 | |
---|
74 | |
---|
75 | #------------------------------------------------------------------------ |
---|
76 | # Return svn revision number or url |
---|
77 | # If not found the return -1 |
---|
78 | #------------------------------------------------------------------------ |
---|
79 | def svnRevision(url) : |
---|
80 | retVal=-1 |
---|
81 | result = NBosCommand.run('svn info '+url) |
---|
82 | if result['returnCode']==0 : |
---|
83 | #reg=r'Revision: (\d+)' |
---|
84 | reg=r'Last Changed Rev: (\d+)' |
---|
85 | found=re.findall(reg,result['stdout']) |
---|
86 | if len(found)!=0 : |
---|
87 | retVal=int(found[0]) |
---|
88 | return retVal |
---|
89 | |
---|
90 | |
---|
91 | #------------------------------------------------------------------------ |
---|
92 | # newer(source, target) |
---|
93 | # Return true if source and is more recently modified than target, |
---|
94 | # (ie return true if source is newer than target and target needs |
---|
95 | # to be rebuilt). |
---|
96 | # |
---|
97 | # If either sourrce or target don't exist then true is returned. |
---|
98 | # |
---|
99 | #------------------------------------------------------------------------ |
---|
100 | def newer(source,target) : |
---|
101 | |
---|
102 | #print '------------------------' |
---|
103 | #print source |
---|
104 | #print target |
---|
105 | #print '------------------------' |
---|
106 | #print ' ' |
---|
107 | |
---|
108 | tarRev=svnRevision(target) |
---|
109 | if tarRev==-1 : |
---|
110 | # Target probably does not exist. It does not have an svn revision |
---|
111 | # nubmer, so return that it is out of date. |
---|
112 | return "Does not exist: "+target |
---|
113 | |
---|
114 | srcRev=svnRevision(source) |
---|
115 | if srcRev==-1 : |
---|
116 | # Source should exist. Something is wrong that will be caught |
---|
117 | # when an 'svn checkout' is done. |
---|
118 | return "Does not exist: "+source |
---|
119 | |
---|
120 | if srcRev>tarRev : |
---|
121 | return "New revision of: "+source |
---|
122 | |
---|
123 | # if there is an externals file then process it |
---|
124 | extFileName=os.path.join(target,"Externals") |
---|
125 | if os.path.isfile(extFileName) : |
---|
126 | extFilePtr = open(extFileName, "r") |
---|
127 | line = extFilePtr.readline() |
---|
128 | |
---|
129 | while line: |
---|
130 | line=line.strip() |
---|
131 | if line!='' : |
---|
132 | if line[0]!='#': |
---|
133 | reg=r'(\S+)(\s+)(\S+)' |
---|
134 | found=re.findall(reg,line) |
---|
135 | if len(found)!=1: |
---|
136 | # something is wrong. Do a rebuild |
---|
137 | return "Assumed out of date when reading: "+extFileName |
---|
138 | found=found[0] |
---|
139 | if len(found)!=3 : |
---|
140 | # something is wrong. Do a rebuild |
---|
141 | return "Assumed out of date when reading: "+extFileName |
---|
142 | extTarget=os.path.join(target,found[0]) |
---|
143 | extSource=found[2] |
---|
144 | # Recursive call to see if external indicates rebuild |
---|
145 | msg=newer(extSource,extTarget) |
---|
146 | if msg : |
---|
147 | extFilePtr.close() |
---|
148 | return msg |
---|
149 | line = extFilePtr.readline() |
---|
150 | |
---|
151 | extFilePtr.close() |
---|
152 | |
---|
153 | return False |
---|
154 | |
---|