Skip to content

Commit 58c20d5

Browse files
committed
Rework the update process
This changes the update process so the Python code itself calls the unzip utility (instead of going through a script). The new code is also extracted to a temporary directory which is then moved into place after the current version has been modev away as a backup. I also added a lot of logging around this area, to have better visibility on what happens.
1 parent 8173bfd commit 58c20d5

File tree

1 file changed

+69
-30
lines changed

1 file changed

+69
-30
lines changed

ReleaseManager/releaseManager.py

Lines changed: 69 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
from github import Github
1010
import wget
1111
import subprocess
12-
from shutil import copyfile
12+
import shutil
1313

1414

1515
class ReleaseManager(MakesmithInitFuncs):
@@ -50,7 +50,7 @@ def checkForLatestPyRelease(self):
5050
tag_float = float(tag_name)
5151
eligible = False
5252
if not enableExperimental:
53-
if not self.isExperimental(tag_name):
53+
if not self.isExperimental(release):
5454
eligible = True
5555
else:
5656
eligible = True
@@ -74,19 +74,16 @@ def checkForLatestPyRelease(self):
7474
except Exception as e:
7575
print("Error checking pyrelease: " + str(e))
7676

77-
def isExperimental(self, tag):
77+
def isExperimental(self, release):
7878
'''
79-
Deternmines if release is experimental. All even releases are stable, odd releases are experimental
79+
Deternmines if release is experimental. Pre-Releases are experimental.
8080
:param tag:
8181
:return:
8282
'''
83-
if float(tag) <= 0.931: # all releases before now are 'stable'
84-
return False
85-
lastDigit = tag[-1]
86-
if (int(lastDigit) % 2) == 0: # only even releases are 'stable'
87-
return False
88-
else:
83+
if release.prerelease:
8984
return True
85+
else:
86+
return False
9087

9188
def processAbsolutePath(self, path):
9289
index = path.find("main.py")
@@ -106,36 +103,78 @@ def updatePyInstaller(self, bypassCheck = False):
106103
except:
107104
print("error cleaning download directory: ", filePath)
108105
print("---")
106+
print("Downloading new WebControl release...")
109107
if self.data.pyInstallPlatform == "win32" or self.data.pyInstallPlatform == "win64":
110108
filename = wget.download(self.data.pyInstallUpdateBrowserUrl, out=home + "\\.WebControl\\downloads")
111109
else:
112110
filename = wget.download(self.data.pyInstallUpdateBrowserUrl, out=home + "/.WebControl/downloads")
113-
print(filename)
111+
print("Successfully downloaded new release to:" + filename)
114112

115113
if self.data.platform == "PYINSTALLER":
116114
lhome = os.path.join(self.data.platformHome)
117115
else:
118116
lhome = "."
119-
if self.data.pyInstallPlatform == "win32" or self.data.pyInstallPlatform == "win64":
120-
path = lhome + "/tools/upgrade_webcontrol_win.bat"
121-
copyfile(path, home + "/.WebControl/downloads/upgrade_webcontrol_win.bat")
122-
path = lhome + "/tools/7za.exe"
123-
copyfile(path, home + "/.WebControl/downloads/7za.exe")
124-
self.data.pyInstallInstalledPath = self.data.pyInstallInstalledPath.replace('/', '\\')
125-
program_name = home + "\\.WebControl\\downloads\\upgrade_webcontrol_win.bat"
126117

118+
print("Creating target version directory...")
119+
target_dir = self.data.pyInstallInstalledPath + '_next'
120+
if os.path.exists(target_dir):
121+
print("New release directory already exists, removing it")
122+
shutil.rmtree(target_dir)
123+
os.mkdir(target_dir)
124+
print("Creating target version directory DONE")
125+
126+
print("Unzipping new release...")
127+
if self.data.pyInstallPlatform == "win32" or self.data.pyInstallPlatform == "win64":
128+
command = [
129+
lhome + "/tools/7za.exe",
130+
"x",
131+
"-y",
132+
filename,
133+
"-o",
134+
target_dir
135+
]
136+
print(command)
137+
subprocess.run(command)
138+
else:
139+
command = [
140+
"tar",
141+
"-zxf",
142+
filename,
143+
"-C",
144+
target_dir
145+
]
146+
print(command)
147+
subprocess.run(command)
148+
print("Unzipping new release DONE")
149+
150+
print("Upgrade script...")
151+
print("Checking if it needs to be run for platform: " + self.data.pyInstallPlatform)
152+
if self.data.pyInstallPlatform == "win32" or self.data.pyInstallPlatform == "win64":
153+
upgrade_script_path = target_dir + "\\tools\\upgrade_" + self.data.pyInstallPlatform + ".bat"
154+
else:
155+
upgrade_script_path = target_dir + "/tools/upgrade_" + self.data.pyInstallPlatform + ".sh"
156+
if os.path.exists(upgrade_script_path):
157+
print("Yes, running it")
158+
self.make_executable(upgrade_script_path)
159+
subprocess.run([upgrade_script_path])
127160
else:
128-
path = lhome + "/tools/upgrade_webcontrol.sh"
129-
copyfile(path, home + "/.WebControl/downloads/upgrade_webcontrol.sh")
130-
program_name = home + "/.WebControl/downloads/upgrade_webcontrol.sh"
131-
self.make_executable(home + "/.WebControl/downloads/upgrade_webcontrol.sh")
132-
tool_path = home + "\\.WebControl\\downloads\\7za.exe"
133-
arguments = [filename, self.data.pyInstallInstalledPath, tool_path]
134-
command = [program_name]
135-
command.extend(arguments)
136-
print("popening")
137-
print(command)
138-
subprocess.Popen(command)
161+
print("No upgrade script needed.")
162+
print("Upgrade script DONE")
163+
164+
print("Backing up the current install...")
165+
backup_path = self.data.pyInstallInstalledPath + '_old'
166+
print("Backup location: " + backup_path)
167+
if os.path.exists(backup_path):
168+
print("Old backup found, removing it")
169+
shutil.rmtree(backup_path)
170+
os.rename(self.data.pyInstallInstalledPath, self.data.pyInstallInstalledPath + '_old')
171+
print("Backing up the current install DONE")
172+
173+
print("Moving the target version in place...")
174+
os.rename(target_dir, self.data.pyInstallInstalledPath)
175+
print("Moving the target version in place DONE")
176+
177+
print("WebControl upgrade complete, shutting down to make way to the target version")
139178
return True
140179
return False
141180

@@ -165,7 +204,7 @@ def update(self, version):
165204
self.data.pyInstallUpdateBrowserUrl = asset.browser_download_url
166205
print(self.data.pyInstallUpdateBrowserUrl)
167206
return self.updatePyInstaller(True)
168-
print("hmmm.. issue")
207+
print("Couldn't find a suitable file for the current platform and target version: " + version)
169208
return False
170209

171210

0 commit comments

Comments
 (0)