~launchpad-pqm/launchpad/devel

« back to all changes in this revision

Viewing changes to utilities/create-lp-wadl-and-apidoc.py

  • Committer: Gary Poster
  • Date: 2011-07-07 19:19:41 UTC
  • mto: This revision was merged to the branch mainline in revision 13394.
  • Revision ID: gary.poster@canonical.com-20110707191941-bi22xetppz7mmaet
set mtime of generated wadl files to correspond to last checkin of branch.  This can let Apache serve ETags consistently across machines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
import os
18
18
import sys
19
19
 
 
20
import bzrlib
 
21
from bzrlib.branch import Branch
20
22
from zope.component import getUtility
21
23
from zope.pagetemplate.pagetemplatefile import PageTemplateFile
22
24
 
30
32
from lazr.restful.interfaces import IWebServiceConfiguration
31
33
 
32
34
 
33
 
def write(filename, content):
 
35
def write(filename, content, timestamp):
34
36
    """Replace the named file with the given string."""
35
37
    f = open(filename, 'w')
36
38
    f.write(content)
37
39
    f.close()
38
 
 
39
 
 
40
 
def make_files(directory, version, force):
 
40
    os.utime(filename, (timestamp, timestamp)) # (atime, mtime)
 
41
 
 
42
def make_files(directory, version, timestamp, force):
41
43
    version_directory = os.path.join(directory, version)
42
44
    base_filename = os.path.join(version_directory, os.environ['LPCONFIG'])
43
45
    wadl_filename = base_filename + '.wadl'
61
63
        if (not os.path.exists(src) or force):
62
64
            print "Writing %s for version %s to %s." % (
63
65
                name, version, src)
64
 
            write(src, gen(version))
 
66
            write(src, gen(version), timestamp)
65
67
        else:
66
68
            print "Skipping already present %s file: %s" % (
67
69
                name, src)
105
107
        print "Writing apidoc for version %s to %s" % (
106
108
            version, html_filename)
107
109
        write(html_filename, generate_html(wadl_filename,
108
 
            suppress_stderr=False))
 
110
            suppress_stderr=False), timestamp)
109
111
    else:
110
112
        print "Skipping already present HTML file:", html_filename
111
113
 
131
133
    f = open(index_filename, 'w')
132
134
    f.write(template(config=config))
133
135
 
 
136
    # Get the time of the last commit.  We will use this as the mtime for the
 
137
    # generated files so that we can safely use it as part of Apache's etag
 
138
    # generation in the face of multiple servers/filesystems.
 
139
    with bzrlib.initialize():
 
140
        branch = Branch.open(os.path.dirname(os.path.dirname(__file__)))
 
141
        timestamp = branch.repository.get_revision(
 
142
            branch.last_revision()).timestamp
 
143
 
134
144
    # Start a process to build each set of WADL and HTML files.
135
145
    processes = []
136
146
    for version in config.active_versions:
137
147
        p = Process(target=make_files,
138
 
            args=(directory, version, force))
 
148
            args=(directory, version, timestamp, force))
139
149
        p.start()
140
150
        processes.append(p)
141
151