summaryrefslogtreecommitdiffstats
path: root/web-export/update.py
blob: 764d3451bd05c85a9fa098a1ed7762bff5f80e6a (plain)
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
#!/usr/bin/env python

import os,re,string

xmlto = "/usr/bin/xmlto"
cvs = "http://cvs.freedesktop.org/"
git = "http://cgit.freedesktop.org/"
specindex = "specs.idx"

try:
	f = open(specindex, 'r')
	lastname = ''
	lastpath = ''
	for line in f.readlines():
		(file, revision, version, path) = string.split(line)
		use_git = False
		if file.startswith("git:"):
			use_git = True
			git_data = file.split(":")
			git_repo = git_data[1]
			file = git_data[2]
		name = os.path.splitext(os.path.split(file)[1])[0]
		# Strip version from name
		if re.search("\d\.\d+$", name):
			name = re.sub("^(.*)-([^/]*)$", "\\1", name)

		if use_git:
			url = '%s%s/plain/%s?id=%s' % (git, git_repo, file, revision)
		else:
			url = '%s%s?rev=%s' % (cvs, file, revision)

		if re.search("\.xml$", file):
			os.system("mkdir %s 2> /dev/null" % (path))
			if lastpath != path and lastname != name:
				os.system("rm -f %s/%s-latest.html" % (path, name))
				os.system("cd %s; ln -s %s-%s.html %s-latest.html" % (path,name,version,name))
				os.system("rm -f %s/latest" % (path))
				os.system("cd %s; ln -s %s latest" % (path,version))

			# if ( lastpath == path and lastname == name and os.path.isfile("%s/%s-%s.xml" % (path, name, version))):
			#	print "Updating", file, "Version", version, "rev", revision, "skipped."
			#	continue

			if os.system("wget -q '%s' -O wget.xml && (diff -q wget.xml %s/%s-%s.xml || mv wget.xml %s/%s-%s.xml)" % (url, path, name, version, path, name, version)):
				print "Updating", file, "Version", version, "rev", revision, "FAILED."
                        os.system("chmod g+w wget.xml");

			print "Updating", file, "Version", version, "rev", revision, "ok"
				
		elif re.search("\.txt$", file):
			os.system("mkdir %s 2> /dev/null" % (path))
			if lastpath != path and lastname != name:
				os.system("rm -f %s/%s-latest.txt" % (path, name))
				os.system("cd %s; ln -s %s-%s.txt %s-latest.txt" % (path,name,version,name))

			if ( lastpath == path and lastname == name and os.path.isfile("%s/%s-%s.txt" % (path, name, version))):
				print "Updating", file, "Version", version, "rev", revision, "skipped."
				continue

			if os.system("wget -q '%s' -O wget.txt && (diff -q wget.txt %s/%s-%s.txt || mv wget.txt %s/%s-%s.txt)" % (url, path, name, version, path, name, version)):
				print "Updating", file, "Version", version, "rev", revision, "FAILED."
                        os.system("chmod g+w wget.txt");

			print "Updating", file, "Version", version, "rev", revision, "ok"

		elif re.search("\.dtd$", file):
			os.system("mkdir %s 2> /dev/null" % (path))
			if lastpath != path and lastname != name:
				os.system("rm -f %s/%s-latest.dtd" % (path, name))
				os.system("cd %s; ln -s %s-%s.dtd %s-latest.dtd" % (path,name,version,name))

			if ( lastpath == path and lastname == name and os.path.isfile("%s/%s-%s.dtd" % (path, name, version))):
				print "Updating", file, "Version", version, "rev", revision, "skipped."
				continue

			if os.system("wget -q '%s' -O wget.dtd && (diff -q wget.dtd %s/%s-%s.dtd || mv wget.dtd %s/%s-%s.dtd)" % (url, path, name, version, path, name, version)):
				print "Updating", file, "Version", version, "rev", revision, "FAILED."
                        os.system("chmod g+w wget.dtd");

			print "Updating", file, "Version", version, "rev", revision, "ok"
		else:
			print "Skipping", file, ", unknown file."
			continue

		lastname = name
		lastpath = path

except IOError:
	print "Can't open", specindex


specs = os.listdir(".")

for spec in specs:
	if not os.path.isdir(spec):
		continue
	versions = os.listdir(spec)
	for file in versions:
		if re.search("\.xml$", file):
			tmp = re.sub("(.*)(\.xml)$", "\\1", file)
			name = re.sub("^(.*)-([^/]*)$", "\\1", tmp)
			ver = re.sub("^(.*)-([^/]*)$", "\\2", tmp)
			
			print "Check", os.path.join(spec,ver), os.path.isdir(os.path.join(spec,ver))
			print "Check", os.path.join(spec,name+"-"+ver+".html"), os.path.isfile(os.path.join(spec,name+"-"+ver+".html"))

			if (	not os.path.isdir(os.path.join(spec,ver))
			    	or not os.path.isfile(os.path.join(spec,name+"-"+ver+".html"))
				or os.path.getmtime(os.path.join(spec,file)) > os.path.getmtime(os.path.join(spec,name+"-"+ver+".html"))):
				os.system("rm -fR %s/%s" % (spec,ver))
				os.system("rm -f %s/%s-%s.html" % (spec,name,ver))
				os.system("mkdir %s/%s" % (spec,ver))
				os.system("cd %s/%s; %s html ../%s" % (spec,ver,xmlto,file))
				# os.system("mv index.html %s/%s-%s.html" % (spec,name,ver))
				# os.system("sed -i %s/%s-%s.html -e 's/index.html/%s-%s.html/;'" % (spec,name,ver,name,ver))
				os.system("cd %s;%s html-nochunks %s" % (spec,xmlto,file))
		elif re.search("(?<!latest)\.html$", file) and not os.path.isfile(os.path.join(spec,re.sub("html","xml",file))):
				tmp = re.sub("(.*)(\.html)$", "\\1", file)
				name = re.sub("^(.*)-([^/]*)$", "\\1", tmp)
				ver = re.sub("^(.*)-([^/]*)$", "\\2", tmp)
				os.system("rm -fR %s/%s" % (spec,ver))
				os.system("rm -f %s/%s-%s.html" % (spec,name,ver))
	for file in versions:
		if re.search("-latest\.dtd$", file):
			# Do nothing
			print "Skipping", file
		elif re.search("\.dtd$", file):
			tmp = re.sub("(.*)(\.dtd)$", "\\1", file)
			name = re.sub("^(.*)-([^/]*)$", "\\1", tmp)
			ver = re.sub("^(.*)-([^/]*)$", "\\2", tmp)
			
			print "Check", os.path.join(spec,ver), os.path.isdir(os.path.join(spec,ver))
			print "Check", os.path.join(spec,name+"-"+ver+".html"), os.path.isfile(os.path.join(spec,name+"-"+ver+".html"))

			os.system("mkdir %s/%s" % (spec,ver))
			os.system("cp %s/%s-%s.dtd %s/%s/%s.dtd" % (spec,name,ver,spec,ver,name))