diff --git a/scripts/index.py b/scripts/index.py index 84f464f99..c17f40cb8 100644 --- a/scripts/index.py +++ b/scripts/index.py @@ -277,40 +277,59 @@ def index_release_to_elasticsearch(es : Elasticsearch, index_name, release_detai 'gh_package_name': "mikrosdk.7z" } elif 'templates' == name_without_extension: - package_changed = True - if len(metadata_content) > 1: - package_changed = metadata_content[0]['templates']['hash'] != metadata_content[1]['templates']['hash'] - templates_version = check_from_index_version(es, index_name, 'templates') - if package_changed: - templates_version = increment_version(templates_version) + package_id = name_without_extension + hash_previous = check_from_index_hash(es, index_name, 'templates') + support.extract_archive_from_url( + asset['url'], + os.path.join(os.path.dirname(__file__), 'test_package'), + token=token + ) + hash_new = hash_directory_contents(os.path.join(os.path.dirname(__file__), 'test_package')) + shutil.rmtree(os.path.join(os.path.dirname(__file__), 'test_package')) + asset_version_previous = check_from_index_version(es, index_name, 'templates') + asset_version_new = asset_version_previous + if hash_previous: + if hash_previous != hash_new: + asset_version_new = increment_version(check_from_index_version(es, index_name, 'templates')) doc = { "name": name_without_extension, - "version" : templates_version, + "version" : asset_version_new, "display_name" : "NECTO project templates", "hidden" : True, "vendor" : "MIKROE", "type" : "application", "download_link" : asset['url'], "install_location" : "%APPLICATION_DATA_DIR%/templates", - "package_changed": package_changed, + "package_changed": asset_version_previous != asset_version_new, + "hash": hash_new, "gh_package_name": "templates.7z" } elif 'images' == name_without_extension: - package_changed = True package_id = name_without_extension + '_sdk' - images_version_previous = check_from_index_version(es, index_name, 'images_sdk') - if len(metadata_content) > 1: - package_changed = metadata_content[0]['images']['hash'] != metadata_content[1]['images']['hash'] + hash_previous = check_from_index_hash(es, index_name, 'images_sdk') + support.extract_archive_from_url( + asset['url'], + os.path.join(os.path.dirname(__file__), 'test_package'), + token=token + ) + hash_new = hash_directory_contents(os.path.join(os.path.dirname(__file__), 'test_package')) + shutil.rmtree(os.path.join(os.path.dirname(__file__), 'test_package')) + asset_version_previous = check_from_index_version(es, index_name, 'images_sdk') + asset_version_new = asset_version_previous + if hash_previous: + if hash_previous != hash_new: + asset_version_new = increment_version(check_from_index_version(es, index_name, 'images_sdk')) doc = { "name": 'images_sdk', - "version" : increment_version(images_version_previous), + "version" : asset_version_new, "display_name" : "mikroSDK Setup images", "hidden" : True, "vendor" : "MIKROE", "type" : "images", "download_link" : asset['url'], "install_location" : "%APPLICATION_DATA_DIR%/resources/images", - "package_changed": True, + "package_changed": asset_version_previous != asset_version_new, + "hash": hash_new, "gh_package_name": "images.7z" } elif asset['name'].startswith('board') or \