File: make_win_release.py

package info (click to toggle)
finalcif 137%2Bdfsg-4
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 43,544 kB
  • sloc: python: 49,119; cpp: 67; sh: 51; makefile: 22
file content (75 lines) | stat: -rw-r--r-- 2,625 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
#  ----------------------------------------------------------------------------
#  "THE BEER-WARE LICENSE" (Revision 42):
#  dkratzert@gmx.de> wrote this file.  As long as you retain
#  this notice you can do whatever you want with this stuff. If we meet some day,
#  and you think this stuff is worth it, you can buy me a beer in return.
#  Dr. Daniel Kratzert
#  ----------------------------------------------------------------------------

import os
import subprocess
import sys
from datetime import datetime
from pathlib import Path

application_path = Path(os.path.abspath(__file__)).parent.parent

sys.path.append(str(Path(__file__).parent.parent))
sys.path.append(str(application_path))

from scripts.compile_ui_files import compile_ui
from finalcif.tools.misc import sha512_checksum_of_file
from finalcif import VERSION


def disable_debug(filepath: str):
    pth = Path(filepath)
    file_lst = pth.read_text(encoding="UTF-8", errors='ignore').split("\n")
    for num, line in enumerate(file_lst):
        if line.startswith("DEBUG") or line.startswith("PROFILE"):
            l = line.split()
            print("DEBUG/PROFILE.. {}, {}".format(l[2], filepath))
            l[2] = '{}'.format("False")
            file_lst[num] = " ".join(l)
    pth.write_text("\n".join(file_lst), encoding="UTF-8")


def make_shasum(filename):
    sha = sha512_checksum_of_file(filename)
    shafile = Path('scripts/Output/FinalCif-setup-x64-v{}-sha512.sha'.format(VERSION))
    shafile.unlink(missing_ok=True)
    shafile.write_text(sha)
    print("SHA512: {}".format(sha))


def make_installer(iss_file: str):
    innosetup_compiler = r'D:\Programme\Inno Setup 6/ISCC.exe'
    innosetup_compiler2 = r'C:\Program Files (x86)\Inno Setup 6/ISCC.exe'
    if not Path(innosetup_compiler).exists():
        innosetup_compiler = innosetup_compiler2
    subprocess.run([innosetup_compiler, '/Qp', f'/dMyAppVersion={VERSION}', iss_file])


def compile_python_files():
    import compileall
    compileall.compile_dir(dir='dist', workers=2, force=True, quiet=True)
    compileall.compile_dir(dir='finalcif', workers=2, force=True, quiet=True)


if __name__ == '__main__':
    iss_file = 'scripts/finalcif-install_win64.iss'

    compile_ui()
    compile_python_files()
    disable_debug('finalcif/appwindow.py')

    os.chdir(application_path)

    make_installer(iss_file)

    make_shasum("scripts/Output/FinalCif-setup-x64-v{}.exe".format(VERSION))

    print('Created version: {}'.format(VERSION))
    print(datetime.now().strftime("%d.%m.%Y %H:%M:%S"))

    subprocess.call("scripts/Output/FinalCif-setup-x64-v{}.exe".format(VERSION))