summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorFernando <fernando@endlessm.com>2013-12-06 13:50:13 -0800
committerFernando <fernando@endlessm.com>2013-12-10 13:37:36 -0800
commit9e51e0059b4413ce54ad04eb81c54185dae84bab (patch)
treeb48255ae224f20fa1706cc8a7f1603645d3e1430
parentc26763c821ff2b2c74f6529081b15b73fa4a5f86 (diff)
Integrated JSON extraction utility
The utility used in eos-english and eos-programming-app was integrated and installed as part of the SDK CR comments addressed include: - Integrated new facilities available on GTK - Removed duplicate prototype declaration - Reformatted CLEANFILES var declaration - Used configure.ac to get @PACKAGE_VERSION@ - Added version() and usage() utilities [endlessm/eos-sdk#335]
-rw-r--r--.gitignore1
-rw-r--r--configure.ac1
-rw-r--r--tools/Makefile.am.inc14
-rw-r--r--tools/eos-json-extractor/eos-json-extractor.in64
4 files changed, 77 insertions, 3 deletions
diff --git a/.gitignore b/.gitignore
index 034c97c..c86f245 100644
--- a/.gitignore
+++ b/.gitignore
@@ -11,6 +11,7 @@ data/eos-wikipedia-domain.gresource
wikipedia/config.js
tools/eos-run-test
tools/eos-application-manifest/eos-application-manifest
+tools/eos-json-extractor/eos-json-extractor
*.py[cod]
diff --git a/configure.ac b/configure.ac
index 0458a57..4f5ad3f 100644
--- a/configure.ac
+++ b/configure.ac
@@ -223,6 +223,7 @@ AC_CONFIG_FILES([
docs/reference/endless/Makefile
docs/reference/endless/version.xml
$EOS_SDK_API_NAME.pc
+ tools/eos-json-extractor/eos-json-extractor
])
AC_CONFIG_FILES([tools/eos-run-test], [chmod +x tools/eos-run-test])
AC_CONFIG_HEADERS([config.h]) dnl Header with system-dependent #defines
diff --git a/tools/Makefile.am.inc b/tools/Makefile.am.inc
index ab668df..47744b2 100644
--- a/tools/Makefile.am.inc
+++ b/tools/Makefile.am.inc
@@ -2,7 +2,8 @@
bin_SCRIPTS = \
tools/eos-run-test \
- tools/eos-application-manifest/eos-application-manifest
+ tools/eos-application-manifest/eos-application-manifest \
+ tools/eos-json-extractor/eos-json-extractor \
$(NULL)
# Use the following script to replace $datadir inside the script, as suggested
@@ -13,6 +14,7 @@ tools_edit = sed \
-e 's|@libexecdir[@]|$(libexecdir)|g' \
-e 's|@PACKAGE_VERSION[@]|$(PACKAGE_VERSION)|g' \
$(NULL)
+
tools/eos-application-manifest/eos-application-manifest: tools/eos-application-manifest/eos-application-manifest.in Makefile
$(AM_V_GEN)$(MKDIR_P) tools/eos-application-manifest && \
rm -f $@ $@.tmp && \
@@ -21,8 +23,14 @@ tools/eos-application-manifest/eos-application-manifest: tools/eos-application-m
chmod a-w $@.tmp && \
mv $@.tmp $@
-CLEANFILES += tools/eos-application-manifest/eos-application-manifest
-EXTRA_DIST += tools/eos-application-manifest/eos-application-manifest.in
+CLEANFILES += \
+ tools/eos-application-manifest/eos-application-manifest \
+ tools/eos-json-extractor/eos-json-extractor \
+ $(NULL)
+EXTRA_DIST += \
+ tools/eos-application-manifest/eos-application-manifest.in \
+ tools/eos-json-extractor/eos-json-extractor.in \
+ $(NULL)
commandsdir = $(libexecdir)/eos-application-manifest/commands
dist_commands_DATA = \
diff --git a/tools/eos-json-extractor/eos-json-extractor.in b/tools/eos-json-extractor/eos-json-extractor.in
new file mode 100644
index 0000000..28c5e8e
--- /dev/null
+++ b/tools/eos-json-extractor/eos-json-extractor.in
@@ -0,0 +1,64 @@
+#!/usr/bin/gjs
+// Copyright 2013 Endless Mobile, Inc.
+
+const Format = imports.format;
+const System = imports.system;
+
+const Gio = imports.gi.Gio;
+const Json = imports.gi.Json;
+
+String.prototype.format = Format.format;
+
+// Other constants, available from subcommands' code
+const programVersion = "@PACKAGE_VERSION@";
+
+/**
+ * usage:
+ *
+ * Print command-line help message.
+ */
+function usage() {
+ print('Extracts translatable strings fron JSON configuration file.\n');
+ print('Usage: %s [Options | <INPUT-FILE> <TOP-SRCDIR>]\n'.format(
+ System.programInvocationName));
+ print('Options:');
+ print(' --help Print this help message');
+ print(' --version Print version and exit');
+ System.exit(0);
+}
+
+/**
+ * version:
+ *
+ * Print command-line version output.
+ */
+function version() {
+ print('%s %s - Discover unit tests in a source tree'.format(
+ System.programInvocationName, programVersion));
+ System.exit(0);
+}
+
+if(ARGV.indexOf('--version') != -1)
+ version();
+if((ARGV.indexOf('--help') != -1) || (ARGV.length != 2)) {
+ usage();
+}
+
+try {
+ let parser = new Json.Parser();
+ let input_file = Gio.File.new_for_path(ARGV[0]);
+ let top_srcdir = Gio.File.new_for_path(ARGV[1]);
+ let full_path = top_srcdir.get_relative_path(input_file);
+
+ parser.connect('object-member', function(parser, object, member_name) {
+ if(!member_name.endsWith('_'))
+ return;
+ print('#line %d "%s"'.format(parser.get_current_line(), full_path));
+ print('_("%s");'.format(object.get_string_member(member_name)));
+ });
+ parser.load_from_file(input_file.get_path());
+
+} catch (e) {
+ printerr('%s: %s'.format(System.programInvocationName, e.message));
+ System.exit(1);
+}