File: packagepython.py

package info (click to toggle)
lilypond 2.2.6-3
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 11,260 kB
  • ctags: 7,622
  • sloc: cpp: 47,787; lisp: 11,217; python: 11,203; sh: 3,290; yacc: 2,011; lex: 831; perl: 373; ansic: 309; makefile: 132; csh: 8
file content (161 lines) | stat: -rwxr-xr-x 3,488 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#!/usr/bin/python


#ugh. junkme.

# packagepython.py --  implement general StepMake-wide python stuff
# 
# source file of the GNU LilyPond music typesetter
# 
# (c)  1997--2003 Han-Wen Nienhuys <hanwen@stack.nl>
#                Jan Nieuwenhuizen <janneke@gnu.org>

import re
import string

import sys
import os
import getopt

make_assign_re = re.compile ('^([A-Z_]*)=(.*)$')

def read_makefile (fn):
	file = open (fn)
	lines = file.readlines()

	mi = pa = mj = 0
	mp = ''

	make_dict = {}
	for l in lines:
		m = make_assign_re.search (l)
		if m:
			nm = m.group (1)
			val = m.group (2)
			make_dict[nm] = val
	return make_dict

class Package:
	def __init__ (self, dirname):
		dict = read_makefile (dirname + '/VERSION')
		version_list = []
		for x in [ 'MAJOR_VERSION', 'MINOR_VERSION', 'PATCH_LEVEL']:
			version_list.append (string.atoi (dict[x]))
		version_list.append (dict['MY_PATCH_LEVEL'])
		self.topdir = dirname
		self.groupdir = self.topdir + '/..'
		self.patch_dir = self.groupdir + '/patches/'
		self.release_dir = self.groupdir + '/releases/'
		self.test_dir = self.groupdir + '/test/'
		self.version =  tuple(version_list)
		self.Name = dict['PACKAGE_NAME']
		self.name = string.lower (self.Name)
		if self.name == 'lilypond':
			self.nickname = 'lelie'
		else:
			self.nickname = self.name
		self.NAME = string.upper (self.Name)


class Packager:
	def __init__ (self):
		try:
			m= os.environ['MAILADDRESS']
		except KeyError:
			m= '(address unknown)'
		self.mail= m
		try:
			m= os.environ['WEBMASTER']
		except KeyError:
			m= self.mail
		self.webmaster= m


def full_version_tup(tup):
	t = [0,0,0,'']
	for i in range (4):
	  try:
		  t[i] = tup[i]
	  except IndexError:
		  break
	return tuple(t)

def split_my_patchlevel (str):
	m = re.match ('(.*?)([0-9]*)$', str)
	return (m.group (1), string.atoi (m.group (2)))

def next_version(tup):
	l = list(full_version_tup (tup))
	t3name=t3num=''
	if l[3]:
		(t3name,t3num)= split_my_patchlevel (l[3])
		if t3num: 
			t3num = '%d' % (t3num + 1)
		else:
			t3num = t3name =''
	else:
		l[2] = l[2] +1

	return tuple(l[0:3] + [t3name +  t3num])

def prev_version(tup):
	l = list(full_version_tup (tup))
	t3name=t3num=''
	if l[3]:
		(t3name, t3num) = split_my_patchlevel (l[3])
		if t3num and t3num - 1 > 0:
			t3num = '%d' %(t3num - 1)
		else:
			t3num = t3name =''

	else:
		l[2] = l[2] -1
		
	return tuple(l[0:3] + [t3name +  t3num])

def version_tuple_to_str(tup):
	tup = full_version_tup (tup)
	if tup[3]:
		my = '.' + tup[3]
	else:
		my = ''
	return ('%d.%d.%d' % tup[0:3]) + my

def version_str_to_tuple(str):
	t = string.split(str, '.')
	mypatch = ''
	if len (t) >= 4:
		mypatch = string.join (t[3:], '.')
	return (string.atoi(t[0]), string.atoi(t[1]), string.atoi(t[2]), mypatch)

def version_compare (ltup, rtup):
	rtup = full_version_tup (ltup)
	rtup = full_version_tup (rtup)
	for i in (0,1,2):
		if ltup[i] - rtup[i]: return ltup[i] - rtup[i]
	if ltup[3] and rtup[3]:
		(lname, lnum) = split_my_patchlevel (ltup[i])
		(rname, rnum) = split_my_patchlevel (rtup[3])
		if lname != rname:
			raise 'ambiguous'
		return sign (lnum - rnum)
	if ltup[3]:
		return 1
	else:
		return -1
	
if __name__ == '__main__':
	p = Package ('.')
	v=  p.version
	print v, prev_version(v), next_version(v)
	pv=(0,1,1,'jcn4')
	print version_tuple_to_str(pv), prev_version(pv), next_version(pv)
	print version_tuple_to_str((0,1,1,''))    
	print full_version_tup ((0,1))

	
def dump_file(f, s):
	i = open(f, 'w')
	i.write(s)
	i.close ()