00001
00002
00003 """
00004 Version helper updates the version in 'SLIMpy/info.py'
00005
00006 """
00007
00008 __copyright__ = """
00009 Copyright 2008 Sean Ross-Ross
00010 """
00011 __license__ = """
00012 This file is part of SLIMpy .
00013
00014 SLIMpy is free software: you can redistribute it and/or modify
00015 it under the terms of the GNU Lesser General Public License as published by
00016 the Free Software Foundation, either version 3 of the License, or
00017 (at your option) any later version.
00018
00019 SLIMpy is distributed in the hope that it will be useful,
00020 but WITHOUT ANY WARRANTY; without even the implied warranty of
00021 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00022 GNU Lesser General Public License for more details.
00023
00024 You should have received a copy of the GNU Lesser General Public License
00025 along with SLIMpy . If not, see <http://www.gnu.org/licenses/>.
00026 """
00027
00028 from os import popen
00029 from os.path import dirname,exists
00030 import re
00031
00032 def getrev():
00033 """
00034 get svn dat,revision as a string using the command line
00035 'svn info \%(SLIMpy.__file__)s'
00036 """
00037 if exists('SVNINFO.txt'):
00038 svn_info = popen("cat SVNINFO.txt")
00039 else:
00040 this = dirname(__file__)
00041 svn_info = popen("svn info %(this)s" %vars())
00042 info = svn_info.read()
00043
00044 revex = re.compile("Last Changed Rev: \d*")
00045 all = revex.findall(info)
00046 try:
00047 rev = all[0][18:]
00048 except:
00049 rev = "Unknown"
00050
00051 dateex = re.compile("Last Changed Date: .*")
00052 all = dateex.findall(info)
00053 dateex = re.compile("\(.*\)")
00054 all = dateex.findall(info)
00055 try:
00056 date = all[0][1:-1]
00057 except:
00058 date = "Unknown"
00059
00060 return date, rev
00061
00062 def format(date, rev):
00063 """
00064 format data and revision in
00065 python style
00066 """
00067 return "date = '%(date)s'\nrev = '%(rev)s'" % vars()
00068
00069 def tofile(name):
00070 """
00071 put data and revision to
00072 importable python file
00073 """
00074 filed = open(name, 'w')
00075 date, rev = getrev()
00076 filed.write(format(date, rev))
00077 filed.close()
00078
00079 if __name__ == "__main__":
00080
00081 tofile("SLIMpy/info.py")
00082