/[gentoo-src]/portage/pym/portage_md5.py
Gentoo

Contents of /portage/pym/portage_md5.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1.4 - (show annotations) (download) (as text)
Wed Aug 25 05:25:08 2004 UTC (10 years, 4 months ago) by genone
Branch: MAIN
CVS Tags: HEAD
Changes since 1.3: +1 -1 lines
File MIME type: text/x-python
FILE REMOVED
add sha1 support

1 # portage.py -- core Portage functionality
2 # Copyright 1998-2003 Daniel Robbins, Gentoo Technologies, Inc.
3 # Distributed under the GNU Public License v2
4 # $Header: /var/cvsroot/gentoo-src/portage/pym/portage_md5.py,v 1.3 2004/08/17 01:12:56 carpaski Exp $
5
6 from portage_const import PRIVATE_PATH,PRELINK_BINARY
7 import os
8 import shutil
9 import portage_exec
10 import portage_util
11 import portage_locks
12 import commands
13
14 prelink_capable = False
15 results = commands.getstatusoutput(PRELINK_BINARY+" --version > /dev/null 2>&1")
16 if (results[0] >> 8) == 0:
17 prelink_capable=1
18 del results
19
20 def perform_md5(x, calc_prelink=0):
21 return perform_checksum(x, calc_prelink)[0]
22
23 # We _try_ to load this module. If it fails we do the slow fallback.
24 try:
25 import fchksum
26
27 def perform_checksum(filename, calc_prelink=False):
28 prelink_tmpfile = PRIVATE_PATH+"/prelink-checksum.tmp"
29 if calc_prelink and prelink_capable:
30 # Create non-prelinked temporary file to md5sum.
31 mylock = portage_locks.lockfile(prelink_tmpfile, wantnewlockfile=1)
32 try:
33 shutil.copy2(filename,prelink_tmpfile)
34 except Exception,e:
35 writemsg("!!! Unable to copy file '"+str(filename)+"'.\n")
36 writemsg("!!! "+str(e)+"\n")
37 sys.exit(1)
38 portage_exec.spawn(PRELINK_BINARY+" --undo "+prelink_tmpfile+" &>/dev/null", free=1)
39 retval = fchksum.fmd5t(prelink_tmpfile)
40 os.unlink(prelink_tmpfile)
41 portage_locks.unlockfile(mylock)
42 return retval
43 else:
44 return fchksum.fmd5t(filename)
45 except ImportError:
46 import md5
47 def perform_checksum(filename, calc_prelink=prelink_capable):
48 prelink_tmpfile = PRIVATE_PATH+"/prelink-checksum.tmp"
49 mylock = portage_locks.lockfile(prelink_tmpfile, wantnewlockfile=1)
50 myfilename=filename
51 if calc_prelink and prelink_capable:
52 # Create non-prelinked temporary file to md5sum.
53 # Raw data is returned on stdout, errors on stderr.
54 # Non-prelinks are just returned.
55 try:
56 shutil.copy2(filename,prelink_tmpfile)
57 except Exception,e:
58 writemsg("!!! Unable to copy file '"+str(filename)+"'.\n")
59 writemsg("!!! "+str(e)+"\n")
60 sys.exit(1)
61 portage_exec.spawn(PRELINK_BINARY+" --undo "+prelink_tmpfile+" &>/dev/null", free=1)
62 myfilename=prelink_tmpfile
63
64 f = open(myfilename, 'rb')
65 blocksize=32768
66 data = f.read(blocksize)
67 size = 0L
68 sum = md5.new()
69 while data:
70 sum.update(data)
71 size = size + len(data)
72 data = f.read(blocksize)
73 f.close()
74
75 if calc_prelink and prelink_capable:
76 os.unlink(prelink_tmpfile)
77 portage_locks.unlockfile(mylock)
78 return (sum.hexdigest(),size)

  ViewVC Help
Powered by ViewVC 1.1.20