summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBastien Nocera <hadess@hadess.net>2019-07-16 14:42:43 +0200
committerBastien Nocera <hadess@hadess.net>2019-07-16 14:59:36 +0200
commit1c21f1d75bca39a2c9a7567e25c21b0bc08311b9 (patch)
tree8faf7a93184a5f01bdb0f25d72324dd33e65eb67
parentb682fa3286595ce8c75842a4958498f30398b36f (diff)
downloadgrilo-1c21f1d75bca39a2c9a7567e25c21b0bc08311b9.tar.gz
grl-inspect: Fix core keys extraction
This fixes incorrectly duplicated keys in grl-core-keys.h which affected the output of metadata in grl-inspect by removing the C comments prior to processing the file. Before: $ sort grl-core-keys.h | uniq --repeated "GRL_METADATA_KEY_MB_RELEASE_GROUP_ID", After: $ sort grl-core-keys.h | uniq --repeated $
-rw-r--r--tools/grilo-inspect/generate_core_keys.py24
1 files changed, 20 insertions, 4 deletions
diff --git a/tools/grilo-inspect/generate_core_keys.py b/tools/grilo-inspect/generate_core_keys.py
index 1c28473..ddd2f3a 100644
--- a/tools/grilo-inspect/generate_core_keys.py
+++ b/tools/grilo-inspect/generate_core_keys.py
@@ -11,20 +11,37 @@
import re
import sys
+# From https://stackoverflow.com/a/241506
+def comment_remover(text):
+ def replacer(match):
+ s = match.group(0)
+ if s.startswith('/'):
+ return " " # note: a space and not an empty string
+ else:
+ return s
+ pattern = re.compile(
+ r'//.*?$|/\*.*?\*/|\'(?:\\.|[^\\\'])*\'|"(?:\\.|[^\\"])*"',
+ re.DOTALL | re.MULTILINE
+ )
+ return re.sub(pattern, replacer, text)
+
if len(sys.argv) != 3:
print("Usage: " + sys.argv[0] + " <input> <output>")
exit(1)
finput = open(sys.argv[1], "r")
+input_data = finput.read()
+input_data = comment_remover(input_data).split('\n')
+finput.close()
foutput = open(sys.argv[2], "w")
foutput.write("gchar *grl_core_keys[] = {\n")
output_keys = False
-for line in finput:
- if re.search("BEGIN CORE KEYS", line):
+for line in input_data:
+ if re.search("GRL_METADATA_KEY_ALBUM", line):
output_keys = True
- if re.search("END CORE KEYS", line):
+ if re.search("G_BEGIN_DECLS", line):
output_keys = False
m = re.search("GRL_METADATA_KEY_[^ ]+", line)
if output_keys and m:
@@ -32,5 +49,4 @@ for line in finput:
foutput.write("};");
-finput.close()
foutput.close()