|
49 | 49 |
|
50 | 50 |
|
51 | 51 | def parse_changelog(changelog_path):
|
52 |
| - """Read changelog entries from provided file path.""" |
53 |
| - changelog_list = [] |
| 52 | + """Parse changelog data from specified gitlab-ci generated file.""" |
54 | 53 | if not os.path.exists(changelog_path):
|
55 | 54 | return None
|
56 |
| - # Attempt to open changelog with utf-8, and then utf-16 (for unix / windows support) |
57 |
| - for encoding_name in ('utf_8', 'utf_16'): |
58 |
| - try: |
59 |
| - with codecs.open( |
60 |
| - changelog_path, 'r', encoding=encoding_name |
61 |
| - ) as changelog_file: |
62 |
| - for line in changelog_file: |
| 55 | + changelog_regex = re.compile(r'(\w{6,10})\s+(\d{4}-\d{2}-\d{2})\s+(.*)\s{2,99}?(.*)') |
| 56 | + changelog_list = [] |
| 57 | + try: |
| 58 | + with codecs.open(changelog_path, 'r', encoding='utf_8') as changelog_file: |
| 59 | + # Split changelog safely (since multiline regex fails to parse the windows line endings correctly) |
| 60 | + # All our log files use unit line endings (even on Windows) |
| 61 | + change_log_lines = changelog_file.read().split("\n") |
| 62 | + for change in change_log_lines: |
| 63 | + # Generate match object with fields from all matching lines |
| 64 | + match = changelog_regex.findall(change) |
| 65 | + if match: |
63 | 66 | changelog_list.append({
|
64 |
| - 'hash': line[:9].strip(), |
65 |
| - 'date': line[9:20].strip(), |
66 |
| - 'author': line[20:45].strip(), |
67 |
| - 'subject': line[45:].strip(), |
| 67 | + "hash": match[0][0].strip(), |
| 68 | + "date": match[0][1].strip(), |
| 69 | + "author": match[0][2].strip(), |
| 70 | + "subject": match[0][3].strip(), |
68 | 71 | })
|
69 |
| - break |
70 |
| - except Exception: |
71 |
| - log.warning('Failed to parse log file %s with encoding %s' % (changelog_path, encoding_name)) |
72 |
| - return changelog_list |
73 |
| - |
74 |
| - |
75 |
| -def parse_new_changelog(changelog_path): |
76 |
| - """Parse changelog data from specified new-format file.""" |
77 |
| - if not os.path.exists(changelog_path): |
| 72 | + except Exception: |
| 73 | + log.warning("Parse error reading {}".format(changelog_path), exc_info=1) |
78 | 74 | return None
|
79 |
| - changelog_list = None |
80 |
| - for encoding_name in ('utf_8', 'utf_16'): |
81 |
| - try: |
82 |
| - with codecs.open(changelog_path, 'r', encoding=encoding_name) as changelog_file: |
83 |
| - # Generate match object with fields from all matching lines |
84 |
| - matches = re.findall( |
85 |
| - r"^-\s?([0-9a-f]{40})\s(\d{4,4}-\d{2,2}-\d{2,2})\s(.*)\s\[(.*)\]\s*$", |
86 |
| - changelog_file.read(), re.MULTILINE) |
87 |
| - log.debug("Parsed {} changelog lines from {}".format(len(matches), changelog_path)) |
88 |
| - changelog_list = [{ |
89 |
| - "hash": entry[0], |
90 |
| - "date": entry[1], |
91 |
| - "subject": entry[2], |
92 |
| - "author": entry[3], |
93 |
| - } for entry in matches] |
94 |
| - except UnicodeError: |
95 |
| - log.debug('Failed to parse log file %s with encoding %s' % (changelog_path, encoding_name)) |
96 |
| - continue |
97 |
| - except Exception: |
98 |
| - log.warning("Parse error reading {}".format(changelog_path), exc_info=1) |
99 |
| - return None |
| 75 | + log.debug("Parsed {} changelog lines from {}".format(len(changelog_list), changelog_path)) |
100 | 76 | return changelog_list
|
101 | 77 |
|
102 | 78 |
|
@@ -409,17 +385,12 @@ def __init__(self):
|
409 | 385 |
|
410 | 386 | # Read changelog file for each project
|
411 | 387 | for project in ['openshot-qt', 'libopenshot', 'libopenshot-audio']:
|
412 |
| - new_changelog_path = os.path.join(info.PATH, 'resources', '{}.log'.format(project)) |
413 |
| - old_changelog_path = os.path.join(info.PATH, 'settings', '{}.log'.format(project)) |
414 |
| - if os.path.exists(new_changelog_path): |
415 |
| - log.debug("Reading changelog file: {}".format(new_changelog_path)) |
416 |
| - changelog_list = parse_new_changelog(new_changelog_path) |
417 |
| - elif os.path.isfile(old_changelog_path): |
418 |
| - log.debug("Reading legacy changelog file: {}".format(old_changelog_path)) |
419 |
| - changelog_list = parse_changelog(old_changelog_path) |
| 388 | + changelog_path = os.path.join(info.PATH, 'settings', '{}.log'.format(project)) |
| 389 | + if os.path.exists(changelog_path): |
| 390 | + log.debug("Reading changelog file: {}".format(changelog_path)) |
| 391 | + changelog_list = parse_changelog(changelog_path) |
420 | 392 | else:
|
421 | 393 | changelog_list = None
|
422 |
| - # Hopefully we found ONE of the two |
423 | 394 | if changelog_list is None:
|
424 | 395 | log.warn("Could not load changelog for {}".format(project))
|
425 | 396 | # Hide the tab for this changelog
|
|
0 commit comments