diff --git a/tools/cefbuilds/cef_json_builder.py b/tools/cefbuilds/cef_json_builder.py index 5edc12afa..4bed305fb 100644 --- a/tools/cefbuilds/cef_json_builder.py +++ b/tools/cefbuilds/cef_json_builder.py @@ -74,16 +74,16 @@ class cef_json_encoder(json.JSONEncoder): return o -_chromium_version_regex = '[1-9]{1}[0-9]{1,2}\.0\.[1-9]{1}[0-9]{2,4}\.(0|[1-9]{1}[0-9]{0,2})' -_cef_hash_regex = 'g[0-9a-f]{7}' -_cef_number_regex = '[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5}' +_chromium_version_regex = r'[1-9]{1}[0-9]{1,2}\.0\.[1-9]{1}[0-9]{2,4}\.(0|[1-9]{1}[0-9]{0,2})' +_cef_hash_regex = r'g[0-9a-f]{7}' +_cef_number_regex = r'[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5}' # Example: 3.2704.1414.g185cd6c -_cef_old_version_regex = _cef_number_regex + '\.' + _cef_hash_regex +_cef_old_version_regex = _cef_number_regex + r'\.' + _cef_hash_regex # Example: 74.0.1+g62d140e+chromium-74.0.3729.6 -_cef_version_release_regex = _cef_number_regex + '\+' + _cef_hash_regex + '\+chromium\-' + _chromium_version_regex +_cef_version_release_regex = _cef_number_regex + r'\+' + _cef_hash_regex + r'\+chromium\-' + _chromium_version_regex # Example: 74.0.0-master.1920+g725ed88+chromium-74.0.3729.0 -_cef_version_dev_regex = _cef_number_regex + '\-\w+\.[0-9]{1,7}\+' + _cef_hash_regex + '\+chromium\-' + _chromium_version_regex +_cef_version_dev_regex = _cef_number_regex + r'\-\w+\.[0-9]{1,7}\+' + _cef_hash_regex + r'\+chromium\-' + _chromium_version_regex class cef_json_builder: @@ -141,6 +141,22 @@ class cef_json_builder: self._versions = {} self._queryct = 0 + def filter_files(self, files, file_type, sha1, name): + filtered_files = [] + file_changed = True + for file_record in files: + if file_record['type'] == file_type: + existing_sha1 = file_record['sha1'] + if existing_sha1 != sha1: + # Print and filter out the file with a different sha1. + self._print(f' Remove {name} {existing_sha1}') + else: + file_changed = False + filtered_files.append(file_record) + else: + filtered_files.append(file_record) + return filtered_files, file_changed + def __repr__(self): # Return a string representation of this object. self._sort_versions() @@ -315,11 +331,10 @@ class cef_json_builder: def _sort_versions(self): # Sort version records by first (newest) file last_modified value. for platform in self._data.keys(): - for i in range(0, len(self._data[platform]['versions'])): - self._data[platform]['versions'] = \ - sorted(self._data[platform]['versions'], - key=lambda k: k['files'][0]['last_modified'], - reverse=True) + self._data[platform]['versions'] = sorted( + self._data[platform]['versions'], + key=lambda k: k['files'][0]['last_modified'], + reverse=True) @staticmethod def _sort_files(files): @@ -422,8 +437,8 @@ class cef_json_builder: # Find the existing version record. version_idx = -1 - for i in range(0, len(self._data[platform]['versions'])): - if self._data[platform]['versions'][i]['cef_version'] == version: + for i, v in enumerate(self._data[platform]['versions']): + if v['cef_version'] == version and v['channel'] == channel: # Check the version record. self._print('add_file: Check %s %s' % (platform, version)) version_idx = i @@ -440,21 +455,9 @@ class cef_json_builder: }) version_idx = len(self._data[platform]['versions']) - 1 - # Find the existing file record with matching type. - file_changed = True - for i in range(0, - len(self._data[platform]['versions'][version_idx]['files'])): - if self._data[platform]['versions'][version_idx]['files'][i][ - 'type'] == type: - existing_sha1 = self._data[platform]['versions'][version_idx]['files'][ - i]['sha1'] - if existing_sha1 != sha1: - # Remove the existing file record. - self._print(' Remove %s %s' % (name, existing_sha1)) - del self._data[platform]['versions'][version_idx]['files'][i] - else: - file_changed = False - break + files = self._data[platform]['versions'][version_idx]['files'] + self._data[platform]['versions'][version_idx][ + 'files'], file_changed = self.filter_files(files, type, sha1, name) if file_changed: # Add a new file record. diff --git a/tools/cefbuilds/cef_json_builder_test.py b/tools/cefbuilds/cef_json_builder_test.py index db348a761..4cf076488 100644 --- a/tools/cefbuilds/cef_json_builder_test.py +++ b/tools/cefbuilds/cef_json_builder_test.py @@ -78,7 +78,8 @@ class TestCefJSONBuilder(unittest.TestCase): type='standard', channel='stable', attrib_idx=0, - shouldfail=False): + shouldfail=False, + sha1='2d48ee05ea6385c8fe80879c98c5dd505ad4b100'): name = cef_json_builder.get_file_name(version, platform, type, channel) + '.tar.gz' @@ -86,7 +87,7 @@ class TestCefJSONBuilder(unittest.TestCase): attribs = [{ 'date_str': '2016-05-18T22:42:15.487Z', 'date_val': datetime.datetime(2016, 5, 18, 22, 42, 15, 487000), - 'sha1': '2d48ee05ea6385c8fe80879c98c5dd505ad4b100', + 'sha1': sha1, 'size': 48395610 }, { 'date_str': '2016-05-14T22:42:15.487Z', @@ -437,6 +438,25 @@ class TestCefJSONBuilder(unittest.TestCase): # Only old-style version numbers. self.assertEqual(4, builder.get_query_count()) + def test_add_files_with_diff_sha1(self): + builder = cef_json_builder() + + sha1 = '2d48ee05ea6385c8fe80879c98c5dd505ad4b100' + self._add_test_file(builder, sha1=sha1) + + new_sha1 = '2d48ee05ea6385c8fe80879c98c5dd505ad4b101' + expected = self._add_test_file(builder, sha1=new_sha1) + files = builder.get_files() + self.assertEqual(len(files), 1) + self.assertEqual(expected, files[0]) + + def test_add_files_with_diff_channels(self): + builder = cef_json_builder() + self._add_test_file(builder, channel='beta') + self._add_test_file(builder, channel='stable') + files = builder.get_files() + self.assertEqual(len(files), 2) + # Program entry point. if __name__ == '__main__':