X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;f=scripts%2Fsdks%2Fagl%2Fdb-dump;h=fecdcd3c32e17d875c8c71e3c741107a2d29ec27;hb=b33e880f23525b4f75cf35e39aa5082addef0fb7;hp=ec2b1d8ac7adb1672e50e888426de28c29e78a5f;hpb=a93832c2e3058c55e183c487dde595bd42238bb0;p=src%2Fxds%2Fxds-server.git diff --git a/scripts/sdks/agl/db-dump b/scripts/sdks/agl/db-dump index ec2b1d8..fecdcd3 100755 --- a/scripts/sdks/agl/db-dump +++ b/scripts/sdks/agl/db-dump @@ -1,4 +1,4 @@ -#!/usr/bin/env python3 +#!/usr/bin/python3 # # /************************************************************************** # * Copyright 2017-2018 IoT.bzh @@ -19,12 +19,15 @@ # **************************************************************************/ import os +import sys import json import logging import inspect import fnmatch import argparse import subprocess +from subprocess import DEVNULL +import re PARSER = argparse.ArgumentParser( description='Lists available and installed SDKs') @@ -48,11 +51,15 @@ ENV = subprocess.check_output( SDK_ROOT_DIR = None for elt in ENV: - k, v = elt.decode().split('=', 1) - if k == 'SDK_ROOT_DIR': - SDK_ROOT_DIR = v.rstrip('/') - elif k == 'SDK_ENV_SETUP_FILENAME': - SDK_ENV_SETUP_FILENAME = v + # only match what defines a variable + z = re.match(r"^(\w+)=([^']*)$", elt.decode()) + if z: + k = z.group(1) + v = z.group(2) + if k == 'SDK_ROOT_DIR': + SDK_ROOT_DIR = v.rstrip('/') + elif k == 'SDK_ENV_SETUP_FILENAME': + SDK_ENV_SETUP_FILENAME = v if SDK_ROOT_DIR is None: logging.error('No SDK_ROOT_DIR environment variable found.') @@ -61,11 +68,11 @@ elif SDK_ENV_SETUP_FILENAME is None: SDK_ENV_SETUP_FILENAME = 'environment-setup*' # Get list of available SDKs -SDK_DB_FILEPATH = os.path.join(SDK_ROOT_DIR, "sdks_latest.json") +SDK_DB_FILEPATH = os.path.join(SDK_ROOT_DIR, 'sdks_latest.json') if not os.path.exists(SDK_DB_FILEPATH): DB_UPDATE_FILEPATH = os.path.join(SCRIPT_PATH, 'db-update') - os.system(DB_UPDATE_FILEPATH + " " + SDK_DB_FILEPATH) + os.system(DB_UPDATE_FILEPATH + ' ' + SDK_DB_FILEPATH) SDK_DB_JSON = json.load(open(SDK_DB_FILEPATH, 'r')) @@ -83,25 +90,42 @@ for root, dirs, files in os.walk(SDK_ROOT_DIR): # profile/version/arch/tag elif depth != 2 and depth != 3: continue - EF, VF = '', '' + + # Only consider SDK as valid if environment-setup and version files and + # sysroots directory can be found + EF, VF, SR = '', '', '' + for one_dir in dirs: + if fnmatch.fnmatch(one_dir, 'sysroots'): + SR = os.path.join(root, one_dir) + for one_file in files: if fnmatch.fnmatch(one_file, SDK_ENV_SETUP_FILENAME): EF = os.path.join(root, one_file) - if fnmatch.fnmatch(one_file, 'version-*'): + elif fnmatch.fnmatch(one_file, 'version-*'): VF = os.path.join(root, one_file) - if EF != '' and VF != '': + if EF != '' and VF != '' and SR != '': logging.debug('Adding installed SDK ' + root) - INSTALLED_SDK.append({'ENV_FILE': EF, 'VERSION_FILE': VF}) + INSTALLED_SDK.append( + {'ENV_FILE': EF, 'VERSION_FILE': VF, 'SYSROOTS': SR}) elif (EF == '' and VF != '') or (EF != '' and VF == ''): logging.debug( - 'WARNING SDK ignored : root=%s, EnvFile=%s, VersFile=%s', root, EF, VF) + 'WARNING SDK ignored : root=%s, EnvFile=%s, VersionFile=%s, sysroots=%s', root, EF, VF, SR) for one_sdk in INSTALLED_SDK: - logging.debug("Processing %s", one_sdk['ENV_FILE']) + logging.debug('Processing %s', one_sdk['ENV_FILE']) envFile = one_sdk['ENV_FILE'].split(SDK_ROOT_DIR+'/')[1] PROFILE = envFile.split('/')[0] VERSION = envFile.split('/')[1] ARCH = envFile.split('/')[2] + # and specific case for qemu where arch is not the same (qemux86-64 vs corei7-64) + if ARCH == 'corei7-64': + # Use /etc/rpm/platform to distinguish qemux86-64 from corei7-64 architecture + grepQemu = subprocess.call(['grep', '-q', 'qemux86', os.path.join( + one_sdk['SYSROOTS'], 'corei7-64-agl-linux', 'etc', 'rpm', 'platform')], + stdout=DEVNULL, stderr=subprocess.STDOUT) + if grepQemu == 0: + ARCH = 'qemux86-64' + DIR = os.path.dirname(one_sdk['ENV_FILE']) if PROFILE == '' or VERSION == '' or ARCH == '' or DIR == '': logging.debug('Path not compliant, skipping') @@ -119,11 +143,27 @@ for one_sdk in INSTALLED_SDK: D[0:4], D[4:6], D[6:8], D[8:10], D[10:12]) logging.debug('Found date: %s', SDK_DATE) + # Check if installed SDKs match the ones listed in json file found = False for sdk in SDK_DB_JSON: + # Matching based on profile + version + arch fields if sdk['profile'] == PROFILE and sdk['version'] == VERSION and sdk['arch'] == ARCH: if sdk['status'] == 'Installed': continue + # Additional verification based on url used to generate UUID (see also same logic in add script) + if sdk['url'] != '': + try: + ps = subprocess.Popen( + ('echo', sdk['url']), stdout=subprocess.PIPE) + uuid_md5 = subprocess.check_output( + ('md5sum'), stdin=ps.stdout) + ps.wait() + if str(uuid_md5).split(' ')[0][2:] != UUID: + continue + except: + e = sys.exc_info()[0] + logging.error('Error while checking UUID: ' % e) + found = True sdk['status'] = 'Installed' sdk['date'] = SDK_DATE @@ -143,11 +183,12 @@ for one_sdk in INSTALLED_SDK: 'version': VERSION, 'arch': ARCH, 'path': DIR, - 'url': "", - 'status': "Installed", + 'url': '', + 'image_url': '', + 'status': 'Installed', 'date': SDK_DATE, - 'size': "", - 'md5sum': "", + 'size': '', + 'md5sum': '', 'setupFile': one_sdk['ENV_FILE'] } SDK_DB_JSON.append(NEW_SDK)