X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=scripts%2Fsdks%2Fagl%2Fdb-dump;h=ec2b1d8ac7adb1672e50e888426de28c29e78a5f;hb=a93832c2e3058c55e183c487dde595bd42238bb0;hp=77f729ee36dc7d6e7d5432b3bec53fd0c9033f4c;hpb=297955b744110f67dad475e628bf068ec849b190;p=src%2Fxds%2Fxds-server.git diff --git a/scripts/sdks/agl/db-dump b/scripts/sdks/agl/db-dump index 77f729e..ec2b1d8 100755 --- a/scripts/sdks/agl/db-dump +++ b/scripts/sdks/agl/db-dump @@ -1,6 +1,6 @@ -#!/usr/bin/python +#!/usr/bin/env python3 # -#/************************************************************************** +# /************************************************************************** # * Copyright 2017-2018 IoT.bzh # * # * author: Romain Forlot @@ -26,25 +26,31 @@ import fnmatch import argparse import subprocess -PARSER = argparse.ArgumentParser(description='Lists available and installed SDKs') +PARSER = argparse.ArgumentParser( + description='Lists available and installed SDKs') PARSER.add_argument('-debug', dest='debug', action='store_true', help='Output debug log messages') ARGS = PARSER.parse_args() if ARGS.debug: - logging.basicConfig(level=logging.DEBUG, format='%(asctime)s:%(levelname)s: %(message)s') + logging.basicConfig(level=logging.DEBUG, + format='%(asctime)s:%(levelname)s: %(message)s') else: - logging.basicConfig(level=logging.INFO, format='%(asctime)s:%(levelname)s: %(message)s') + logging.basicConfig(level=logging.INFO, + format='%(asctime)s:%(levelname)s: %(message)s') -SCRIPT_PATH = os.path.dirname(os.path.abspath(inspect.getfile(inspect.currentframe()))) +SCRIPT_PATH = os.path.dirname(os.path.abspath( + inspect.getfile(inspect.currentframe()))) -ENV = subprocess.check_output([os.path.join(SCRIPT_PATH, './_env-init.sh'), '-print']).splitlines() +ENV = subprocess.check_output( + [os.path.join(SCRIPT_PATH, './_env-init.sh'), '-print']).splitlines() +SDK_ROOT_DIR = None for elt in ENV: - k, v = elt.split('=', 1) + k, v = elt.decode().split('=', 1) if k == 'SDK_ROOT_DIR': - SDK_ROOT_DIR = v + SDK_ROOT_DIR = v.rstrip('/') elif k == 'SDK_ENV_SETUP_FILENAME': SDK_ENV_SETUP_FILENAME = v @@ -65,12 +71,18 @@ SDK_DB_JSON = json.load(open(SDK_DB_FILEPATH, 'r')) for one_sdk in SDK_DB_JSON: one_sdk['status'] = 'Not Installed' + one_sdk['uuid'] = '' INSTALLED_SDK = [] for root, dirs, files in os.walk(SDK_ROOT_DIR): depth = root[len(SDK_ROOT_DIR) + len(os.path.sep):].count(os.path.sep) + # Limit the walking depth of processed directories if depth >= 4: dirs[:] = [] + # Only process SDK dir matching profile/version/arch or + # profile/version/arch/tag + elif depth != 2 and depth != 3: + continue EF, VF = '', '' for one_file in files: if fnmatch.fnmatch(one_file, SDK_ENV_SETUP_FILENAME): @@ -78,41 +90,54 @@ for root, dirs, files in os.walk(SDK_ROOT_DIR): if fnmatch.fnmatch(one_file, 'version-*'): VF = os.path.join(root, one_file) if EF != '' and VF != '': + logging.debug('Adding installed SDK ' + root) INSTALLED_SDK.append({'ENV_FILE': EF, 'VERSION_FILE': VF}) + elif (EF == '' and VF != '') or (EF != '' and VF == ''): + logging.debug( + 'WARNING SDK ignored : root=%s, EnvFile=%s, VersFile=%s', root, EF, VF) for one_sdk in INSTALLED_SDK: logging.debug("Processing %s", one_sdk['ENV_FILE']) - PROFILE = one_sdk['ENV_FILE'].split('/')[3] - VERSION = one_sdk['ENV_FILE'].split('/')[4] - ARCH = one_sdk['ENV_FILE'].split('/')[5] + envFile = one_sdk['ENV_FILE'].split(SDK_ROOT_DIR+'/')[1] + PROFILE = envFile.split('/')[0] + VERSION = envFile.split('/')[1] + ARCH = envFile.split('/')[2] DIR = os.path.dirname(one_sdk['ENV_FILE']) if PROFILE == '' or VERSION == '' or ARCH == '' or DIR == '': logging.debug('Path not compliant, skipping') continue + UUID = os.path.basename(os.path.normpath(DIR)) + SDK_DATE = '' for line in open(one_sdk['VERSION_FILE']).readlines(): if line.startswith('Timestamp'): D = line.split(':')[1] if D: D = D.strip() - SDK_DATE = '{}-{}-{} {}:{}'.format(D[0:4], D[4:6], D[6:8], D[8:10], D[10:12]) + SDK_DATE = '{}-{}-{} {}:{}'.format( + D[0:4], D[4:6], D[6:8], D[8:10], D[10:12]) logging.debug('Found date: %s', SDK_DATE) found = False for sdk in SDK_DB_JSON: if sdk['profile'] == PROFILE and sdk['version'] == VERSION and sdk['arch'] == ARCH: + if sdk['status'] == 'Installed': + continue found = True sdk['status'] = 'Installed' sdk['date'] = SDK_DATE sdk['setupFile'] = one_sdk['ENV_FILE'] sdk['path'] = DIR + sdk['uuid'] = UUID break if not found: - logging.debug('Not found in database, adding it...') + logging.debug('Not found in database, add: ' + + PROFILE + '-' + ARCH + '-' + VERSION) NEW_SDK = { 'name': PROFILE + '-' + ARCH + '-' + VERSION, + 'uuid': UUID, 'description': 'AGL SDK ' + ARCH + ' (version ' + VERSION + ')', 'profile': PROFILE, 'version': VERSION, @@ -124,7 +149,7 @@ for one_sdk in INSTALLED_SDK: 'size': "", 'md5sum': "", 'setupFile': one_sdk['ENV_FILE'] - } + } SDK_DB_JSON.append(NEW_SDK) -print json.dumps(SDK_DB_JSON) +print(json.dumps(SDK_DB_JSON))