Skip to content

Commit 53d270e

Browse files
Add reinstall option to viewer and python 2 version
1 parent 5aa47a2 commit 53d270e

File tree

2 files changed

+194
-55
lines changed

2 files changed

+194
-55
lines changed

install_viewer.py

Lines changed: 55 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -74,62 +74,62 @@ def main():
7474

7575
if isNewer(latestVersion, currentInfo['version']):
7676
print("There is a newer version available.\nCurrent version is: %s. The new version is %s." % (currentInfo['version'], latestVersion))
77-
shouldDownload = input("Download? (Y/N) > ").lower() == "y"
78-
if shouldDownload:
79-
newestUrl = baseUrl + ("%s/%s.zip" % (latestVersion, currentInfo['system']))
80-
downloadLocation = os.path.join(directory, zipFileName)
81-
if os.path.exists(downloadLocation):
82-
print("Removing previous archive...")
83-
os.remove(downloadLocation)
84-
print("Deleted old archive.")
85-
print("Downloading new client... This could take a while.")
86-
urlretrieve(newestUrl, downloadLocation, downloadProgress)
87-
print()
88-
print("Successfully downloaded files. ")
89-
outputDirectory = os.path.join(directory, viewerDirectory)
90-
if os.path.exists(outputDirectory):
91-
print("Removing previous client")
92-
shutil.rmtree(outputDirectory, True)
93-
print("Successfully removed previous client.")
94-
print("Extracting from archive...")
95-
zip_ref = zipfile.ZipFile(downloadLocation, "r")
96-
zip_ref.extractall(outputDirectory)
97-
zip_ref.close()
98-
print("Extracted fully!")
99-
if os.path.exists(downloadLocation):
100-
print("Cleaning up downloads...")
101-
os.remove(downloadLocation)
102-
print("Cleaned up")
103-
try:
104-
if currentInfo['system'] == 'Linux32':
105-
print("Fixing permissions...")
106-
print("chmod 777 viewer_latest/Linux32/battleclient18.x86")
107-
os.system("chmod 777 viewer_latest/Linux32/battleclient18.x86")
108-
print("Done fixing permissions!")
109-
elif currentInfo['system'] == 'Linux64':
110-
print("Fixing permissions...")
111-
print("chmod 777 viewer_latest/Linux64/battleclient18.x86_64")
112-
os.system("chmod 777 viewer_latest/Linux64/battleclient18.x86_64")
113-
print("Done fixing permissions!")
114-
if currentInfo['system'] == 'Mac':
115-
print("Fixing permissions...")
116-
print("chmod -R 777 viewer_latest/Mac/battleclient18.app")
117-
os.system("chmod -R 777 viewer_latest/Mac/battleclient18.app")
118-
print("Done fixing permissions!")
119-
except:
120-
pass
121-
print("Updating current version number...")
122-
newInfo = {}
123-
newInfo['version'] = latestVersion
124-
newInfo['system'] = currentInfo['system']
125-
currentInfoFile = open(currentInfoFileLocation, "w")
126-
currentInfo = json.dump(newInfo, currentInfoFile)
127-
currentInfoFile.close()
128-
print("All set! The viewer is in: %s" % outputDirectory)
129-
else:
130-
print("Not downloading - your system has not been changed.")
13177
else:
132-
print("No updates!")
78+
print("No updates! Would you like to reinstall the viewer anyway?")
79+
shouldDownload = input("Download? (Y/N) > ").lower() == "y"
80+
if shouldDownload:
81+
newestUrl = baseUrl + ("%s/%s.zip" % (latestVersion, currentInfo['system']))
82+
downloadLocation = os.path.join(directory, zipFileName)
83+
if os.path.exists(downloadLocation):
84+
print("Removing previous archive...")
85+
os.remove(downloadLocation)
86+
print("Deleted old archive.")
87+
print("Downloading new client... This could take a while.")
88+
urlretrieve(newestUrl, downloadLocation, downloadProgress)
89+
print()
90+
print("Successfully downloaded files. ")
91+
outputDirectory = os.path.join(directory, viewerDirectory)
92+
if os.path.exists(outputDirectory):
93+
print("Removing previous client")
94+
shutil.rmtree(outputDirectory, True)
95+
print("Successfully removed previous client.")
96+
print("Extracting from archive...")
97+
zip_ref = zipfile.ZipFile(downloadLocation, "r")
98+
zip_ref.extractall(outputDirectory)
99+
zip_ref.close()
100+
print("Extracted fully!")
101+
if os.path.exists(downloadLocation):
102+
print("Cleaning up downloads...")
103+
os.remove(downloadLocation)
104+
print("Cleaned up")
105+
try:
106+
if currentInfo['system'] == 'Linux32':
107+
print("Fixing permissions...")
108+
print("chmod 777 viewer_latest/Linux32/battleclient18.x86")
109+
os.system("chmod 777 viewer_latest/Linux32/battleclient18.x86")
110+
print("Done fixing permissions!")
111+
elif currentInfo['system'] == 'Linux64':
112+
print("Fixing permissions...")
113+
print("chmod 777 viewer_latest/Linux64/battleclient18.x86_64")
114+
os.system("chmod 777 viewer_latest/Linux64/battleclient18.x86_64")
115+
print("Done fixing permissions!")
116+
if currentInfo['system'] == 'Mac':
117+
print("Fixing permissions...")
118+
print("chmod -R 777 viewer_latest/Mac/battleclient18.app")
119+
os.system("chmod -R 777 viewer_latest/Mac/battleclient18.app")
120+
print("Done fixing permissions!")
121+
except:
122+
pass
123+
print("Updating current version number...")
124+
newInfo = {}
125+
newInfo['version'] = latestVersion
126+
newInfo['system'] = currentInfo['system']
127+
currentInfoFile = open(currentInfoFileLocation, "w")
128+
currentInfo = json.dump(newInfo, currentInfoFile)
129+
currentInfoFile.close()
130+
print("All set! The viewer is in: %s" % outputDirectory)
131+
else:
132+
print("Not downloading - your system has not been changed.")
133133

