~ubuntu-branches/ubuntu/karmic/zeroinstall-injector/karmic

« back to all changes in this revision

Viewing changes to zeroinstall/zerostore/manifest.py

  • Committer: Bazaar Package Importer
  • Author(s): Thomas Leonard
  • Date: 2009-04-05 10:40:06 UTC
  • mfrom: (1.1.9 upstream) (6.1.5 sid)
  • Revision ID: james.westby@ubuntu.com-20090405104006-e3x93j5ibvjqu65a
Tags: 0.39-1ubuntu1
* Updated build for Python 2.6.
* FFe: LP: #336317.

Show diffs side-by-side

added added

removed removed

Lines of Context:
20
20
A top-level ".manifest" file is ignored.
21
21
"""
22
22
 
23
 
# Copyright (C) 2006, Thomas Leonard
 
23
# Copyright (C) 2009, Thomas Leonard
24
24
# See the README file for details, or visit http://0install.net.
25
25
 
26
26
from __future__ import generators
27
27
import os, stat
28
 
import sha
29
28
from zeroinstall import SafeException
30
29
from zeroinstall.zerostore import BadDigest
31
30
 
32
31
try:
33
32
        import hashlib
 
33
        sha1_new = hashlib.sha1
34
34
except:
 
35
        import sha
 
36
        sha1_new = sha.new
35
37
        hashlib = None
36
38
 
37
39
class Algorithm:
82
84
                        assert sub[1:]
83
85
                        leaf = os.path.basename(sub[1:])
84
86
                        if stat.S_ISREG(m):
85
 
                                d = sha.new(file(full).read()).hexdigest()
 
87
                                d = sha1_new(file(full).read()).hexdigest()
86
88
                                if m & 0111:
87
89
                                        yield "X %s %s %s %s" % (d, int(info.st_mtime) ,info.st_size, leaf)
88
90
                                else:
89
91
                                        yield "F %s %s %s %s" % (d, int(info.st_mtime) ,info.st_size, leaf)
90
92
                        elif stat.S_ISLNK(m):
91
 
                                d = sha.new(os.readlink(full)).hexdigest()
 
93
                                d = sha1_new(os.readlink(full)).hexdigest()
92
94
                                # Note: Can't use utime on symlinks, so skip mtime
93
95
                                yield "S %s %s %s" % (d, info.st_size, leaf)
94
96
                        else:
97
99
                for x in recurse('/'): yield x
98
100
        
99
101
        def new_digest(self):
100
 
                return sha.new()
 
102
                return sha1_new()
101
103
 
102
104
        def getID(self, digest):
103
105
                return 'sha1=' + digest.hexdigest()
402
404
 
403
405
        def __init__(self, name):
404
406
                if name == 'sha1':
405
 
                        self.new_digest = sha.new
 
407
                        self.new_digest = sha1_new
406
408
                        self.name = 'sha1new'
407
409
                else:
408
410
                        self.new_digest = getattr(hashlib, name)