From b8adc0518bf4a38686f194a3e1b5059311ed78db Mon Sep 17 00:00:00 2001 From: Vincent Untz Date: Wed, 25 Jan 2012 09:18:07 +0100 Subject: web-export: Completely rewrite update.py It's real python now. It also fetches specs.idx directly from git, and checks there's no new version of this script before doing anything. --- web-export/update.py | 401 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 263 insertions(+), 138 deletions(-) (limited to 'web-export') diff --git a/web-export/update.py b/web-export/update.py index dc15a59..1f43676 100755 --- a/web-export/update.py +++ b/web-export/update.py @@ -1,140 +1,265 @@ #!/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(): - line = line.strip() - if not line or line.startswith('#'): - continue - - (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("(?>sys.stderr, 'Script is not up-to-date, please download %s' % SCRIPT.get_url() + sys.exit(1) + + SPECS_INDEX.fetch() + lines = SPECS_INDEX.data.split('\n') +else: + lines = open('specs.idx').readlines() + + +latests = [] + +for line in lines: + line = line.strip() + if not line or line.startswith('#'): + continue + + (data, revision, version, path) = line.split() + if data.startswith("git:"): + git_data = data.split(":") + vcs = VcsObject('git', git_data[1], git_data[2], revision) + else: + vcs = VcsObject('cvs', None, data, revision) + + spec = SpecObject(vcs, path, version) + + spec.download() + spec.htmlize() + + # Create latest links if it's the first time we see this spec + if (spec.spec_dir, spec.basename_no_ext) not in latests: + latests.append((spec.spec_dir, spec.basename_no_ext)) + spec.latestize() -- cgit v1.2.3-70-g09d2