summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-05-22 20:23:02 +0200
committerZbigniew Jędrzejewski-Szmek <zbyszek@in.waw.pl>2021-05-22 20:44:04 +0200
commit82ca34e6e6e2f779f7a6ee8da67cb8f81e0fc2a5 (patch)
tree2e7c72afc36b52acbdf80183900816c4505dca9c
parentman/check-os-release.py: strip trailing whitespace (diff)
downloadsystemd-82ca34e6e6e2f779f7a6ee8da67cb8f81e0fc2a5.tar.xz
systemd-82ca34e6e6e2f779f7a6ee8da67cb8f81e0fc2a5.zip
man/check-os-release.py: ignore comment and empty lines
Plus fix off-by-one in error printing.
-rw-r--r--man/check-os-release.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/man/check-os-release.py b/man/check-os-release.py
index 069ca74b20..2440202349 100644
--- a/man/check-os-release.py
+++ b/man/check-os-release.py
@@ -2,21 +2,28 @@
import ast
import re
+import sys
def read_os_release():
try:
- f = open('/etc/os-release')
+ filename = '/etc/os-release'
+ f = open(filename)
except FileNotFoundError:
- f = open('/usr/lib/os-release')
+ filename = '/usr/lib/os-release'
+ f = open(filename)
for line_number, line in enumerate(f):
- if m := re.match(r'([A-Z][A-Z_0-9]+)=(.*?)\s*$', line):
+ line = line.rstrip()
+ if not line or line.startswith('#'):
+ continue
+ if m := re.match(r'([A-Z][A-Z_0-9]+)=(.*)', line):
name, val = m.groups()
if val and val[0] in '"\'':
val = ast.literal_eval(val)
yield name, val
else:
- print(f'Warning: bad line {line_number}: {line}', file=sys.stderr)
+ print(f'{filename}:{line_number + 1}: bad line {line!r}',
+ file=sys.stderr)
os_release = dict(read_os_release())