[gnome-settings-daemon] power: Add tools to generate Python constants
- From: Bastien Nocera <hadess src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-settings-daemon] power: Add tools to generate Python constants
- Date: Mon, 21 Jan 2013 08:23:31 +0000 (UTC)
commit d0d8a8bfb6816fc5adddb1fe1bd8b57db0cc2ce4
Author: Bastien Nocera <hadess hadess net>
Date: Mon Jan 21 09:09:33 2013 +0100
power: Add tools to generate Python constants
Add gsd-power-constants.py and gsd-power-enums.py for use
in the test suite, to avoid magic numbers being used.
configure.ac | 1 +
plugins/power/Makefile.am | 39 +++++++++++++++++++++-
plugins/power/gsd-power-constants-update.pl | 46 +++++++++++++++++++++++++++
plugins/power/gsd-power-enums-update.c | 38 ++++++++++++++++++++++
plugins/power/gsdpowerconstants.py | 12 +++++++
plugins/power/gsdpowerenums.py | 9 +++++
6 files changed, 143 insertions(+), 2 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index 82373e4..d33ace0 100644
--- a/configure.ac
+++ b/configure.ac
@@ -84,6 +84,7 @@ esac
AC_SUBST([GSD_PLUGIN_LDFLAGS])
AC_PATH_PROG(GLIB_GENMARSHAL, glib-genmarshal)
+AC_PATH_PROG([GLIB_MKENUMS],[glib-mkenums])
dnl ================================================================
dnl GSettings stuff
diff --git a/plugins/power/Makefile.am b/plugins/power/Makefile.am
index fe8cc04..23673c5 100644
--- a/plugins/power/Makefile.am
+++ b/plugins/power/Makefile.am
@@ -95,9 +95,44 @@ EXTRA_DIST += \
org.gnome.settings-daemon.plugins.power.policy.in.in
endif
-check-local: $(top_builddir)/tests/shiftkey gsd-test-power
+# Enums
+GSD_POWER_ENUM_FILES = gsd-power-enums.c gsd-power-enums.h
+
+gsd-power-enums.h: gsm-inhibitor-flag.h gsm-presence-flag.h Makefile
+ $(AM_V_GEN)($(GLIB_MKENUMS) \
+ --fhead "#ifndef GSD_POWER_ENUMS_H\n#define GSD_POWER_ENUMS_H\n\n#include <glib-object.h>\n\nG_BEGIN_DECLS\n" \
+ --fprod "/* enumerations from \"@filename \" */\n" \
+ --vhead "GType @enum_name _get_type (void) G_GNUC_CONST;\n#define GSD_POWER_TYPE_ ENUMSHORT@ (@enum_name _get_type())\n" \
+ --ftail "G_END_DECLS\n\n#endif /* !GSD_POWER_ENUMS_H */" $(srcdir)/gsm-inhibitor-flag.h $(srcdir)/gsm-presence-flag.h > $@)
+
+gsd-power-enums.c: gsd-power-constants.h gsm-inhibitor-flag.h gsm-presence-flag.h Makefile gsd-power-enums.h
+ $(AM_V_GEN)($(GLIB_MKENUMS) \
+ --fhead "#include \"gsm-inhibitor-flag.h\"\n#include \"gsm-presence-flag.h\"\n#include \"gsd-power-enums.h\"" \
+ --fprod "\n/* enumerations from \"@filename \" */" \
+ --vhead "GType\n enum_name@_get_type (void)\n{\n static GType etype = 0;\n if (etype == 0) {\n static const G Type@Value values[] = {" \
+ --vprod " { @VALUENAME@, \"@VALUENAME \", \"@valuenick \" }," \
+ --vtail " { 0, NULL, NULL }\n };\n etype = g_ type@_register_static (\"@EnumName \", values);\n }\n return etype;\n}\n" \
+ $(srcdir)/gsm-inhibitor-flag.h $(srcdir)/gsm-presence-flag.h > $@)
+
+gsdpowerconstants.py: gsd-power-constants-update.pl gsd-power-constants.h
+ $(AM_V_GEN) $(srcdir)/gsd-power-constants-update.pl
+
+gsdpowerenums.py: gsd-power-enums-update gsd-power-enums.h gsd-power-enums.c
+ $(AM_V_GEN) $(srcdir)/gsd-power-enums-update > $@
+
+noinst_PROGRAMS = gsd-power-enums-update
+gsd_power_enums_update_SOURCES = \
+ gsd-power-enums-update.c \
+ gsd-power-enums.h \
+ gsd-power-enums.c
+gsd_power_enums_update_CFLAGS = $(libpower_la_CFLAGS)
+gsd_power_enums_update_LDFLAGS = $(POWER_LIBS)
+
+EXTRA_DIST += gsdpowerconstants.py gsdpowerenums.py
+
+check-local: $(top_builddir)/tests/shiftkey gsd-test-power test.py gsdpowerconstants.py gsdpowerenums.py
BUILDDIR=$(builddir) TOP_BUILDDIR=$(top_builddir) ${PYTHON} $(srcdir)/test.py
-
+
clean-local:
rm -f *~
diff --git a/plugins/power/gsd-power-constants-update.pl b/plugins/power/gsd-power-constants-update.pl
new file mode 100755
index 0000000..cd7bb1a
--- /dev/null
+++ b/plugins/power/gsd-power-constants-update.pl
@@ -0,0 +1,46 @@
+#!/usr/bin/env perl
+
+# Author : Simos Xenitellis <simos at gnome dot org>.
+# Author : Bastien Nocera <hadess hadess net>
+# Version : 1.2
+#
+# Input : gsd-power-constants.h
+# Output : gsdpowerconstants.py
+#
+use strict;
+
+# Used for reading the keysymdef symbols.
+my @constantselements;
+
+die "Could not open file gsd-power-constants.h: $!\n" unless open(IN_CONSTANTS, "<:utf8", "gsd-power-constants.h");
+
+# Output: gtk+/gdk/gdkkeysyms.h
+die "Could not open file gsdpowerconstants.py: $!\n" unless open(OUT_CONSTANTS, ">:utf8", "gsdpowerconstants.py");
+
+print OUT_CONSTANTS<<EOF;
+
+# File auto-generated from script http://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-constants-update.pl
+
+# Modified by the GTK+ Team and others 1997-2012. See the AUTHORS
+# file for a list of people on the GTK+ Team. See the ChangeLog
+# files for a list of changes. These files are distributed with
+# GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+
+EOF
+
+while (<IN_CONSTANTS>)
+{
+ next if ( ! /^#define / );
+
+ @constantselements = split(/\s+/);
+ die "Internal error, no \ constantselements: $_\n" unless @constantselements;
+
+ my $constant = $constantselements[1];
+ my $value = $constantselements[2];
+
+ printf OUT_CONSTANTS "%s = %s;\n", $constant, $value;
+}
+
+close IN_CONSTANTS;
+
+printf "We just finished converting gsd-power-constants.h to gsdpowerconstants.py\nThank you\n";
diff --git a/plugins/power/gsd-power-enums-update.c b/plugins/power/gsd-power-enums-update.c
new file mode 100644
index 0000000..bdc4e05
--- /dev/null
+++ b/plugins/power/gsd-power-enums-update.c
@@ -0,0 +1,38 @@
+#include <glib-object.h>
+#include <gsd-power-enums.h>
+
+static void
+output_enum_values (GType class_type)
+{
+ GEnumClass *eclass;
+ guint i;
+
+ eclass = G_ENUM_CLASS (g_type_class_peek (class_type));
+ for (i = 0; i < eclass->n_values; i++) {
+ GEnumValue *value = &(eclass->values[i]);
+ g_print ("%s = %d;\n", value->value_name, value->value);
+ }
+}
+
+static void
+output_flags_values (GType class_type)
+{
+ GFlagsClass *fclass;
+ guint i;
+
+ fclass = G_FLAGS_CLASS (g_type_class_peek (class_type));
+ for (i = 0; i < fclass->n_values; i++) {
+ GFlagsValue *value = &(fclass->values[i]);
+ g_print ("%s = %d;\n", value->value_name, value->value);
+ }
+}
+
+int
+main (int argc, char **argv)
+{
+ g_type_class_ref (GSD_POWER_TYPE_INHIBITOR_FLAG);
+ g_type_class_ref (GSD_POWER_TYPE_PRESENCE_STATUS);
+ output_flags_values (GSD_POWER_TYPE_INHIBITOR_FLAG);
+ output_enum_values (GSD_POWER_TYPE_PRESENCE_STATUS);
+ return 0;
+}
diff --git a/plugins/power/gsdpowerconstants.py b/plugins/power/gsdpowerconstants.py
new file mode 100644
index 0000000..c1f54f8
--- /dev/null
+++ b/plugins/power/gsdpowerconstants.py
@@ -0,0 +1,12 @@
+
+# File auto-generated from script http://git.gnome.org/browse/gnome-settings-daemon/tree/plugins/power/gsd-power-constants-update.pl
+
+# Modified by the GTK+ Team and others 1997-2012. See the AUTHORS
+# file for a list of people on the GTK+ Team. See the ChangeLog
+# files for a list of changes. These files are distributed with
+# GTK+ at ftp://ftp.gtk.org/pub/gtk/.
+
+SCREENSAVER_TIMEOUT_BLANK = 20;
+IDLE_DIM_BLANK_DISABLED_MIN = 60;
+IDLE_DELAY_TO_IDLE_DIM_FRACTION = 3;
+MINIMUM_IDLE_DIM_DELAY = 10;
diff --git a/plugins/power/gsdpowerenums.py b/plugins/power/gsdpowerenums.py
new file mode 100644
index 0000000..d3d9c21
--- /dev/null
+++ b/plugins/power/gsdpowerenums.py
@@ -0,0 +1,9 @@
+GSM_INHIBITOR_FLAG_LOGOUT = 1;
+GSM_INHIBITOR_FLAG_SWITCH_USER = 2;
+GSM_INHIBITOR_FLAG_SUSPEND = 4;
+GSM_INHIBITOR_FLAG_IDLE = 8;
+GSM_INHIBITOR_FLAG_AUTOMOUNT = 16;
+GSM_PRESENCE_STATUS_AVAILABLE = 0;
+GSM_PRESENCE_STATUS_INVISIBLE = 1;
+GSM_PRESENCE_STATUS_BUSY = 2;
+GSM_PRESENCE_STATUS_IDLE = 3;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]