Skip to content

Commit c295fba

Browse files
author
Michael Whapples
committed
Code to warn users when not a production ready build.
1 parent 283d5fc commit c295fba

3 files changed

Lines changed: 40 additions & 4 deletions

File tree

.github/workflows/python-app.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ name: Python application
66
on:
77
push:
88
branches: [ "main" ]
9+
tags: [ "release/*" ]
910
pull_request:
1011
branches: [ "main" ]
1112

@@ -34,6 +35,9 @@ jobs:
3435
pdm build_exe --assume-yes-for-downloads
3536
- name: Add build data
3637
run: git show --no-patch > Convert2EBRL.dist/build-data.txt
38+
- name: add-release-hash
39+
if: github.ref_type == 'tag'
40+
run: python "src\convert2ebrl\hash_utils.py" "Convert2EBRL.dist\Convert2EBRL.exe" > "Convert2EBRL\release.hash"
3741
- name: Create release zip
3842
run: Compress-Archive -Path Convert2EBRL.dist -Destination convert2ebrl-continuous.zip
3943
- name: Update continuous tag

src/convert2ebrl/__main__.py

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,24 +6,35 @@
66
# You should have received a copy of the GNU General Public License along with Convert2EBRL. If not, see <https://www.gnu.org/licenses/>.
77

88
import logging
9+
import os.path
910
import sys
1011
from collections.abc import Sequence
12+
from pathlib import Path
1113

12-
from PySide6.QtCore import QSettings
13-
from PySide6.QtWidgets import QApplication
14+
from PySide6.QtCore import QSettings, QTimer
15+
from PySide6.QtWidgets import QApplication, QMessageBox
1416
# noinspection PyUnresolvedReferences
1517
from __feature__ import snake_case, true_property
1618

1719
from convert2ebrl.brf_to_ebrf import Brf2EbrfDialog
20+
from convert2ebrl.hash_utils import get_file_hash
1821
from convert2ebrl.settings import PROFILES_FILE_NAME
1922
from convert2ebrl.settings.defaults import DEFAULT_SETTINGS_PROFILES_LIST
2023
from convert2ebrl.utils import save_settings_profiles, get_app_config_path
2124

25+
def check_release(exe_file_name: str) -> bool:
26+
exe_hash = get_file_hash(exe_file_name).strip()
27+
app_dir = os.path.dirname(exe_file_name)
28+
hash_path = Path(os.path.join(app_dir, "release.hash"))
29+
return hash_path.exists() and Path(hash_path).read_text(encoding="UTF-8").strip() == exe_hash
2230

2331
def run_app(args: Sequence[str]):
2432
logging.basicConfig(
2533
level=logging.INFO, format="%(levelname)s:%(asctime)s:%(module)s:%(message)s"
2634
)
35+
logging.debug(f"Executable hash: {get_file_hash(sys.argv[0])}")
36+
release_build = check_release(sys.argv[0])
37+
logging.info(f"Release build: {release_build}")
2738
app = QApplication(args)
2839
app.organization_name = "American Printing House for the Blind"
2940
app.organization_domain = "aph.org"
@@ -32,8 +43,13 @@ def run_app(args: Sequence[str]):
3243
profiles_path = get_app_config_path().joinpath(PROFILES_FILE_NAME)
3344
if not profiles_path.exists():
3445
save_settings_profiles(DEFAULT_SETTINGS_PROFILES_LIST)
35-
w = Brf2EbrfDialog()
36-
w.show()
46+
def starting_app():
47+
if not release_build:
48+
QMessageBox.warning(None, "Not for production use!", "This is not a production ready build and is only for testing purposes. No other use is recommended and is at the user's own risk.")
49+
w = Brf2EbrfDialog()
50+
w.show()
51+
52+
QTimer.single_shot(0, starting_app)
3753
app.exec()
3854

3955

src/convert2ebrl/hash_utils.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
# Copyright (c) 2024. American Printing House for the Blind.
2+
#
3+
# This file is part of Convert2EBRL.
4+
# Convert2EBRL is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
5+
# Convert2EBRL is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
6+
# You should have received a copy of the GNU General Public License along with Convert2EBRL. If not, see <https://www.gnu.org/licenses/>.
7+
import hashlib
8+
import sys
9+
10+
11+
def get_file_hash(filename: str) -> str:
12+
with open(filename, "rb") as f:
13+
return hashlib.file_digest(f, hashlib.sha256).hexdigest()
14+
15+
if __name__ == "__main__":
16+
print("\n".join(get_file_hash(filename) for filename in sys.argv[1:]))

0 commit comments

Comments
 (0)