diff options
Diffstat (limited to 'doc/docgen.py')
-rw-r--r-- | doc/docgen.py | 32 |
1 files changed, 13 insertions, 19 deletions
diff --git a/doc/docgen.py b/doc/docgen.py index 544aafe53..1ec6c8090 100644 --- a/doc/docgen.py +++ b/doc/docgen.py @@ -57,7 +57,6 @@ try: import hashlib import os import re - import sys from collections import defaultdict from operator import itemgetter except ImportError as message: @@ -141,6 +140,16 @@ IGNORE_COMPLETIONS_ITEMS = ( ) +def sha256_file(filename, default=None): + """Return SHA256 checksum of a file.""" + try: + with open(filename, 'rb') as _file: + checksum = hashlib.sha256(_file.read()).hexdigest() + except IOError: + checksum = default + return checksum + + class AutogenDoc(object): """A class to write auto-generated doc files.""" @@ -158,29 +167,14 @@ class AutogenDoc(object): """Write a line in auto-generated doc file.""" self._file.write(string) - @staticmethod - def sha256_file(filename, default): - """ - Return SHA256 checksum of a file, "default" if file is not found. - """ - try: - with open(filename, 'r') as _file: - content = _file.read() - if sys.version_info >= (3, ): - content = content.encode('utf-8') - checksum = hashlib.sha256(content).hexdigest() - except IOError: - checksum = default - return checksum - def update(self, obj_name, num_files, num_files_updated): """Update doc file if needed (if content has changed).""" # close temp file self._file.close() - shaold = AutogenDoc.sha256_file(self.filename, 'old') - shanew = AutogenDoc.sha256_file(self.filename_tmp, 'new') + sha_old = sha256_file(self.filename, 'old') + sha_new = sha256_file(self.filename_tmp, 'new') # compare checksums - if shaold != shanew: + if sha_old != sha_new: # update doc file if os.path.exists(self.filename): os.unlink(self.filename) |