-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdeploy.py
More file actions
125 lines (105 loc) · 3.98 KB
/
deploy.py
File metadata and controls
125 lines (105 loc) · 3.98 KB
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
114
115
116
117
118
119
120
121
122
123
import sys,os
import subprocess
import win32api
def amIExe():
try:
basePath = sys._MEIPASS # are we a built with pyinstaller or in an dev env?
return True
except:
return False
def getVersionGit():
version = subprocess.run(["git","describe","--tags"],capture_output = True, text=True)
print("Git tells version (full):",version.stdout.strip())
return version.stdout.strip()
def writeVersionFile(version, file="exeVersionInfo.txt"):
buffer = []
with open(file) as f:
stream = f.readlines()
for line in stream:
if "ProductVersion" in line:
print("line:",line)
posVersion = line.find("ProductVersion")
posVersion = posVersion + len("ProductVersion")
posNbr = line.find("u'",posVersion) + 2
line = list(line)
line = line[0:posNbr]
version = list(version)
for i,a in enumerate(version):
line.append(a)
#line[posNbr + i] = a
sLine = slice(0,posNbr + i + 1)
line = line[sLine]
line = ''.join(line)#create a string out of a list
line = line + "\')])\n"
print("line:",line)
buffer.append(line)
print("Buffer:",buffer)
with open(file,"w") as f:
f.writelines(buffer)
def getResourcePath(relPath):
try:
basePath = sys._MEIPASS
except Exception:
basePath = os.path.abspath(".")
return os.path.join(basePath,relPath)
def getFileVersionExe(path=getResourcePath("")):
if amIExe():
path = path + "..\\jira-flow.exe"
else: # we run in a dev env
path = "C:\\Program Files\\Jira-Flow\\jira-flow.exe"
print("path to exe:",path)
try:
info = win32api.GetFileVersionInfo(path,'\\')
except Exception as e:
print("we dont seem to run as an exe, aborting version check\n",e)
else:
Pls = info['ProductVersionLS']
Pms = info['ProductVersionMS']
Fls = info['FileVersionLS']
Fms = info['FileVersionMS']
Pversion = ".".join([str(win32api.HIWORD(Pms)),str(win32api.LOWORD(Pms)),str(win32api.HIWORD(Pls)),str(win32api.LOWORD(Pls))])
Fversion = ".".join([str(win32api.HIWORD(Fms)),str(win32api.LOWORD(Fms)),str(win32api.HIWORD(Fls)),str(win32api.LOWORD(Fls))])
#P2version = info['ProductVersion']
print("ProductversionMSLS",Pversion)
print("Fileversion",Fversion)
return Fversion
def getVersionsExe(path=getResourcePath(""),info_str="ProductVersion"):
ver_strings = (
"Comments",
"InternalName",
"ProductName",
"CompanyName",
"LegalCopyright",
"ProductVersion",
"FileDescription",
"LegalTrademarks",
"PrivateBuild",
"FileVersion",
"OriginalFilename",
"SpecialBuild",
)
if amIExe():#we run as deployed version
path = path + "..\\jira-flow.exe"
else: # we run in a dev env sow we run a test against another exe
path = "C:\\Program Files\\Jira-Flow\\jira-flow.exe"
print("path to exe:",path)
try:
info = win32api.GetFileVersionInfo(path,'\\VarFileInfo\\Translation')
except Exception as e:
print("we dont seem to run as an exe, aborting version check\n",e)
else:
for lang,codepage in info:
for ver_string in ver_strings:
str_info = f"\\StringFileInfo\\{lang:04X}{codepage:04X}\\{ver_string}"
print(ver_string, repr(win32api.GetFileVersionInfo(path, str_info)))
if ver_string == info_str:
return repr(win32api.GetFileVersionInfo(path,str_info))
if not amIExe():
version = getVersionGit()
writeVersionFile(version)
if "__main__" in __name__:
version = getVersionGit()
print("version:",version)
writeVersionFile(version)
fileVersion = getFileVersionExe()
print(fileVersion)