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