134134
if __name__ == "__main__":
135135
main()

install_viewer_py2.py

Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
from __future__ import print_function
2+
import os
3+
import json
4+
import zipfile
5+
import shutil
6+
import sys
7+
8+
9+
import urllib #import urlretrieve, urlopen
10+
11+
#def downloadFile(url, outFile):
12+
# urlretrieve(url, outFile)
13+
14+
def isNewer(new, original):
15+
majorMult, minorMult, patchMult = 10000,100,1
16+
major1, minor1, patch1 = original.split('.')
17+
major2, minor2, patch2 = new.split('.')
18+
return majorMult * major2 + minorMult * minor2 + patchMult * minor2 > majorMult * major1 + minorMult * minor1 + patchMult * minor1
19+
20+
21+
def downloadProgress(count, blockSize, totalSize):
22+
if count % 1000 == 0:
23+
percentDone = float(count) * blockSize / totalSize * 100.0
24+
print("%4.2f%%" % percentDone,end='\b\b\b\b\b\b')
25+
26+
def main():
27+
currentInstallFileName = "viewer_currentInstall.json"
28+
29+
versionAndChangeLogUrl = "http://s3.amazonaws.com/battlecode-2018/viewer/"
30+
31+
versionFileName = "version.txt"
32+
changelogFileName = "changelog.json"
33+
34+
baseUrl = "http://s3.amazonaws.com/battlecode-2018/viewer/"
35+
36+
directory = os.path.dirname(os.path.realpath(__file__))
37+
38+
zipFileName = "viewer_latest.zip"
39+
viewerDirectory = "viewer_latest/"
40+
41+
currentInfoFileLocation = os.path.join(directory, currentInstallFileName)
42+
if os.path.exists(currentInfoFileLocation):
43+
currentInfoFile = open(currentInfoFileLocation)
44+
currentInfo = json.load(currentInfoFile)
45+
currentInfoFile.close()
46+
else:
47+
possibleSystems = [
48+
("1", "Windows (64-bit)", "Win64"),
49+
("2", "Windows (32-bit)", "Win32"),
50+
("3", "Linux (64-bit)", "Linux64"),
51+
("4", "Linux (32-bit)", "Linux32"),
52+
("5", "Mac OS X", "Mac")
53+
]
54+
print("It looks like this is your first time installing the viewer. What system are you using?")
55+
for optionNum, optionName, actualName in possibleSystems:
56+
print("%s) %s" % (optionNum, optionName))
57+
systemInp = raw_input("> ")
58+
try:
59+
systemInp = int(systemInp)
60+
if systemInp <= 0 or systemInp > len(possibleSystems):
61+
raise Exception()
62+
currentInfo = {
63+
'version': '0.0.0',
64+
'system': possibleSystems[systemInp - 1][2]
65+
}
66+
print("Done setup! You've selected the system %s. \nIf you ever want to change this setup, delete the file %s " % (possibleSystems[systemInp-1][1], currentInstallFileName))
67+
except:
68+
print("Invalid input. Exiting..")
69+
sys.exit(1)
70+
71+
72+
versionFileUrl = versionAndChangeLogUrl + versionFileName
73+
latestVersion = urllib.urlopen(versionFileUrl).read().decode()
74+
75+
print("Checking for updates...")
76+
77+
if isNewer(latestVersion, currentInfo['version']):
78+
print("There is a newer version available.\nCurrent version is: %s. The new version is %s." % (currentInfo['version'], latestVersion))
79+
else:
80+
print("No updates! Would you like to reinstall the viewer anyway?")
81+
shouldDownload = raw_input("Download? (Y/N) > ").lower() == "y"
82+
if shouldDownload:
83+
newestUrl = baseUrl + ("%s/%s.zip" % (latestVersion, currentInfo['system']))
84+
downloadLocation = os.path.join(directory, zipFileName)
85+
if os.path.exists(downloadLocation):
86+
print("Removing previous archive...")
87+
os.remove(downloadLocation)
88+
print("Deleted old archive.")
89+
print("Downloading new client... This could take a while.")
90+
urllib.urlretrieve(newestUrl, downloadLocation, downloadProgress)
91+
print()
92+
print("Successfully downloaded files. ")
93+
outputDirectory = os.path.join(directory, viewerDirectory)
94+
if os.path.exists(outputDirectory):
95+
print("Removing previous client")
96+
shutil.rmtree(outputDirectory, True)
97+
print("Successfully removed previous client.")
98+
print("Extracting from archive...")
99+
zip_ref = zipfile.ZipFile(downloadLocation, "r")
100+
zip_ref.extractall(outputDirectory)
101+
zip_ref.close()
102+
print("Extracted fully!")
103+
if os.path.exists(downloadLocation):
104+
print("Cleaning up downloads...")
105+
os.remove(downloadLocation)
106+
print("Cleaned up")
107+
try:
108+
if currentInfo['system'] == 'Linux32':
109+
print("Fixing permissions...")
110+
print("chmod 777 viewer_latest/Linux32/battleclient18.x86")
111+
os.system("chmod 777 viewer_latest/Linux32/battleclient18.x86")
112+
print("Done fixing permissions!")
113+
elif currentInfo['system'] == 'Linux64':
114+
print("Fixing permissions...")
115+
print("chmod 777 viewer_latest/Linux64/battleclient18.x86_64")
116+
os.system("chmod 777 viewer_latest/Linux64/battleclient18.x86_64")
117+
print("Done fixing permissions!")
118+
if currentInfo['system'] == 'Mac':
119+
print("Fixing permissions...")
120+
print("chmod -R 777 viewer_latest/Mac/battleclient18.app")
121+
os.system("chmod -R 777 viewer_latest/Mac/battleclient18.app")
122+
print("Done fixing permissions!")
123+
except:
124+
pass
125+
print("Updating current version number...")
126+
newInfo = {}
127+
newInfo['version'] = latestVersion
128+
newInfo['system'] = currentInfo['system']
129+
currentInfoFile = open(currentInfoFileLocation, "w")
130+
currentInfo = json.dump(newInfo, currentInfoFile)
131+
currentInfoFile.close()
132+
print("All set! The viewer is in: %s" % outputDirectory)
133+
else:
134+
print("Not downloading - your system has not been changed.")
135+
136+
if __name__ == "__main__":
137+
main()
138+
139+

0 commit comments

Comments
 (0)