mirror of
https://github.com/paolo-projects/unlocker.git
synced 2025-07-29 17:04:33 +02:00
Completed tools downloader
This commit is contained in:
parent
3cc4516735
commit
d59b8ab3b2
76
gettools.py
76
gettools.py
@ -1,3 +1,27 @@
|
|||||||
|
"""
|
||||||
|
The MIT License (MIT)
|
||||||
|
|
||||||
|
Copyright (c) 2015 Dave Parsons
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the 'Software'), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in
|
||||||
|
all copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
||||||
|
THE SOFTWARE.
|
||||||
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import urllib
|
import urllib
|
||||||
import urllib2
|
import urllib2
|
||||||
@ -11,10 +35,12 @@ import zipfile
|
|||||||
class myHTMLParser(HTMLParser):
|
class myHTMLParser(HTMLParser):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
|
HTMLParser.__init__(self)
|
||||||
self.reset()
|
self.reset()
|
||||||
self.HTMLDATA = []
|
self.HTMLDATA = []
|
||||||
|
|
||||||
def handle_data(self, data):
|
def handle_data(self, data):
|
||||||
|
# Build a list of numeric data from any element
|
||||||
if data.find("\n") == -1 :
|
if data.find("\n") == -1 :
|
||||||
if data[0].isdigit():
|
if data[0].isdigit():
|
||||||
self.HTMLDATA.append(data)
|
self.HTMLDATA.append(data)
|
||||||
@ -23,31 +49,57 @@ class myHTMLParser(HTMLParser):
|
|||||||
self.HTMLDATA = []
|
self.HTMLDATA = []
|
||||||
|
|
||||||
|
|
||||||
|
def convertPath(path):
|
||||||
|
# OS path separator replacement funciton
|
||||||
|
return path.replace(os.path.sep, '/')
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
|
# Setup url and file paths
|
||||||
url = 'http://softwareupdate.vmware.com/cds/vmw-desktop/fusion/'
|
url = 'http://softwareupdate.vmware.com/cds/vmw-desktop/fusion/'
|
||||||
dir = os.path.dirname(os.path.abspath(__file__))
|
dir = os.path.dirname(os.path.abspath(__file__))
|
||||||
|
|
||||||
|
# Re-create the tools folder
|
||||||
|
shutil.rmtree(dir + '/tools', True)
|
||||||
|
os.mkdir(dir + '/tools')
|
||||||
|
|
||||||
|
# Get the list of Fusion releases
|
||||||
|
# And get the last item in the ul/li tags
|
||||||
response = urllib2.urlopen(url)
|
response = urllib2.urlopen(url)
|
||||||
html = response.read()
|
html = response.read()
|
||||||
parser = myHTMLParser()
|
parser = myHTMLParser()
|
||||||
parser.feed(html)
|
parser.feed(html)
|
||||||
url = url + parser.HTMLDATA[-1] + '/'
|
url = url + parser.HTMLDATA[-1] + '/'
|
||||||
|
parser.clean()
|
||||||
|
|
||||||
|
# Open the latest release page
|
||||||
|
# And build file URL
|
||||||
response = urllib2.urlopen(url)
|
response = urllib2.urlopen(url)
|
||||||
html = response.read()
|
html = response.read()
|
||||||
parser.clean()
|
|
||||||
parser.feed(html)
|
parser.feed(html)
|
||||||
url = url + parser.HTMLDATA[-1] + '/packages/com.vmware.fusion.tools.darwin.zip.tar'
|
url = url + parser.HTMLDATA[-1] + '/packages/com.vmware.fusion.tools.darwin.zip.tar'
|
||||||
urllib.urlretrieve(url, 'tools/com.vmware.fusion.tools.darwin.zip.tar')
|
|
||||||
parser.clean()
|
parser.clean()
|
||||||
tar = tarfile.open('tools/com.vmware.fusion.tools.darwin.zip.tar', 'r')
|
|
||||||
tar.extract('com.vmware.fusion.tools.darwin.zip', path='tools/')
|
# Download the darwin.iso tgz file
|
||||||
zip = zipfile.ZipFile('tools/com.vmware.fusion.tools.darwin.zip', 'r')
|
urllib.urlretrieve(url, 'tools/com.vmware.fusion.tools.darwin.zip.tar')
|
||||||
zip.extract('payload/darwin.iso', path='tools/')
|
|
||||||
zip.extract('payload/darwin.iso.sig', path='tools/')
|
# Extract the tar to zip
|
||||||
shutil.move(dir + '/tools/payload/darwin.iso', dir + '/tools/darwin.iso')
|
tar = tarfile.open(convertPath(dir + '/tools/com.vmware.fusion.tools.darwin.zip.tar'), 'r')
|
||||||
shutil.move(dir + '/tools/payload/darwin.iso.sig', dir + '/tools/darwin.iso.sig')
|
tar.extract('com.vmware.fusion.tools.darwin.zip', path=convertPath(dir + '/tools/'))
|
||||||
shutil.rmtree(dir + '/tools/payload', True)
|
|
||||||
os.remove(dir + '/tools/com.vmware.fusion.tools.darwin.zip.tar')
|
# Extract the iso and sig files from zip
|
||||||
os.remove(dir + '/tools/com.vmware.fusion.tools.darwin.zip')
|
zip = zipfile.ZipFile(convertPath(dir + '/tools/com.vmware.fusion.tools.darwin.zip'), 'r')
|
||||||
|
zip.extract('payload/darwin.iso', path=convertPath(dir + '/tools/'))
|
||||||
|
zip.extract('payload/darwin.iso.sig', path=convertPath(dir + '/tools/'))
|
||||||
|
|
||||||
|
# Move the iso and sig files to tools folder
|
||||||
|
shutil.move(convertPath(dir + '/tools/payload/darwin.iso'), convertPath(dir + '/tools/darwin.iso'))
|
||||||
|
shutil.move(convertPath(dir + '/tools/payload/darwin.iso.sig'), convertPath(dir + '/tools/darwin.iso.sig'))
|
||||||
|
|
||||||
|
# Cleanup workiong files and folders
|
||||||
|
shutil.rmtree(convertPath(dir + '/tools/payload'), True)
|
||||||
|
os.remove(convertPath(dir + '/tools/com.vmware.fusion.tools.darwin.zip.tar'))
|
||||||
|
os.remove(convertPath(dir + '/tools/com.vmware.fusion.tools.darwin.zip'))
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
Loading…
x
Reference in New Issue
Block a user