1
0
Fork 0
mirror of https://github.com/foxlet/macOS-Simple-KVM.git synced 2024-11-26 21:19:41 +01:00

[TOOLS] Make FetchMacOS Python2/3 compatible.

This commit is contained in:
Foxlet 2019-04-23 03:53:55 -04:00
parent 5611154d8b
commit 02b3c12bb9

View file

@ -8,6 +8,7 @@ import os
import errno import errno
import click import click
import requests import requests
import sys
__author__ = "Foxlet" __author__ = "Foxlet"
__copyright__ = "Copyright 2018, FurCode Project" __copyright__ = "Copyright 2018, FurCode Project"
@ -66,7 +67,10 @@ class SoftwareService:
return catalog_raw.text.encode('UTF-8') return catalog_raw.text.encode('UTF-8')
def getosinstall(self): def getosinstall(self):
root = plistlib.readPlistFromString(self.catalog_data) if (sys.version_info > (3, 0)):
root = plistlib.readPlistFromBytes(self.catalog_data)
else:
root = plistlib.readPlistFromString(self.catalog_data)
products = root['Products'] products = root['Products']
for product in products: for product in products:
if 'ExtendedMetaInfo' in products[product]: if 'ExtendedMetaInfo' in products[product]:
@ -79,7 +83,10 @@ class SoftwareService:
class MacOSProduct: class MacOSProduct:
def __init__(self, catalog, product_id): def __init__(self, catalog, product_id):
root = plistlib.readPlistFromString(catalog) if (sys.version_info > (3, 0)):
root = plistlib.readPlistFromBytes(catalog)
else:
root = plistlib.readPlistFromString(catalog)
products = root['Products'] products = root['Products']
self.date = root['IndexDate'] self.date = root['IndexDate']
self.product = products[product_id] self.product = products[product_id]
@ -107,13 +114,13 @@ def fetchmacos(output_dir="BaseSystem/", catalog_id="DeveloperSeed", product_id=
product_id = remote.getosinstall() product_id = remote.getosinstall()
else: else:
if product_id == "": if product_id == "":
print "You must provide a Product ID (or pass the -l flag) to continue." print("You must provide a Product ID (or pass the -l flag) to continue.")
exit(1) exit(1)
product_id = product_id product_id = product_id
try: try:
update = MacOSProduct(catalog, product_id) update = MacOSProduct(catalog, product_id)
except KeyError: except KeyError:
print "Product ID {} could not be found.".format(product_id) print("Product ID {} could not be found.".format(product_id))
exit(1) exit(1)
logging.info("Selected macOS Product: {}".format(product_id)) logging.info("Selected macOS Product: {}".format(product_id))