~ubuntu-branches/ubuntu/lucid/jhbuild/lucid

« back to all changes in this revision

Viewing changes to jhbuild/utils/httpcache.py

  • Committer: Bazaar Package Importer
  • Author(s): Emilio Pozuelo Monfort, Loic Minier, Emilio Pozuelo Monfort
  • Date: 2009-11-09 20:28:48 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20091109202848-m9ec7dmzptqtchtj
Tags: 2.28.0-1
[ Loic Minier ]
* Cleanups.
* Ship scripts.
* Don't set GNOME_MODULE as it equals the name of the source package.

[ Emilio Pozuelo Monfort ]
* New upstream release. Closes: #524504.
  - Use 'git rev-parse' rather than 'git-rev-parse'. Closes: #544642.
* Ship install-check. Closes: #441008.
* Uploaders list regenerated. Closes: #523542, #554071.
* debian/control.in,
  debian/rules:
  - Stop shipping a copy of subprocess.py. Require python >= 2.4.
  - Switch to python-support.
* debian/control.in:
  - Bump Standards-Version to 3.8.3, no changes needed.
  - Build depend on intltool >= 0.35.0.
  - Build depend on pkg-config, gnome-doc-utils and rarian-compat to build
    the documentation.
  - Make jhbuild arch any since install-check is a binary. Depend on
    ${shlibs:Depends}.
  - Recommend, and not suggest, git-core. Also recommend mercurial.
* debian/watch:
  - Added.
* debian/patches/01_import_from_pkgdatadir.patch:
  - Added, import jhbuild from pkgdatadir if everything else fails.
    This way we can ship the jhbuild private modules in /usr/sharejhbuild.
* debian/jhbuild.docs:
  - Removed, the necessary docs are now installed by the upstream Makefile.
* debian/rules:
  - Include autotools.mk and gnome.mk.
  - Remove all the manual build process, autotools.mk does everything now.
  - Install the jhbuild modules in /usr/share/jhbuild.
* debian/install:
  - Install the modulesets and patches from here since the upstream build
    system doesn't install them.

Show diffs side-by-side

added added

removed removed

Lines of Context:
29
29
'''
30
30
 
31
31
import os
 
32
import sys
32
33
import urllib2
33
34
import urlparse
34
35
import time
42
43
try:
43
44
    import xml.dom.minidom
44
45
except ImportError:
45
 
    raise SystemExit, 'Python xml packages are required but could not be found'
 
46
    raise SystemExit, _('Python xml packages are required but could not be found')
46
47
 
47
48
def _parse_isotime(string):
48
49
    if string[-1] != 'Z':
68
69
        self.expires = expires
69
70
 
70
71
class Cache:
71
 
    cachedir = os.path.join(os.environ['HOME'], '.jhbuild', 'cache')
 
72
    try:
 
73
        cachedir = os.path.join(os.environ['XDG_CACHE_HOME'], 'jhbuild')
 
74
    except KeyError:
 
75
        cachedir = os.path.join(os.environ['HOME'], '.cache','jhbuild')
 
76
 
72
77
    # default to a 6 hour expiry time.
73
78
    default_age = 6 * 60 * 60
74
79
 
155
160
                base = base + '-'
156
161
        return base
157
162
 
158
 
    def load(self, uri, nonetwork=False):
 
163
    def load(self, uri, nonetwork=False, age=None):
159
164
        '''Downloads the file associated with the URI, and returns a local
160
165
        file name for contents.'''
161
166
        # pass file URIs straight through -- no need to cache them
162
167
        parts = urlparse.urlparse(uri)
163
168
        if parts[0] in ('', 'file'):
164
169
            return parts[2]
 
170
        if sys.platform.startswith('win') and uri[1] == ':':
 
171
            # On Windows, path like c:... are local
 
172
            return uri
165
173
 
166
174
        now = time.time()
167
175
 
168
176
        # is the file cached and not expired?
169
177
        self.read_cache()
170
178
        entry = self.entries.get(uri)
171
 
        if entry:
 
179
        if entry and (age != 0 or nonetwork):
172
180
            if (nonetwork or now <= entry.expires):
173
181
                return os.path.join(self.cachedir, entry.local)
174
182
 
175
183
        if nonetwork:
176
 
            raise RuntimeError('file not in cache, but not allowed '
177
 
                               'to check network')
 
184
            raise RuntimeError(_('file not in cache, but not allowed to check network'))
178
185
 
179
186
        request = urllib2.Request(uri)
180
187
        if gzip:
214
221
        # set expiry date
215
222
        entry.expires = _parse_date(expires)
216
223
        if entry.expires <= now: # ignore expiry times that have already passed
217
 
            entry.expires = now + self.default_age
 
224
            if age is None:
 
225
                age = self.default_age
 
226
            entry.expires = now + age
218
227
 
219
228
        # save cache
220
229
        self.entries[uri] = entry
222
231
        return filename
223
232
 
224
233
_cache = None
225
 
def load(uri, nonetwork=False):
 
234
def load(uri, nonetwork=False, age=None):
226
235
    '''Downloads the file associated with the URI, and returns a local
227
236
    file name for contents.'''
228
237
    global _cache
229
238
    if not _cache: _cache = Cache()
230
 
    return _cache.load(uri, nonetwork=nonetwork)
 
239
    return _cache.load(uri, nonetwork=nonetwork, age=age)