Commit b09406e3 authored by Oliver Pinter's avatar Oliver Pinter
Browse files

HBSD: add basic error handling



Signed-off-by: default avatarOliver Pinter <oliver.pinter@hardenedbsd.org>
parent cfa32540
...@@ -5,11 +5,21 @@ import os.path ...@@ -5,11 +5,21 @@ import os.path
cwd = os.path.basename(os.getcwd()) cwd = os.path.basename(os.getcwd())
with open("CHECKSUM.SHA512", "r") as f: try:
checksum = f.read() with open("CHECKSUM.SHA512", "r") as f:
checksum = f.read()
with open("CHECKSUM.SHA512.asc", "r") as f: update_checksum = True
signature = f.read() except:
print("missing CHECKSUM.SHA512 file!")
update_checksum = False
try:
with open("CHECKSUM.SHA512.asc", "r") as f:
signature = f.read()
update_signature = True
except:
print("missing CHECKSUM.SHA512.asc file!")
update_signature = False
with open("drupal-{version}.template".format(version=cwd), "r") as f: with open("drupal-{version}.template".format(version=cwd), "r") as f:
drupal_template = f.read() drupal_template = f.read()
...@@ -34,17 +44,17 @@ github_text = "\n".join(github_formatted_lines) ...@@ -34,17 +44,17 @@ github_text = "\n".join(github_formatted_lines)
drupal_text = "\n".join(drupal_formatted_lines) drupal_text = "\n".join(drupal_formatted_lines)
with open("drupal-{version}.txt".format(version=cwd), "w+") as f: with open("drupal-{version}.txt".format(version=cwd), "w+") as f:
drupal = (drupal_template drupal = drupal_template.replace("%%NOTES%%", drupal_text)
.replace("%%NOTES%%", drupal_text) if update_checksum:
.replace("%%CHECKSUM%%", checksum) drupal = drupal.replace("%%CHECKSUM%%", checksum)
.replace("%%SIGNATURE%%", signature) if update_signature:
) drupal = drupal.replace("%%SIGNATURE%%", signature)
f.write(drupal) f.write(drupal)
with open("github-{version}.txt".format(version=cwd), "w+") as f: with open("github-{version}.txt".format(version=cwd), "w+") as f:
github = (github_template github = github_template.replace("%%NOTES%%", github_text)
.replace("%%NOTES%%", github_text) if update_checksum:
.replace("%%CHECKSUM%%", checksum) github = github.replace("%%CHECKSUM%%", checksum)
.replace("%%SIGNATURE%%", signature) if update_signature:
) github = github.replace("%%SIGNATURE%%", signature)
f.write(github) f.write(github)
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment