summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMattias Andrée <maandree@operamail.com>2014-03-19 03:32:37 +0100
committerMattias Andrée <maandree@operamail.com>2014-03-19 03:32:37 +0100
commitbddb70af344aad17d3579d59a613a403842e6ccb (patch)
treea87adb4ef314fd7ace9bf0f8c06d99989fe068c1
parentbump version (diff)
downloadblueshift-bddb70af344aad17d3579d59a613a403842e6ccb.tar.gz
blueshift-bddb70af344aad17d3579d59a613a403842e6ccb.tar.bz2
blueshift-bddb70af344aad17d3579d59a613a403842e6ccb.tar.xz
add modes example
Signed-off-by: Mattias Andrée <maandree@operamail.com>
-rw-r--r--Makefile2
-rw-r--r--TODO1
-rw-r--r--examples/modes63
3 files changed, 64 insertions, 2 deletions
diff --git a/Makefile b/Makefile
index e6a3d43..3d308eb 100644
--- a/Makefile
+++ b/Makefile
@@ -68,7 +68,7 @@ CBINDINGS = $(foreach B,$(SERVER_BINDINGS),blueshift_$(B).so)
# Configuration script example files
EXAMPLES = comprehensive sleepmode crtc-detection crtc-searching logarithmic \
xmobar xpybar stored-settings current-settings xmonad threaded \
- backlight darkroom textconf textconf.conf
+ backlight darkroom textconf textconf.conf modes
# Build rules
diff --git a/TODO b/TODO
index e7e82be..52c03c8 100644
--- a/TODO
+++ b/TODO
@@ -6,7 +6,6 @@ Medium priority:
Test, demo and document _ICC_PROFILE
Add functions to store and restore curves so that we do not need
to recalculate all filters before withs that are output specific.
- Make an example that loads a configuration script from a directory
Make it possible to have settings depend on sky condicitions.
(I have a GPL3 implmenetion of wheter observation in xpybar.)
diff --git a/examples/modes b/examples/modes
new file mode 100644
index 0000000..8cac965
--- /dev/null
+++ b/examples/modes
@@ -0,0 +1,63 @@
+# -*- python -*-
+
+# This example can be used to name a mode you want to use,
+# and load the script, without having the use Blueshift's -c
+# option and give a pathname. You will only need to give a
+# filename. In this example, those modes are installed in
+# the directory `$XDG_CONFIG_HOME/blueshift-modes`, and the
+# default mode is named `default`.
+
+
+# Copyright © 2014 Mattias Andrée (maandree@member.fsf.org)
+#
+# This program is free software: you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation, either version 3 of the License, or
+# (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program. If not, see <http://www.gnu.org/licenses/>.
+
+import os
+
+
+# Name of default mode.
+mode = 'default'
+
+# Directory of mode scripts.
+modedir = '%s/blueshift-modes'
+modedir_ = os.environ['XDG_CONFIG_HOME'] if 'XDG_CONFIG_HOME' in os.environ else None
+if modedir_ is None:
+ home = os.environ['HOME'] if 'HOME' in os.environ else None
+ if home is None:
+ import pwd
+ home = pwd.getpwuid(os.getuid()).pw_dir
+ modedir_ = '%s/.config' % home
+modedir = (modedir % modedir_) + '/'
+
+# Get selected mode.
+if 'mode' in conf_storage:
+ mode = conf_storage['mode']
+else:
+ conf_opts[:] = conf_opts[1:]
+ if len(conf_opts) > 0:
+ if not (conf_opts[0].startswith('-') or conf_opts[0].startswith('+')):
+ mode = conf_opts[0]
+ conf_opts[:] = conf_opts[1:]
+ conf_storage['mode'] = mode
+ conf_opts[:0] = [mode]
+
+# Exec mode script.
+mode_file = modedir + mode
+code = None
+with open(mode_file, 'rb') as script:
+ code = script.read()
+code = code.decode('utf-8', 'error') + '\n'
+code = compile(code, mode_file, 'exec')
+exec(code, globals())
+