1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: install_util.py,v 1.8 2002-09-10 00:18:20 richard Exp $
18+ # $Id: install_util.py,v 1.9 2003-11-11 22:37:25 richard Exp $
1919
2020__doc__ = """
2121Support module to generate and check fingerprints of installed files.
3030
3131digested_file_types = sgml_file_types + hash_file_types + slast_file_types
3232
33-
34- def checkDigest (filename ):
35- """Read file, check for valid fingerprint, return TRUE if ok"""
36- # open and read file
37- inp = open (filename , "r" )
38- lines = inp .readlines ()
39- inp .close ()
40-
33+ def extractFingerprint (lines ):
4134 # get fingerprint from last line
42- if lines [- 1 ][: 6 ] == "#SHA: " :
35+ if lines [- 1 ]. startswith ( "#SHA: " ) :
4336 # handle .py/.sh comment
44- fingerprint = lines [- 1 ][6 :].strip ()
45- elif lines [- 1 ][: 10 ] == "<!-- SHA: " :
37+ return lines [- 1 ][6 :].strip ()
38+ elif lines [- 1 ]. startswith ( "<!-- SHA: " ) :
4639 # handle xml/html files
4740 fingerprint = lines [- 1 ][10 :]
4841 fingerprint = fingerprint .replace ('-->' , '' )
49- fingerprint = fingerprint .strip ()
50- elif lines [- 1 ][: 8 ] == "/* SHA: " :
42+ return fingerprint .strip ()
43+ elif lines [- 1 ]. startswith ( "/* SHA: " ) :
5144 # handle css files
5245 fingerprint = lines [- 1 ][8 :]
5346 fingerprint = fingerprint .replace ('*/' , '' )
54- fingerprint = fingerprint .strip ()
55- else :
47+ return fingerprint .strip ()
48+ return None
49+
50+ def checkDigest (filename ):
51+ """Read file, check for valid fingerprint, return TRUE if ok"""
52+ # open and read file
53+ inp = open (filename , "r" )
54+ lines = inp .readlines ()
55+ inp .close ()
56+
57+ fingerprint = extractFingerprint (lines )
58+ if fingerprint is None :
5659 return 0
5760 del lines [- 1 ]
5861
@@ -76,6 +79,12 @@ def __init__(self, filename):
7679 self .file = open (self .filename , "w" )
7780
7881 def write (self , data ):
82+ lines = data .splitlines ()
83+ # if the file is coming from an installed tracker being used as a
84+ # template, then we will want to re-calculate the SHA
85+ fingerprint = extractFingerprint (lines )
86+ if fingerprint is not None :
87+ data = '\n ' .join (lines [:- 1 ]) + '\n '
7988 self .file .write (data )
8089 self .digest .update (data )
8190
0 commit comments