Module version
[hide private]
[frames] | no frames]

Source Code for Module version

  1  #!/usr/bin/env python 
  2  ### BITPIM 
  3  ### 
  4  ### Copyright (C) 2003-2006 Roger Binns <rogerb@rogerbinns.com> 
  5  ### 
  6  ### This program is free software; you can redistribute it and/or modify 
  7  ### it under the terms of the BitPim license as detailed in the LICENSE file. 
  8  ### 
  9  ### $Id: version.py 4315 2007-07-23 01:03:58Z djpham $ 
 10   
 11  """Information about BitPim version number""" 
 12   
 13  # We'd like to record information in this file, but without subversion 
 14  # considering the file modified.  This is done by placing the information 
 15  # in the dollar id fields.  When freeze is run, it does those various 
 16  # substitutions 
 17   
 18  __FROZEN__="$Id: version.py 4315 2007-07-23 01:03:58Z djpham $" 
 19   
 20  import os, sys 
 21  import time 
 22   
 23  name="BitPim" 
 24  vendor="$Id: version.py 4315 2007-07-23 01:03:58Z djpham $" 
 25  release=0  # when rereleases of the same version happen, this gets incremented 
 26  contact="The BitPim home page is at http://www.bitpim.org.  You can post any " \ 
 27           "questions or feedback to the mailing list detailed on that page." # where users are sent to contact with feedback 
 28   
 29  # user defined version 
 30  userdefined=False 
 31  userversion="" 
 32  uservendor="" 
 33   
 34  svnrevision=0  # we don't know 
 35  # were we frozen? 
 36  f=__FROZEN__.split() 
 37  if len(f)==3: # we were - calc svnrevision 
 38      svnrevision=int(f[1]) 
 39   
 40  # fixup vendor 
 41  if vendor[1:].startswith("Id:"): 
 42      if len(vendor.split())>3: 
 43          vendor="" 
 44      else: 
 45          vendor=vendor.split()[1] 
 46   
 47  _headurl="$HeadURL: https://bitpim.svn.sourceforge.net/svnroot/bitpim/releases/1.0.7/src/version.py $".split()[1] 
 48  # work out our version number 
 49  _rp="https://bitpim.svn.sourceforge.net/svnroot/bitpim/releases/" 
 50   
 51  if userdefined: 
52 - def isdevelopmentversion(): return True
53 version=userversion 54 vendor=uservendor 55 elif _headurl.startswith(_rp):
56 - def isdevelopmentversion(): return False
57 version=_headurl[len(_rp):].split("/")[0] 58 if not vendor: 59 vendor="official" 60 else:
61 - def isdevelopmentversion(): return True
62 prefix="https://bitpim.svn.sourceforge.net/svnroot/bitpim/" 63 version="-".join(_headurl[len(prefix):].split("/")[:-2]) # -2 to prune off src/version.py 64 del prefix 65 # were we frozen? 66 if svnrevision: 67 version=version+"-"+`svnrevision` 68 if not vendor: 69 vendor="developer build" 70 71 del _headurl 72 del _rp 73 74 versionstring=version 75 76 if release>0: 77 versionstring+="-"+`release` 78 79 if not isdevelopmentversion(): 80 # dotted quad version as used on Windows (a.b.c.d where all must be digits only) 81 # we use major.minor.point.last 82 dqver=[int(x) for x in version.split(".")] 83 while len(dqver)<3: 84 dqver.append(0) 85 while len(dqver)<4: 86 dqver.append(svnrevision) 87 dqver=dqver[:4] 88 else: 89 dqver=[0,0,0,svnrevision] # svnrevision will be zero if we weren't frozen 90 91 dqverstr=".".join([`x` for x in dqver]) 92 93 del x 94 95 url="http://www.bitpim.org" 96 97 description="BitPim "+versionstring 98 copyright="(C) 2003-2006 Roger Binns and others - see http://www.bitpim.org" 99
100 -def setversion(versionstring, vendorstring='Test'):
101 """Set the version and vendor based on user's input""" 102 # my filename 103 myfilename=os.path.splitext(__file__)[0]+".py" 104 # update with new version and vendor 105 result=[] 106 if versionstring: 107 # user specifies a version 108 _versionflg='True' 109 _version=versionstring 110 _vendor=vendorstring 111 else: 112 _versionflg='False' 113 _version=_vendor='' 114 for line in file(myfilename, "rtU"): 115 if line.startswith('userversion'): 116 line='userversion="%s"\n'%_version 117 elif line.startswith('uservendor'): 118 line='uservendor="%s"\n'%_vendor 119 elif line.startswith('userdefined'): 120 line='userdefined=%s\n'%_versionflg 121 result.append(line) 122 file(myfilename, "wt").write("".join(result)) 123 # python doesn't check .pyc/.pyo files correctly so we proactively delete them 124 for ext in (".pyc", ".pyo"): 125 try: 126 os.remove(os.path.splitext(__file__)[0]+ext) 127 except OSError: 128 pass
129
130 -def __freeze():
131 # my filename 132 myfilename=os.path.splitext(__file__)[0]+".py" 133 134 # modify the frozen field with the current revision number 135 print "Freezing version" 136 svnver=os.popen("svnversion -n .", "r").read() 137 if len(svnver)<4: 138 print "svnversion command doesn't appear to be working." 139 sys.exit(3) 140 try: 141 # temporary - remove following line once code works 142 if svnver[-1]=='M': svnver=svnver[:-1] 143 [int(x) for x in svnver.split(":")] 144 except: 145 print "Your tree isn't pure. Do you have files not checked in (M)?" 146 print svnver,"was returned by svnversion" 147 sys.exit(4) 148 svnver=svnver.split(":")[-1] 149 print "Embedding svnrevision",svnver,"into",myfilename 150 result=[] 151 for line in open(myfilename, "rtU"): 152 if line.startswith('__FROZEN__="$Id:'): 153 line='__FROZEN__="$%s %s $"\n' % ("Id:", svnver) 154 result.append(line) 155 156 open(myfilename, "wt").write("".join(result)) 157 # python doesn't check .pyc/.pyo files correctly so we proactively delete them 158 for ext in (".pyc", ".pyo"): 159 try: 160 os.remove(os.path.splitext(__file__)[0]+ext) 161 except OSError: 162 pass
163 164 if __name__=='__main__': 165 import sys 166 if len(sys.argv)==1: 167 # generated for the benefit of the help 168 # purposely missing " around values 169 print "#define VERSION", versionstring 170 print "#define DATENOW", time.strftime("%d %B %Y") 171 elif sys.argv[1]=="freeze": 172 __freeze() 173 else: 174 print "Unknown arguments",sys.argv[1:] 175