1
# FreeCAD RevInfo script to get the revision information from Subversion.
2
# (c) 2006 Werner Mayer
4
# Under Linux the Subversion tool SubWCRev shipped with TortoiseSVN isn't
5
# available which is provided by this script.
7
#***************************************************************************
8
#* Copyright (c) 2006 Werner Mayer <werner.wm.mayer@gmx.de> *
10
#* This file is part of the FreeCAD CAx development system. *
12
#* This program is free software; you can redistribute it and/or modify *
13
#* it under the terms of the GNU General Public License (GPL) *
14
#* as published by the Free Software Foundation; either version 2 of *
15
#* the License, or (at your option) any later version. *
16
#* for detail see the LICENCE text file. *
18
#* FreeCAD is distributed in the hope that it will be useful, *
19
#* but WITHOUT ANY WARRANTY; without even the implied warranty of *
20
#* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
21
#* GNU Library General Public License for more details. *
23
#* You should have received a copy of the GNU Library General Public *
24
#* License along with FreeCAD; if not, write to the Free Software *
25
#* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 *
28
#***************************************************************************
31
import os,sys,string,re,time
33
import xml.sax.handler
34
import xml.sax.xmlreader
37
# SAX handler to parse the subversion output
38
class SvnHandler(xml.sax.handler.ContentHandler):
44
def startElement(self, name, attributes):
47
self.mapping["Rev"] = attributes["revision"]
53
def characters(self, data):
59
def endElement(self, name):
62
self.mapping["Url"] = self.buffer
66
self.mapping["Date"] = self.buffer
71
#if(len(sys.argv) != 2):
72
# sys.stderr.write("Usage: SubWCRev \"`svn info .. --xml`\"\n")
74
parser=xml.sax.make_parser()
76
parser.setContentHandler(handler)
78
#Create an XML stream with the required information and read in with a SAX parser
79
Ver=os.popen("svnversion . -n").read()
80
Info=os.popen("svn info . --xml").read()
82
inpsrc = xml.sax.InputSource()
83
strio=StringIO.StringIO(Info)
84
inpsrc.setByteStream(strio)
87
sys.stderr.write("No svn repository\n")
90
#Information of the Subversion stuff
91
Url = handler.mapping["Url"]
92
Rev = handler.mapping["Rev"]
93
Date = handler.mapping["Date"]
95
#Same format as SubWCRev does
96
Date = string.replace(Date,'T',' ')
97
Date = string.replace(Date,'-','/')
99
#Date is given as GMT. Now we must convert to local date.
100
m=time.strptime(Date,"%Y/%m/%d %H:%M:%S")
101
#Copy the tuple and set tm_isdst to 0 because it's GMT
102
l=(m.tm_year,m.tm_mon,m.tm_mday,m.tm_hour,m.tm_min,m.tm_sec,m.tm_wday,m.tm_yday,0)
103
#Take timezone into account
104
t=time.mktime(l)-time.timezone
105
Date=time.strftime("%Y/%m/%d %H:%M:%S",time.localtime(t))
107
#Get the current local date
108
Time = time.strftime("%Y/%m/%d %H:%M:%S")
110
Mods = 'Src not modified'
111
Mixed = 'Src not mixed'
114
# if version string ends with an 'M'
115
r=re.search("M$",Ver)
117
Mods = 'Src modified'
119
# if version string contains a range
120
r=re.match("^\\d+\\:\\d+",Ver)
123
Range = Ver[:r.end()]
125
# Open the template file and the version file
126
file = open("./src/Build/Version.h.in")
127
lines = file.readlines()
129
out = open("./src/Build/Version.h","w");
132
line = string.replace(line,'$WCREV$',Rev)
133
line = string.replace(line,'$WCDATE$',Date)
134
line = string.replace(line,'$WCRANGE$',Range)
135
line = string.replace(line,'$WCURL$',Url)
136
line = string.replace(line,'$WCNOW$',Time)
137
line = string.replace(line,'$WCMODS?Src modified:Src not modified$',Mods)
138
line = string.replace(line,'$WCMIXED?Src mixed:Src not mixed$',Mixed)
143
if __name__ == "__main__":