gh_step_summary = os.getenv("GITHUB_STEP_SUMMARY")
if gh_step_summary:
# Print Markdown summary
- summary_fp = open(gh_step_summary, "a", encoding="utf-8")
- print("### clang-tidy summary", file=summary_fp)
+ with open(gh_step_summary, "a", encoding="utf-8") as summary_fp:
+ print("### clang-tidy summary", file=summary_fp)
fixes = fixes["Diagnostics"]
have_warnings = False
pkg = 'dnsdist'
cmd = 'dnsdist'
- f = open('{}{}.{}-{}'.format(g_dockerfile, release, os, os_version), 'w')
-
- # This comment was in the template for the `--nobest` part but that makes
- # the template look even more different than the final output, so:
- #
- # > When should the logic be in the code and when in the template? :shrug:
- # > I prefer it to be in the code but I also do not want to add extra vars
- # > and logic to the code unless necessary.
- f.write(tpl.render({ "os": os,
- "os_image": os_image,
- "os_version": os_version,
- "release": release,
- "cmd": cmd,
- "pkg": pkg }))
- f.close()
+ with open('{}{}.{}-{}'.format(g_dockerfile, release, os, os_version), 'w') as f:
+ # This comment was in the template for the `--nobest` part but that makes
+ # the template look even more different than the final output, so:
+ #
+ # > When should the logic be in the code and when in the template? :shrug:
+ # > I prefer it to be in the code but I also do not want to add extra vars
+ # > and logic to the code unless necessary.
+ f.write(tpl.render({ "os": os,
+ "os_image": os_image,
+ "os_version": os_version,
+ "release": release,
+ "cmd": cmd,
+ "pkg": pkg }))
def write_list_file (os, os_version, release):
tpl = g_env.get_template('pdns-list.jinja2')
- f = open('pdns.list.{}.{}-{}'.format(release, os, os_version), 'w')
- f.write(tpl.render({ "os": os,
- "os_version": os_version,
- "release": release }))
- f.close()
+ with open('pdns.list.{}.{}-{}'.format(release, os, os_version), 'w') as f:
+ f.write(tpl.render({ "os": os,
+ "os_version": os_version,
+ "release": release }))
def write_pkg_pin_file (release):
elif release.startswith('dnsdist-'):
pkg = 'dnsdist'
- f = open('pkg-pin', 'w')
- f.write(tpl.render({ "pkg": pkg }))
- f.close()
+ with open('pkg-pin', 'w') as f:
+ f.write(tpl.render({ "pkg": pkg }))
def write_release_files (release):
# README file and 2) it's easier to type in the README file than to put a raw
# string in below ...
def read(fname):
- return open(os.path.join(os.path.dirname(__file__), fname),
- 'r', encoding='utf-8').read()
+ with open(os.path.join(os.path.dirname(__file__), fname),
+ 'r', encoding='utf-8') as f:
+ return f.read()
version = os.environ.get('BUILDER_VERSION', '0.0.0')
vars['tag'] = tag
varnames.update(vars.keys())
stats=dict()
- for line in open(fname):
- if line.startswith('<'):
- sname = line.split(';')[4][:-3]
- sval = line.split(';')[8][:-3]
- stats[sname]=sval
- statnames.add(sname)
+ with open(fname) as f
+ for line in f:
+ if line.startswith('<'):
+ sname = line.split(';')[4][:-3]
+ sval = line.split(';')[8][:-3]
+ stats[sname]=sval
+ statnames.add(sname)
# print fname, vars, stats
runs.append(dict(vars.items()+stats.items()))