rename templateFile variable to template_file

More pep8-y.

Change-Id: I76a6b218a30c65b15593336a29c4da0e916ebbb9
Signed-off-by: Doug Hellmann <doug@doughellmann.com>
This commit is contained in:
Doug Hellmann
2017-07-15 18:38:57 -04:00
parent 2dd080ebb7
commit 2ad1d522cc

View File

@@ -234,30 +234,30 @@ def _get_official_repos():
def render_template(environment, project_data, regular_repos, infra_repos, def render_template(environment, project_data, regular_repos, infra_repos,
templateFile, output_directory): template_file, output_directory):
logger = logging.getLogger() logger = logging.getLogger()
logger.info("generating %s", templateFile) logger.info("generating %s", template_file)
# Determine the relative path to a few common directories so # Determine the relative path to a few common directories so
# we don't need to set them in the templates. # we don't need to set them in the templates.
topdir = os.path.relpath( topdir = os.path.relpath(
'.', os.path.dirname(templateFile), '.', os.path.dirname(template_file),
).rstrip('/') + '/' ).rstrip('/') + '/'
scriptdir = os.path.join(topdir, 'common', 'js').rstrip('/') + '/' scriptdir = os.path.join(topdir, 'common', 'js').rstrip('/') + '/'
cssdir = os.path.join(topdir, 'common', 'css').rstrip('/') + '/' cssdir = os.path.join(topdir, 'common', 'css').rstrip('/') + '/'
imagedir = os.path.join(topdir, 'common', 'images').rstrip('/') + '/' imagedir = os.path.join(topdir, 'common', 'images').rstrip('/') + '/'
try: try:
template = environment.get_template(templateFile) template = environment.get_template(template_file)
except Exception as e: except Exception as e:
logger.error("parsing template %s failed: %s" % logger.error("parsing template %s failed: %s" %
(templateFile, e)) (template_file, e))
raise raise
try: try:
output = template.render( output = template.render(
PROJECT_DATA=project_data, PROJECT_DATA=project_data,
TEMPLATE_FILE=templateFile, TEMPLATE_FILE=template_file,
REGULAR_REPOS=regular_repos, REGULAR_REPOS=regular_repos,
INFRA_REPOS=infra_repos, INFRA_REPOS=infra_repos,
topdir=topdir, topdir=topdir,
@@ -265,18 +265,18 @@ def render_template(environment, project_data, regular_repos, infra_repos,
cssdir=cssdir, cssdir=cssdir,
imagedir=imagedir, imagedir=imagedir,
) )
if templateFile.endswith('.html'): if template_file.endswith('.html'):
soup = BeautifulSoup(output, "lxml") soup = BeautifulSoup(output, "lxml")
output = soup.prettify() output = soup.prettify()
except Exception as e: except Exception as e:
logger.error("rendering template %s failed: %s" % logger.error("rendering template %s failed: %s" %
(templateFile, e)) (template_file, e))
raise raise
try: try:
target_directory = os.path.join(output_directory, target_directory = os.path.join(output_directory,
os.path.dirname(templateFile)) os.path.dirname(template_file))
target_file = os.path.join(output_directory, templateFile) target_file = os.path.join(output_directory, template_file)
if not os.path.isdir(target_directory): if not os.path.isdir(target_directory):
logger.debug("creating target directory %s" % logger.debug("creating target directory %s" %
target_directory) target_directory)
@@ -311,17 +311,17 @@ def main():
return 1 return 1
# Render the templates. # Render the templates.
for templateFile in environment.list_templates(): for template_file in environment.list_templates():
if not (templateFile.endswith('.html') if not (template_file.endswith('.html')
or templateFile.endswith('.htaccess')): or template_file.endswith('.htaccess')):
logger.info('ignoring %s', templateFile) logger.info('ignoring %s', template_file)
continue continue
render_template( render_template(
environment, environment,
project_data, project_data,
regular_repos, regular_repos,
infra_repos, infra_repos,
templateFile, template_file,
args.output_directory, args.output_directory,
) )