Fix remote file not found error

Last published version doesn't ship with darwin tools so in case of error fall back to the latest version that has them
Also needs the main bash script to be updated to use this python script in place of the exe
This commit is contained in:
Paolo 2019-09-22 15:22:36 +02:00 committed by GitHub
parent 99325b99a7
commit 69d8a517d1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -78,21 +78,32 @@ def main():
sys.stderr.write('You need Python 2.7 or later\n')
sys.exit(1)
# Setup url and file paths
url = 'http://softwareupdate.vmware.com/cds/vmw-desktop/fusion/'
dest = os.path.dirname(os.path.abspath(__file__))
# Re-create the tools folder
shutil.rmtree(dest + '/tools', True)
os.mkdir(dest + '/tools')
parser = CDSParser()
success = False
n = 1
# Last published version doesn't ship with darwin tools
# so in case of error fall back to the latest version that has them
while (success == False):
print('Trying for the '+str(n)+'th time')
# Setup url and file paths
url = 'http://softwareupdate.vmware.com/cds/vmw-desktop/fusion/'
# Get the list of Fusion releases
# And get the last item in the ul/li tags
response = urlopen(url)
html = response.read()
parser = CDSParser()
parser.clean()
parser.feed(str(html))
url = url + parser.HTMLDATA[-1] + '/'
url = url + parser.HTMLDATA[-n] + '/'
parser.clean()
# Open the latest release page
@ -100,14 +111,21 @@ def main():
response = urlopen(url)
html = response.read()
parser.feed(str(html))
urlpost15 = url + parser.HTMLDATA[-1] + '/packages/com.vmware.fusion.tools.darwin.zip.tar'
urlpre15 = url + parser.HTMLDATA[-1] + '/packages/com.vmware.fusion.tools.darwinPre15.zip.tar'
parser.clean()
# Download the darwin.iso tgz file
print('Retrieving Darwin tools from: ' + urlpost15)
try:
urlretrieve(urlpost15, convertpath(dest + '/tools/com.vmware.fusion.tools.darwin.zip.tar'))
except:
print('Link didn\'t work, trying another one...')
n += 1
continue
# Extract the tar to zip
tar = tarfile.open(convertpath(dest + '/tools/com.vmware.fusion.tools.darwin.zip.tar'), 'r')
tar.extract('com.vmware.fusion.tools.darwin.zip', path=convertpath(dest + '/tools/'))
@ -130,7 +148,12 @@ def main():
# Download the darwinPre15.iso tgz file
print('Retrieving DarwinPre15 tools from: ' + urlpre15)
try:
urlretrieve(urlpre15, convertpath(dest + '/tools/com.vmware.fusion.tools.darwinPre15.zip.tar'))
except:
print('Link didn\'t work, trying another one...')
n += 1
continue
# Extract the tar to zip
tar = tarfile.open(convertpath(dest + '/tools/com.vmware.fusion.tools.darwinPre15.zip.tar'), 'r')
@ -153,7 +176,7 @@ def main():
shutil.rmtree(convertpath(dest + '/tools/payload'), True)
os.remove(convertpath(dest + '/tools/com.vmware.fusion.tools.darwinPre15.zip.tar'))
os.remove(convertpath(dest + '/tools/com.vmware.fusion.tools.darwinPre15.zip'))
success = True
if __name__ == '__main__':
main()