diff options
author | gbrandl <gbrandl@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2007-06-11 18:37:48 +0000 |
---|---|---|
committer | gbrandl <gbrandl@929543f6-e4f2-0310-98a6-ba3bd3dd1d04> | 2007-06-11 18:37:48 +0000 |
commit | 02299c91bc4e7c776b1d6e61d6fee62e39e85f0c (patch) | |
tree | a514b18aea2d120eeeaac11e8189e84a32ce26c3 /sandbox/py-rest-doc/sphinx/environment.py | |
parent | c4314343086f37fc9d243c7cee0ef8295e97c14b (diff) | |
download | docutils-02299c91bc4e7c776b1d6e61d6fee62e39e85f0c.tar.gz |
Use md5 to detect changed files; indicate version in the header link.
git-svn-id: http://svn.code.sf.net/p/docutils/code/trunk@5231 929543f6-e4f2-0310-98a6-ba3bd3dd1d04
Diffstat (limited to 'sandbox/py-rest-doc/sphinx/environment.py')
-rw-r--r-- | sandbox/py-rest-doc/sphinx/environment.py | 21 |
1 files changed, 16 insertions, 5 deletions
diff --git a/sandbox/py-rest-doc/sphinx/environment.py b/sandbox/py-rest-doc/sphinx/environment.py index e19c03deb..ac68034c3 100644 --- a/sandbox/py-rest-doc/sphinx/environment.py +++ b/sandbox/py-rest-doc/sphinx/environment.py @@ -11,6 +11,7 @@ from __future__ import with_statement import heapq +import hashlib import difflib import itertools import cPickle as pickle @@ -40,7 +41,7 @@ default_settings = { # This is increased every time a new environment attribute is added # to properly invalidate pickle files. -ENV_VERSION = 8 +ENV_VERSION = 9 def walk_depth(node, depth, maxdepth): @@ -163,7 +164,7 @@ class BuildEnvironment: # Build times -- to determine changed files # Also use this as an inventory of all existing and built filenames. - self.all_files = {} # filename -> mtime at the time of build + self.all_files = {} # filename -> (mtime, md5) at the time of build # File metadata self.metadata = {} # filename -> dict of metadata items @@ -250,8 +251,14 @@ class BuildEnvironment: if filename not in self.all_files: changed.append(filename) else: - mtime = path.getmtime(path.join(self.srcdir, filename)) - if mtime > self.all_files.get(filename, 0): + mtime, md5 = self.all_files[filename] + newmtime = path.getmtime(path.join(self.srcdir, filename)) + if newmtime == mtime: + continue + # check the MD5 + with file(path.join(self.srcdir, filename), 'rb') as f: + newmd5 = hashlib.md5(f.read()).digest() + if newmd5 != md5: changed.append(filename) return removed, changed @@ -289,7 +296,11 @@ class BuildEnvironment: self.create_title_from(filename, doctree) self.note_labels_from(filename, doctree) self.build_toc_from(filename, doctree) - self.all_files[filename] = path.getmtime(filesystem_filename) + + # calculate the MD5 of the file at time of build + with file(filesystem_filename, 'rb') as f: + md5 = hashlib.md5(f.read()).digest() + self.all_files[filename] = (path.getmtime(filesystem_filename), md5) # make it picklable doctree.reporter = None |