compute and generate an MD5SUMS file for each source document

This commit is contained in:
Martin A. Brown 2016-04-01 22:19:25 -07:00
parent 9fac28f160
commit 753774c5e9
1 changed files with 31 additions and 1 deletions

View File

@ -7,6 +7,7 @@ from __future__ import unicode_literals
import os
import sys
import stat
import time
import errno
import codecs
import shutil
@ -140,11 +141,39 @@ class BaseDoctype(object):
s = '''
# - - - - - {source.stem} - - - - - -
cd -- "{output.dirname}"'''
cd -- "{output.dirname}"'''
return self.shellscript(s, **kwargs)
os.chdir(self.output.dirname)
return True
def generate_md5sums(self, **kwargs):
logger.debug("%s generating MD5SUMS in %s.",
self.output.stem, self.output.dirname)
md5file = os.path.join(self.output.dirname, 'MD5SUMS')
fileset = sorted(self.source.md5sums.items())
if self.config.script:
l = list()
for fname, hashval in fileset:
l.append('# {} {}'.format(hashval, fname))
md5s = '\n'.join(l)
s = '''# -- calculating MD5SUMS file
#
# md5sum > {} -- {}
#
# -- These are the values for sources at timestamp {}
#
{}
#'''
s = s.format(md5file,
' '.join(self.source.statinfo.keys()),
time.strftime('%F-%T', time.gmtime()),
md5s)
return self.shellscript(s, **kwargs)
with codecs.open(md5file, 'w', encoding='utf-8') as f:
for fname, hashval in fileset:
print(hashval + ' ' + fname, file=f)
return True
def copy_static_resources(self, **kwargs):
logger.debug("%s copy resources %s.",
self.output.stem, self.output.dirname)
@ -233,6 +262,7 @@ class BaseDoctype(object):
'clear_output',
'mkdir_output',
'chdir_output',
'generate_md5sums',
'copy_static_resources',
]