Skip to content

Commit c53853b

Browse files
authored
Merge pull request #5011 from OpenShot/fix-changelog-parsing
Fix changelog parsing (simplify regex, code cleanup)
2 parents 1862ede + 0ad1d5a commit c53853b

File tree

3 files changed

+28
-53
lines changed

3 files changed

+28
-53
lines changed

.gitlab-ci.yml

+4
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,8 @@ windows-builder-x64:
8888
- build\install-x64\share\*.log
8989
- build\build-server.log
9090
script:
91+
- $PSVersionTable
92+
- $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
9193
- try { Invoke-WebRequest -Uri "http://gitlab.openshot.org/OpenShot/libopenshot/-/jobs/artifacts/$CI_COMMIT_REF_NAME/download?job=windows-builder-x64" -Headers @{"PRIVATE-TOKEN"="$ACCESS_TOKEN"} -OutFile "artifacts.zip" } catch { $_.Exception.Response.StatusCode.Value__ }
9294
- if (-not (Test-Path "artifacts.zip")) { Invoke-WebRequest -Uri "http://gitlab.openshot.org/OpenShot/libopenshot/-/jobs/artifacts/develop/download?job=windows-builder-x64" -Headers @{"PRIVATE-TOKEN"="$ACCESS_TOKEN"} -OutFile "artifacts.zip" }
9395
- Expand-Archive -Path artifacts.zip -DestinationPath .
@@ -123,6 +125,8 @@ windows-builder-x86:
123125
- build\install-x86\share\*.log
124126
- build\build-server.log
125127
script:
128+
- $PSVersionTable
129+
- $PSDefaultParameterValues['Out-File:Encoding'] = 'utf8'
126130
- try { Invoke-WebRequest -Uri "http://gitlab.openshot.org/OpenShot/libopenshot/-/jobs/artifacts/$CI_COMMIT_REF_NAME/download?job=windows-builder-x86" -Headers @{"PRIVATE-TOKEN"="$ACCESS_TOKEN"} -OutFile "artifacts.zip" } catch { $_.Exception.Response.StatusCode.Value__ }
127131
- if (-not (Test-Path "artifacts.zip")) { Invoke-WebRequest -Uri "http://gitlab.openshot.org/OpenShot/libopenshot/-/jobs/artifacts/develop/download?job=windows-builder-x86" -Headers @{"PRIVATE-TOKEN"="$ACCESS_TOKEN"} -OutFile "artifacts.zip" }
128132
- Expand-Archive -Path artifacts.zip -DestinationPath .

src/windows/about.py

+23-52
Original file line numberDiff line numberDiff line change
@@ -49,54 +49,30 @@
4949

5050

5151
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."""
5453
if not os.path.exists(changelog_path):
5554
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:
6366
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(),
6871
})
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)
7874
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))
10076
return changelog_list
10177

10278

@@ -409,17 +385,12 @@ def __init__(self):
409385

410386
# Read changelog file for each project
411387
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)
420392
else:
421393
changelog_list = None
422-
# Hopefully we found ONE of the two
423394
if changelog_list is None:
424395
log.warn("Could not load changelog for {}".format(project))
425396
# Hide the tab for this changelog

src/windows/views/zoom_slider.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -150,7 +150,7 @@ def paintEvent(self, event, *args):
150150

151151
# Get FPS info
152152
fps_num = get_app().project.get("fps").get("num", 24)
153-
fps_den = get_app().project.get("fps").get("den", 1)
153+
fps_den = get_app().project.get("fps").get("den", 1) or 1
154154
fps_float = float(fps_num / fps_den)
155155

156156
# Determine scale factor

0 commit comments

Comments
 (0)