]> git.donarmstrong.com Git - lilypond.git/blob - stepmake/bin/packagepython.py
Merge branch 'jneeman' of git+ssh://jneem@git.sv.gnu.org/srv/git/lilypond into jneeman
[lilypond.git] / stepmake / bin / packagepython.py
1 #!/usr/bin/python
2
3
4 #ugh. junkme.
5
6 # packagepython.py --  implement general StepMake-wide python stuff
7
8 # source file of the GNU LilyPond music typesetter
9
10 # (c) 1997--2006 Han-Wen Nienhuys <hanwen@stack.nl>
11 #                Jan Nieuwenhuizen <janneke@gnu.org>
12
13 import re
14 import string
15
16 import sys
17 import os
18 import getopt
19
20 make_assign_re = re.compile ('^([A-Z_]*)=(.*)$')
21
22 def read_makefile (fn):
23     file = open (fn)
24     lines = file.readlines()
25
26     mi = pa = mj = 0
27     mp = ''
28
29     make_dict = {}
30     for l in lines:
31         m = make_assign_re.search (l)
32         if m:
33             nm = m.group (1)
34             val = m.group (2)
35             make_dict[nm] = val
36     return make_dict
37
38 class Package:
39     def __init__ (self, dirname):
40         dict = read_makefile (dirname + '/VERSION')
41         version_list = []
42         for x in [ 'MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_LEVEL']:
43             version_list.append (string.atoi (dict[x]))
44         version_list.append (dict['MY_PATCH_LEVEL'])
45         self.topdir = dirname
46         self.groupdir = self.topdir + '/..'
47         self.patch_dir = self.groupdir + '/patches/'
48         self.release_dir = self.groupdir + '/releases/'
49         self.test_dir = self.groupdir + '/test/'
50         self.version =  tuple(version_list)
51         self.Name = dict['PACKAGE_NAME']
52         self.name = string.lower (self.Name)
53         if self.name == 'lilypond':
54             self.nickname = 'lelie'
55         else:
56             self.nickname = self.name
57         self.NAME = string.upper (self.Name)
58
59
60 class Packager:
61     def __init__ (self):
62         try:
63             m= os.environ['MAILADDRESS']
64         except KeyError:
65             m= '(address unknown)'
66         self.mail= m
67         try:
68             m= os.environ['WEBMASTER']
69         except KeyError:
70             m= self.mail
71         self.webmaster= m
72
73
74 def full_version_tup(tup):
75     t = [0,0,0,'']
76     for i in range (4):
77      try:
78          t[i] = tup[i]
79      except IndexError:
80          break
81     return tuple(t)
82
83 def split_my_patchlevel (str):
84     m = re.match ('(.*?)([0-9]*)$', str)
85     return (m.group (1), string.atoi (m.group (2)))
86
87 def next_version(tup):
88     l = list(full_version_tup (tup))
89     t3name=t3num=''
90     if l[3]:
91         (t3name,t3num)= split_my_patchlevel (l[3])
92         if t3num: 
93             t3num = '%d' % (t3num + 1)
94         else:
95             t3num = t3name =''
96     else:
97         l[2] = l[2] +1
98
99     return tuple(l[0:3] + [t3name +  t3num])
100
101 def prev_version(tup):
102     l = list(full_version_tup (tup))
103     t3name=t3num=''
104     if l[3]:
105         (t3name, t3num) = split_my_patchlevel (l[3])
106         if t3num and t3num - 1 > 0:
107             t3num = '%d' %(t3num - 1)
108         else:
109             t3num = t3name =''
110
111     else:
112         l[2] = l[2] -1
113         
114     return tuple(l[0:3] + [t3name +  t3num])
115
116 def version_tuple_to_str(tup):
117     tup = full_version_tup (tup)
118     if tup[3]:
119         my = '.' + tup[3]
120     else:
121         my = ''
122     return ('%d.%d.%d' % tup[0:3]) + my
123
124 def version_str_to_tuple(str):
125     t = string.split(str, '.')
126     mypatch = ''
127     if len (t) >= 4:
128         mypatch = string.join (t[3:], '.')
129     return (string.atoi(t[0]), string.atoi(t[1]), string.atoi(t[2]), mypatch)
130
131 def version_compare (ltup, rtup):
132     rtup = full_version_tup (ltup)
133     rtup = full_version_tup (rtup)
134     for i in (0,1,2):
135         if ltup[i] - rtup[i]: return ltup[i] - rtup[i]
136     if ltup[3] and rtup[3]:
137         (lname, lnum) = split_my_patchlevel (ltup[i])
138         (rname, rnum) = split_my_patchlevel (rtup[3])
139         if lname != rname:
140             raise 'ambiguous'
141         return sign (lnum - rnum)
142     if ltup[3]:
143         return 1
144     else:
145         return -1
146     
147 if __name__ == '__main__':
148     p = Package ('.')
149     v=  p.version
150     print v, prev_version(v), next_version(v)
151     pv=(0,1,1,'jcn4')
152     print version_tuple_to_str(pv), prev_version(pv), next_version(pv)
153     print version_tuple_to_str((0,1,1,''))    
154     print full_version_tup ((0,1))
155
156     
157 def dump_file(f, s):
158     i = open(f, 'w')
159     i.write(s)
160     i.close ()
161