cefbuilds: Add channel matching for file records

This commit is contained in:
Marshall Greenblatt 2024-10-02 13:23:31 -04:00
parent abfc029a01
commit 2b6f461337
2 changed files with 53 additions and 30 deletions

View File

@ -74,16 +74,16 @@ class cef_json_encoder(json.JSONEncoder):
return o 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})' _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 = 'g[0-9a-f]{7}' _cef_hash_regex = r'g[0-9a-f]{7}'
_cef_number_regex = '[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5}' _cef_number_regex = r'[0-9]{1,5}\.[0-9]{1,5}\.[0-9]{1,5}'
# Example: 3.2704.1414.g185cd6c # 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 # 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 # 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: class cef_json_builder:
@ -141,6 +141,22 @@ class cef_json_builder:
self._versions = {} self._versions = {}
self._queryct = 0 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): def __repr__(self):
# Return a string representation of this object. # Return a string representation of this object.
self._sort_versions() self._sort_versions()
@ -315,9 +331,8 @@ class cef_json_builder:
def _sort_versions(self): def _sort_versions(self):
# Sort version records by first (newest) file last_modified value. # Sort version records by first (newest) file last_modified value.
for platform in self._data.keys(): 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'] = \ self._data[platform]['versions'],
sorted(self._data[platform]['versions'],
key=lambda k: k['files'][0]['last_modified'], key=lambda k: k['files'][0]['last_modified'],
reverse=True) reverse=True)
@ -422,8 +437,8 @@ class cef_json_builder:
# Find the existing version record. # Find the existing version record.
version_idx = -1 version_idx = -1
for i in range(0, len(self._data[platform]['versions'])): for i, v in enumerate(self._data[platform]['versions']):
if self._data[platform]['versions'][i]['cef_version'] == version: if v['cef_version'] == version and v['channel'] == channel:
# Check the version record. # Check the version record.
self._print('add_file: Check %s %s' % (platform, version)) self._print('add_file: Check %s %s' % (platform, version))
version_idx = i version_idx = i
@ -440,21 +455,9 @@ class cef_json_builder:
}) })
version_idx = len(self._data[platform]['versions']) - 1 version_idx = len(self._data[platform]['versions']) - 1
# Find the existing file record with matching type. files = self._data[platform]['versions'][version_idx]['files']
file_changed = True self._data[platform]['versions'][version_idx][
for i in range(0, 'files'], file_changed = self.filter_files(files, type, sha1, name)
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
if file_changed: if file_changed:
# Add a new file record. # Add a new file record.

View File

@ -78,7 +78,8 @@ class TestCefJSONBuilder(unittest.TestCase):
type='standard', type='standard',
channel='stable', channel='stable',
attrib_idx=0, attrib_idx=0,
shouldfail=False): shouldfail=False,
sha1='2d48ee05ea6385c8fe80879c98c5dd505ad4b100'):
name = cef_json_builder.get_file_name(version, platform, type, name = cef_json_builder.get_file_name(version, platform, type,
channel) + '.tar.gz' channel) + '.tar.gz'
@ -86,7 +87,7 @@ class TestCefJSONBuilder(unittest.TestCase):
attribs = [{ attribs = [{
'date_str': '2016-05-18T22:42:15.487Z', 'date_str': '2016-05-18T22:42:15.487Z',
'date_val': datetime.datetime(2016, 5, 18, 22, 42, 15, 487000), 'date_val': datetime.datetime(2016, 5, 18, 22, 42, 15, 487000),
'sha1': '2d48ee05ea6385c8fe80879c98c5dd505ad4b100', 'sha1': sha1,
'size': 48395610 'size': 48395610
}, { }, {
'date_str': '2016-05-14T22:42:15.487Z', 'date_str': '2016-05-14T22:42:15.487Z',
@ -437,6 +438,25 @@ class TestCefJSONBuilder(unittest.TestCase):
# Only old-style version numbers. # Only old-style version numbers.
self.assertEqual(4, builder.get_query_count()) 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. # Program entry point.
if __name__ == '__main__': if __name__ == '__main__':