File: util.py

package info (click to toggle)
pyopengl 2.0.1.08-5.1
  • links: PTS
  • area: main
  • in suites: sarge
  • size: 19,484 kB
  • ctags: 9,036
  • sloc: pascal: 64,950; xml: 28,088; ansic: 20,696; python: 19,761; tcl: 668; makefile: 240; sh: 25
file content (51 lines) | stat: -rw-r--r-- 1,244 bytes parent folder | download | duplicates (2)
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
import re, os, os.path, string


def get_build_info(file):
	BUILD = {'api_versions':[0x100], 'shadow':0, 'headers':[], 'api_version_check':0, 'include_dirs':[], 'sources':[]}
		
	x = open(file).read()
	x = string.replace(x, '\r\n', '\n')
	x = string.replace(x, '\r', '\n')
	for name, value in re.findall(r'[#]\s*BUILD\s+([^\s]+)\s+((?:[^\n\\]+|\\.|\\\n)+)', x):
		BUILD[name] = eval(string.strip(string.replace(value, '\\\n', ' ')))

	BUILD['api_versions'].sort()
	BUILD['api_versions'].reverse()

	return BUILD	


def outdated(x, dependencies):
	if not os.path.exists(x):
		return 1
	x_mtime = os.path.getmtime(x)
	for dependency in dependencies:
		if x_mtime < os.path.getmtime(dependency):
			return 1
	return 0


def mkdir(x):
	head, tail = os.path.split(x)
	if head != '':
		mkdir(head)
	if not os.path.exists(x):
		os.mkdir(x)


build_re = re.compile("__build__\s*=\s*(.+)")


def get_version():
	return string.strip(open(os.path.join('OpenGL', 'version')).read())


def increment_build():
	p = os.path.join('OpenGL', '__init__.py')
	x = open(p).read()
	builds = build_re.findall(x)
	if len(builds):
		x = build_re.sub('__build__ = %d' % (int(builds[0]) + 1), x)
		open(p, 'w').write(x)