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 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113
|
# -*- coding: utf-8 -*-
"""Version-check script."""
import os
import sys
import codecs
Failed = 0
VERSION = "2.0"
VERSION_1 = VERSION.split(".")[0]
VERSION_2 = str(int(float(VERSION) * 10 - int(VERSION_1) * 10))
VERSION_3 = str(int(float(VERSION) * 100 - int(VERSION_1)
* 100 - int(VERSION_2) * 10))
VERSION_4 = "0"
SETUP_ITEMS = [
"version='{0}'",
'https://github.com/sepandhaghighi/pyrgg/tarball/v{0}']
README_ITEMS = [
"[Version {0}](https://github.com/sepandhaghighi/pyrgg/archive/v{0}.zip)",
"[Exe-Version {0}](https://github.com/sepandhaghighi/pyrgg/releases/download/v{0}/PYRGG-{0}.exe)",
"Run `PYRGG-{0}.exe`",
"pip install pyrgg=={0}"]
CHANGELOG_ITEMS = [
"## [{0}]",
"https://github.com/sepandhaghighi/pyrgg/compare/v{0}...dev",
"[{0}]:"]
RC_ITEMS = [
"filevers=({0}, {1}, {2}, {3})",
"prodvers=({0}, {1}, {2}, {3})",
"(u'FileVersion', u'{0}.{1}.{2}.{3}'),",
"(u'ProductVersion', u'{0}, {1}, {2}, {3}')"]
PARAMS_ITEMS = ['PYRGG_VERSION = "{0}"']
META_ITEMS = ['% set version = "{0}" %']
SPEC_ITEMS = ['pyrgg_version = "{0}"']
ISSUE_TEMPLATE_ITEMS = ["- PyRGG {0}"]
SECURITY_ITEMS = ["| {0} | :white_check_mark: |", "| < {0} | :x: |"]
FILES = {
"setup.py": SETUP_ITEMS,
"PYRGG.spec": SPEC_ITEMS,
"README.md": README_ITEMS,
"CHANGELOG.md": CHANGELOG_ITEMS,
"SECURITY.md": SECURITY_ITEMS,
os.path.join(
"pyrgg",
"params.py"): PARAMS_ITEMS,
os.path.join(
"otherfile",
"meta.yaml"): META_ITEMS,
os.path.join(
".github",
"ISSUE_TEMPLATE",
"bug_report.yml"): ISSUE_TEMPLATE_ITEMS,
}
TEST_NUMBER = len(FILES.keys()) + 1
def print_result(failed: bool = False) -> None:
"""
Print final result.
:param failed: failed flag
"""
message = "Version tag tests "
if not failed:
print("\n" + message + "passed!")
else:
print("\n" + message + "failed!")
print("Passed : " + str(TEST_NUMBER - Failed) + "/" + str(TEST_NUMBER))
if __name__ == "__main__":
for file_name in FILES.keys():
try:
file_content = codecs.open(
file_name, "r", "utf-8", 'ignore').read()
for test_item in FILES[file_name]:
if file_content.find(test_item.format(VERSION)) == -1:
print("Incorrect version tag in " + file_name)
Failed += 1
break
except Exception as e:
Failed += 1
print("Error in " + file_name + "\n" + "Message : " + str(e))
try:
file_content = codecs.open(
os.path.join(
"otherfile",
"Version.rc"),
"r",
"utf-8",
'ignore').read()
for test_item in RC_ITEMS:
if file_content.find(
test_item.format(
VERSION_1,
VERSION_2,
VERSION_3,
VERSION_4)) == -1:
print("Incorrect version tag in " + "Version.rc")
Failed += 1
break
except Exception as e:
Failed += 1
print("Error in Version.rc" + "\n" + "Message : " + str(e))
if Failed == 0:
print_result(False)
sys.exit(0)
else:
print_result(True)
sys.exit(1)
|