Update package filter

Update and tested
This commit is contained in:
Kamte
2024-03-10 17:52:45 +06:30
committed by GitHub
parent 6a59f55d3a
commit 233a8a188e

View File

@@ -14,6 +14,7 @@ import json
import locale import locale
import ctypes import ctypes
import sys import sys
import operator
from collections import OrderedDict from collections import OrderedDict
from xml.etree import ElementTree as ET from xml.etree import ElementTree as ET
@@ -32,7 +33,7 @@ except ImportError:
or run: pip3 install tqdm.""") or run: pip3 install tqdm.""")
VERSION = 1 VERSION = 1
VERSION_STR = '0.0.1' VERSION_STR = '0.0.3'
CODE_QUALITY = 'Really_AWFUL' CODE_QUALITY = 'Really_AWFUL'
ADOBE_PRODUCTS_XML_URL = 'https://prod-rel-ffc-ccm.oobesaas.adobe.com/adobe-ffc-external/core/v{urlVersion}/products/all?_type=xml&channel=ccm&channel=sti&platform={installPlatform}&productType=Desktop' ADOBE_PRODUCTS_XML_URL = 'https://prod-rel-ffc-ccm.oobesaas.adobe.com/adobe-ffc-external/core/v{urlVersion}/products/all?_type=xml&channel=ccm&channel=sti&platform={installPlatform}&productType=Desktop'
@@ -51,12 +52,6 @@ ADOBE_DL_HEADERS = {
session = requests.sessions.Session() session = requests.sessions.Session()
try:
os.environ["PROGRAMFILES(X86)"]
osArch = "win64"
except:
osArch = "win32"
def show_version(): def show_version():
ye = int((32 - len(VERSION_STR)) / 2) ye = int((32 - len(VERSION_STR)) / 2)
@@ -88,10 +83,19 @@ def url_version():
elif args.urlVersion.lower() == "v6" or args.urlVersion == "6": elif args.urlVersion.lower() == "v6" or args.urlVersion == "6":
urlVersion = 6 urlVersion = 6
else: else:
print('Invalid argument "{}" for {}'.format(args.urlVersion, 'URL version')) print('Invalid argument "{}" for {}! Please select from version list below\n'.format(args.urlVersion, 'URL version'))
exit(1) urlVersion = None
while not urlVersion: while not urlVersion:
versions = {
'v4' : 'URL version 4',
'v5' : 'URL version 5',
'v6' : 'URL version 6',
}
print('Available URL versions')
for p, v in versions.items():
print('[{}]{}{}'.format(p, (12 - len(p)) * ' ', v))
val = input('\nPlease enter the URL version(v4/v5/v6) for downloading products.xml, or nothing for v6: ') or 'v6' val = input('\nPlease enter the URL version(v4/v5/v6) for downloading products.xml, or nothing for v6: ') or 'v6'
if val == 'v4' or val == '4': if val == 'v4' or val == '4':
urlVersion = 4 urlVersion = 4
@@ -100,35 +104,37 @@ def url_version():
elif val == 'v6' or val == '6': elif val == 'v6' or val == '6':
urlVersion = 6 urlVersion = 6
else: else:
print('Invalid URL version: {}'.format(val)) print('Invalid URL version: {}\n'.format(val))
print('\nUsing URL version {}\n'.format(urlVersion))
return urlVersion return urlVersion
def app_platform(): def app_platform():
winPlatforms = {
'win32' : '32 Bit Windows',
'win64' : '64 Bit Windows',
'winarm64' : 'Windows ARM',
}
appPlatform = None appPlatform = None
if args.appPlatform: if args.appPlatform:
if "64" in args.appPlatform: if args.appPlatform in winPlatforms:
appPlatform = "win64" appPlatform = args.appPlatform
print('\nUsing provided version: ' + appPlatform)
elif "32" in args.appPlatform:
appPlatform = "win32"
print('\nUsing provided version: ' + appPlatform) print('\nUsing provided version: ' + appPlatform)
else: else:
print('Invalid argument "{}" for {}'.format(args.appPlatform, 'application platform')) print('Invalid argument "{}" for {}! Please select form list below\n'.format(args.appPlatform, 'application platform'))
exit(1) appPlatform = None
while not appPlatform: while not appPlatform:
val = input('Please enter application platform (eg win32), or nothing for win64: ') or osArch print('Available Platforms')
if val == 'win32': for p, v in winPlatforms.items():
appPlatform = 'win32' print('[{}]{}{}'.format(p, (12 - len(p)) * ' ', v))
elif val == 'win64':
appPlatform = 'win64' val = input('\nPlease enter application platform (eg win32), or nothing for win64: ') or 'win64'
else: if val in winPlatforms:
print('Invalid platform: {}'.format(val)) appPlatform = val
else:
print('Invalid platform: {}\n'.format(val))
print('\nGetting {} products\n'.format(appPlatform))
return appPlatform return appPlatform
@@ -184,7 +190,6 @@ def install_language(supportedLangs):
else: else:
if 'All' not in supportedLangs: if 'All' not in supportedLangs:
supportedLangs.append('All') supportedLangs.append('All')
supportedLangs.sort() supportedLangs.sort()
# Detecting Current set default Os language. Fixed. # Detecting Current set default Os language. Fixed.
@@ -234,6 +239,7 @@ def install_language(supportedLangs):
print('\nDownloading packages with {} language'.format(installLanguage)) print('\nDownloading packages with {} language'.format(installLanguage))
return installLanguage return installLanguage
def product_icons(elem): def product_icons(elem):
productIcons = [] productIcons = []
if len(elem.find('productIcons')): if len(elem.find('productIcons')):
@@ -286,7 +292,7 @@ def parse_products_xml(products_url, allowed_platform, selected_platform):
for platform in platforms: for platform in platforms:
appPlatform = platform.attrib['id'] appPlatform = platform.attrib['id']
# filtered by allowed platform # filtered by allowed platforms
if appPlatform in allowed_platform: if appPlatform in allowed_platform:
languageSet = platform.findall("languageSet") languageSet = platform.findall("languageSet")
if len(languageSet): if len(languageSet):
@@ -299,7 +305,6 @@ def parse_products_xml(products_url, allowed_platform, selected_platform):
'displayName': displayName, 'displayName': displayName,
'appPlatform' : appPlatform, 'appPlatform' : appPlatform,
'productVersion' : productInfo.get('productVersion'), 'productVersion' : productInfo.get('productVersion'),
'baseVersion' : productInfo.get('baseVersion'),
'supportedLanguages' : product_languages(ls), 'supportedLanguages' : product_languages(ls),
'productIcons' : product_icons(product), 'productIcons' : product_icons(product),
'buildGuid' : productInfo.get('buildGuid'), 'buildGuid' : productInfo.get('buildGuid'),
@@ -336,7 +341,6 @@ def parse_products_xml(products_url, allowed_platform, selected_platform):
'displayName': displayName, 'displayName': displayName,
'appPlatform' : selected_platform, 'appPlatform' : selected_platform,
'productVersion' : productInfo.get('productVersion'), 'productVersion' : productInfo.get('productVersion'),
'baseVersion' : productInfo.get('baseVersion'),
'supportedLanguages' : product_languages(ls), 'supportedLanguages' : product_languages(ls),
'productIcons' : product_icons(product), 'productIcons' : product_icons(product),
'buildGuid' : productInfo.get('buildGuid'), 'buildGuid' : productInfo.get('buildGuid'),
@@ -352,7 +356,10 @@ def parse_products_xml(products_url, allowed_platform, selected_platform):
def get_products(): def get_products():
selectedVersion = url_version() selectedVersion = url_version()
print('\nUsing URL version {}\n'.format(selectedVersion))
selectedPlatform = app_platform() selectedPlatform = app_platform()
print('\nGetting {} products\n'.format(selectedPlatform))
if args.Auth: if args.Auth:
ADOBE_REQ_HEADERS['Authorization'] = args.Auth ADOBE_REQ_HEADERS['Authorization'] = args.Auth
@@ -364,7 +371,7 @@ def get_products():
productsPlatform += ',win32' productsPlatform += ',win32'
products_xml_url = ADOBE_PRODUCTS_XML_URL.format(urlVersion=selectedVersion, installPlatform=productsPlatform) products_xml_url = ADOBE_PRODUCTS_XML_URL.format(urlVersion=selectedVersion, installPlatform=productsPlatform)
# download and parse product xml products, cdn = # download and parse product xml
products, cdn = parse_products_xml(products_xml_url, allowedPlatforms, selectedPlatform) products, cdn = parse_products_xml(products_xml_url, allowedPlatforms, selectedPlatform)
sapCodes = {} sapCodes = {}
@@ -383,7 +390,7 @@ def get_products():
print('\nProvided SAP Code not found in products: ' + args.sapCode) print('\nProvided SAP Code not found in products: ' + args.sapCode)
exit(1) exit(1)
return products, cdn, sapCodes return products, cdn, sapCodes, selectedPlatform
def get_download_path(): def get_download_path():
@@ -448,12 +455,11 @@ def file_download(url, dest_dir, s, v, name=None):
def download_acrobat(appInfo, cdn): def download_acrobat(appInfo, cdn):
"""Download manifest.xml""" """Download manifest.xml"""
# download manifest.xml
response = session.get(cdn + appInfo['manifestURL'], stream=True, headers=ADOBE_REQ_HEADERS) response = session.get(cdn + appInfo['manifestURL'], stream=True, headers=ADOBE_REQ_HEADERS)
response.encoding = 'utf-8' response.encoding = 'utf-8'
# to study # to study
#with open('manifest.xml', 'wb+') as f: with open('manifest.xml', 'wb+') as f:
# f.write(response.content) f.write(response.content)
manifest = ET.fromstring(response.text) manifest = ET.fromstring(response.text)
# for full app # for full app
@@ -532,25 +538,74 @@ def write_driver_xml(jsonData, products_dir, prefix=""):
tree = ET.ElementTree(driver) tree = ET.ElementTree(driver)
ET.indent(tree, space=" ", level=0) ET.indent(tree, space=" ", level=0)
xml_file = os.path.join(products_dir, prefix + 'driver.xml') xml_file = os.path.join(products_dir, prefix + 'Driver.xml')
tree.write(xml_file, encoding='utf-8', xml_declaration=True) tree.write(xml_file, encoding='utf-8', xml_declaration=True)
def condition_check(condition, language): def condition_test(package, language, ProcessorFamily, condition):
if 'installLanguage' in condition: packageType = ProcessorFamily
if language == 'All': if 'ProcessorFamily' in package:
return True packageType = package['ProcessorFamily']
else:
if language in condition:
return True
if 'OSProcessorFamily' in condition: if '==' in condition:
# lock on 64 bit os testSubject, testValue = condition.split('==')
processor = '64-bit' testOption = operator.eq
if processor in condition: elif '!=' in condition:
return True testSubject, testValue = condition.split('!=')
testOption = operator.ne
elif '<=' in condition:
testSubject, testValue = condition.split('<=')
testOption = operator.le
elif '>=' in condition:
testSubject, testValue = condition.split('>=')
testOption = operator.ge
elif '>' in condition:
testSubject, testValue = condition.split('>')
testOption = operator.gt
elif '<' in condition:
testSubject, testValue = condition.split('<')
testOption = operator.lt
return False # start testing
if testSubject.strip() == '[OSProcessorFamily]':
return testOption(testValue.strip(), ProcessorFamily)
elif testSubject.strip() == '[OSVersion]':
getWinVer = sys.getwindowsversion()
winVer = '{}.{}'.format(getWinVer.major, getWinVer.minor)
return testOption(testValue.strip(), winVer)
elif testSubject.strip() == '[installLanguage]' and packageType == ProcessorFamily:
if language.lower() == 'all' or language.lower() == 'mul':
return True
else:
return testOption(testValue.strip(), language)
else:
# alway true on unset
return True
def condition_filter(package, language, ProcessorFamily):
conditions = []
conditionString = package['Condition'].strip()
result = False
if '&&' in conditionString:
conditions = conditionString.split('&&')
for condition in conditions:
result = True
if condition_test(package, language, ProcessorFamily, condition) == False:
result = False
break
elif '||' in conditionString:
conditions = conditionString.split('||')
for condition in conditions:
result = False
if condition_test(package, language, ProcessorFamily, condition) == True:
result = True
break
else:
result = condition_test(package, language, ProcessorFamily, conditionString)
return result
def language_for_premiere(language): def language_for_premiere(language):
@@ -560,61 +615,85 @@ def language_for_premiere(language):
return language return language
def package_filter(package, language): def package_filter(package, language, platform):
coreCount = 0 coreCount = 0
noneCoreCount = 0 noneCoreCount = 0
newPackage = [] urlPath = []
urlPath = [] newPackage = []
for pkg in package:
if pkg.get('Type') and pkg['Type'] == 'core':
if 'Condition' in pkg:
condition = pkg['Condition']
if condition_check(condition, language):
newPackage.append(pkg)
urlPath.append(pkg['Path'])
coreCount += 1
else:
newPackage.append(pkg)
urlPath.append(pkg['Path'])
coreCount += 1
else: ProcessorFamily = '64-bit'
if 'Condition' in pkg: if platform == 'win32':
condition = pkg['Condition'] ProcessorFamily = '32-bit'
if condition_check(condition, language):
newPackage.append(pkg) for pkg in package:
urlPath.append(pkg['Path']) if pkg.get('Type') and pkg['Type'] == 'core':
noneCoreCount += 1 if 'Condition' in pkg:
else: if condition_filter(pkg, language, ProcessorFamily) == True:
newPackage.append(pkg)
urlPath.append(pkg['Path'])
coreCount += 1
elif 'ProcessorFamily' in pkg:
if platform == 'win32':
if pkg['ProcessorFamily'] == ProcessorFamily:
newPackage.append(pkg)
urlPath.append(pkg['Path'])
coreCount += 1
else:
newPackage.append(pkg)
urlPath.append(pkg['Path'])
coreCount += 1
else:
newPackage.append(pkg)
urlPath.append(pkg['Path'])
coreCount += 1
else:
if 'Condition' in pkg:
if condition_filter(pkg, language, ProcessorFamily) == True:
newPackage.append(pkg)
urlPath.append(pkg['Path'])
noneCoreCount += 1
elif 'ProcessorFamily' in pkg:
if platform == 'win32':
if pkg['ProcessorFamily'] == ProcessorFamily:
newPackage.append(pkg)
urlPath.append(pkg['Path'])
noneCoreCount += 1
else:
newPackage.append(pkg)
urlPath.append(pkg['Path'])
noneCoreCount += 1
else:
# for premiere pro # for premiere pro
if '-esl_lp_' in pkg['PackageName']: if '-esl_lp_' in pkg['PackageName']:
if language_for_premiere(language) in pkg['PackageName']: if language_for_premiere(language) in pkg['PackageName']:
newPackage.append(pkg) newPackage.append(pkg)
urlPath.append(pkg['Path']) urlPath.append(pkg['Path'])
noneCoreCount += 1 noneCoreCount += 1
else: else:
newPackage.append(pkg) newPackage.append(pkg)
urlPath.append(pkg['Path']) urlPath.append(pkg['Path'])
noneCoreCount += 1 noneCoreCount += 1
print('Selected {} core packages and {} non-core packages'.format(coreCount, noneCoreCount))
return urlPath, newPackage print('Selected {} core packages and {} non-core packages'.format(coreCount, noneCoreCount))
return urlPath, newPackage
def dependencies_download(dep_data, products_dir): def dependencies_download(dep_data, products_dir, language, selectedPlatform):
dep_dir = os.path.join(products_dir, dep_data['sapCode']) dep_dir = os.path.join(products_dir, dep_data['sapCode'])
os.makedirs(dep_dir, exist_ok=True) os.makedirs(dep_dir, exist_ok=True)
dep_data = list(dep_data['versions'].values()) dep_data = list(dep_data['versions'].values())
firstItem = dep_data[0] firstItem = dep_data[0]
dep_json = get_application_json(firstItem['buildGuid']) dep_json = get_application_json(firstItem['buildGuid'])
package_download(dep_json, dep_dir) package_download(dep_json, dep_dir, language, selectedPlatform)
def package_download(app_json, package_dir, language='All'): def package_download(app_json, package_dir, language, selectedPlatform):
allPackages = app_json['Packages']['Package'] allPackages = app_json['Packages']['Package']
cdn = app_json['Cdn']['Secure'] cdn = app_json['Cdn']['Secure']
sapCode = app_json['SAPCode'] sapCode = app_json['SAPCode']
version = app_json['ProductVersion'] version = app_json['ProductVersion']
urls, package = package_filter(allPackages, language) urls, package = package_filter(allPackages, language, selectedPlatform)
# filtered json data # filtered json data
app_json['Packages']['Package'] = package app_json['Packages']['Package'] = package
@@ -625,7 +704,7 @@ def package_download(app_json, package_dir, language='All'):
file_download(cdn + url, package_dir, sapCode, version) file_download(cdn + url, package_dir, sapCode, version)
def run_ccdl(products, cdn, sapCodes): def run_ccdl(products, cdn, sapCodes, selectedPlatform):
"""Run Main execution.""" """Run Main execution."""
# get product list # get product list
sapCode = product_code(sapCodes) sapCode = product_code(sapCodes)
@@ -663,13 +742,13 @@ def run_ccdl(products, cdn, sapCodes):
app_json = get_application_json(prodInfo['buildGuid']) app_json = get_application_json(prodInfo['buildGuid'])
package_download(app_json, package_dir, installLanguage) package_download(app_json, package_dir, installLanguage, selectedPlatform)
if 'Dependencies' in app_json: if 'Dependencies' in app_json:
for dependency in app_json['Dependencies']['Dependency']: for dependency in app_json['Dependencies']['Dependency']:
depSap = dependency['SAPCode'] depSap = dependency['SAPCode']
depPackage = products.get(depSap) depPackage = products.get(depSap)
dependencies_download(depPackage, products_dir) dependencies_download(depPackage, products_dir, installLanguage, selectedPlatform)
print('\nGenerating driver.xml') print('\nGenerating driver.xml')
prefix = app_json['SAPCode'] + '-' prefix = app_json['SAPCode'] + '-'
@@ -704,9 +783,9 @@ if __name__ == '__main__':
help="Skip existing files, e.g. resuming failed downloads", action='store_true') help="Skip existing files, e.g. resuming failed downloads", action='store_true')
args = parser.parse_args() args = parser.parse_args()
products, cdn, sapCodes = get_products() products, cdn, sapCodes, selectedPlatform = get_products()
while True: while True:
run_ccdl(products, cdn, sapCodes) run_ccdl(products, cdn, sapCodes, selectedPlatform)
if args.noRepeatPrompt or not questiony('\n\nDo you want to download another package'): if args.noRepeatPrompt or not questiony('\n\nDo you want to download another package'):
break break