Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
106 changes: 16 additions & 90 deletions gettools.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,53 +27,23 @@
import os
import sys
import shutil
import tarfile
import zipfile
import time

ARCH = 'x86_x64'

try:
# For Python 3.0 and later
# noinspection PyCompatibility
from urllib.request import urlopen
# noinspection PyCompatibility
from html.parser import HTMLParser
# noinspection PyCompatibility
from urllib.request import urlretrieve
except ImportError:
# Fall back to Python 2
# noinspection PyCompatibility
from urllib2 import urlopen
# noinspection PyCompatibility
from HTMLParser import HTMLParser
# noinspection PyCompatibility
from urllib import urlretrieve


# Parse the Fusion directory page
class CDSParser(HTMLParser):

def __init__(self):
HTMLParser.__init__(self)
self.reset()
self.HTMLDATA = []

def handle_data(self, data):
# Build a list of numeric data from any element
if data.find("\n") == -1:
if data[0].isdigit():
self.HTMLDATA.append(data)
self.HTMLDATA.sort(key=lambda s: [int(u) for u in s.split('.')])

def clean(self):
self.HTMLDATA = []


def convertpath(path):
# OS path separator replacement funciton
return path.replace(os.path.sep, '/')

def reporthook(count, block_size, total_size):
global start_time
if count == 0:
Expand All @@ -100,67 +70,23 @@ def main():
shutil.rmtree(dest + '/tools', True)
os.mkdir(dest + '/tools')

parser = CDSParser()

# Last published version doesn't ship with darwin tools
# so in case of error get it from the core.vmware.fusion.tar
print('Trying to get tools from the packages folder...')

# 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.clean()
parser.feed(str(html))
url = url + parser.HTMLDATA[-1] + '/'
parser.clean()

# Open the latest release page
# And build file URL
response = urlopen(url)
html = response.read()
parser.feed(str(html))

lastVersion = parser.HTMLDATA[-1]

parser.clean()

urlcoretar = url + lastVersion + '/universal/core/com.vmware.fusion.zip.tar'

# Get the main core file
# Static URL for direct tool ISO download from VMWare's frozen repository
url_darwin = 'https://packages.vmware.com/tools/frozen/darwin/darwin.iso'
url_darwin_pre15 = 'https://packages.vmware.com/tools/frozen/darwin/darwinPre15.iso'

print('Trying to get Tools from the frozen repository...')

# Get the two darwin ISOs
try:
urlretrieve(urlcoretar, convertpath(dest + '/tools/com.vmware.fusion.zip.tar'), reporthook)
except:
print('Couldn\'t find tools')
urlretrieve(url_darwin, convertpath(dest + '/tools/darwin.iso'), reporthook)
urlretrieve(url_darwin_pre15, convertpath(dest + '/tools/darwinPre15.iso'), reporthook)
except Exception as e:
print('\nError downloading tools: ' + str(e))
return

print('Extracting com.vmware.fusion.zip.tar...')
tar = tarfile.open(convertpath(dest + '/tools/com.vmware.fusion.zip.tar'), 'r')
tar.extract('com.vmware.fusion.zip', path=convertpath(dest + '/tools/'))
tar.close()

print('Extracting files from com.vmware.fusion.zip...')
cdszip = zipfile.ZipFile(convertpath(dest + '/tools/com.vmware.fusion.zip'), 'r')
cdszip.extract('payload/VMware Fusion.app/Contents/Library/isoimages/' + ARCH + '/darwin.iso', path=convertpath(dest + '/tools/'))
cdszip.extract('payload/VMware Fusion.app/Contents/Library/isoimages/' + ARCH + '/darwinPre15.iso', path=convertpath(dest + '/tools/'))
cdszip.close()

# Move the iso and sig files to tools folder
shutil.move(convertpath(dest + '/tools/payload/VMware Fusion.app/Contents/Library/isoimages/' + ARCH + '/darwin.iso'), convertpath(dest + '/tools/darwin.iso'))
shutil.move(convertpath(dest + '/tools/payload/VMware Fusion.app/Contents/Library/isoimages/' + ARCH + '/darwinPre15.iso'), convertpath(dest + '/tools/darwinPre15.iso'))

# Cleanup working files and folders
shutil.rmtree(convertpath(dest + '/tools/payload'), True)
os.remove(convertpath(dest + '/tools/com.vmware.fusion.zip.tar'))
os.remove(convertpath(dest + '/tools/com.vmware.fusion.zip'))

print('Tools retrieved successfully')

print('\nTools retrieved successfully')
return


if __name__ == '__main__':
main()