summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLars Wirzenius <liw@liw.fi>2012-04-06 23:58:42 +0100
committerLars Wirzenius <liw@liw.fi>2012-04-06 23:58:42 +0100
commitcf1b517f26f291253ec402aa3bb9f9ac7089db4e (patch)
tree63be89aa55b7325b1e59bd18f5e886005bea3848
parent0bf075b90d332d727d589d14f4f2bd148f6fabb2 (diff)
downloadliw-automation-cf1b517f26f291253ec402aa3bb9f9ac7089db4e.tar.gz
Add a couple of scripts
-rw-r--r--scripts/auto-disp63
-rw-r--r--scripts/sync-gtd9
2 files changed, 72 insertions, 0 deletions
diff --git a/scripts/auto-disp b/scripts/auto-disp
new file mode 100644
index 0000000..6e43a6f
--- /dev/null
+++ b/scripts/auto-disp
@@ -0,0 +1,63 @@
+#!/usr/bin/python
+
+
+import re
+
+import cliapp
+
+
+class AutoDisp(cliapp.Application):
+
+ lid = 'LVDS1'
+ externals = ['VGA1', 'HDMI1', 'DVI1', 'DP1']
+
+ def process_args(self, args):
+ out = self.runcmd(['xrandr', '-q'])
+ outputs = self.parse_outputs(out)
+
+ got_internal = self.got_output(self.lid, outputs)
+ got_externals = [x
+ for x in self.externals
+ if self.got_output(x, outputs)]
+
+ argv = ['xrandr']
+ if got_externals:
+ res, name = max((outputs[x], x) for x in got_externals)
+ argv += ['--output', name, '--mode', '%dx%d' % res]
+ if got_internal:
+ argv += ['--output', self.lid, '--off']
+ elif got_internal:
+ argv += ['--output', self.lid,
+ '--mode', '%dx%d' % outputs[self.lid]]
+ else:
+ raise cliapp.AppException('Oops, don\'t know what to do')
+
+ self.runcmd(argv)
+
+ def got_output(self, name, outputs):
+ return name in outputs
+
+ def parse_outputs(self, xrandr):
+ output = re.compile(r'^(?P<output>[A-Z0-9]+) connected ')
+ mode = re.compile(r'^ (?P<x>\d+)x(?P<y>\d+) ')
+
+ result = {}
+ current = None
+
+ lines = xrandr.splitlines()
+ for line in lines:
+ words = line.split()
+ output_match = output.match(line)
+ mode_match = mode.match(line)
+ if output_match:
+ current = output_match.group('output')
+ elif mode_match:
+ assert current is not None
+ x = int(mode_match.group('x'))
+ y = int(mode_match.group('y'))
+ prev = result.get(current, (0,0))
+ result[current] = max((x,y), prev)
+
+ return result
+
+AutoDisp().run()
diff --git a/scripts/sync-gtd b/scripts/sync-gtd
new file mode 100644
index 0000000..9bdcab0
--- /dev/null
+++ b/scripts/sync-gtd
@@ -0,0 +1,9 @@
+#!/bin/sh
+
+set -e
+
+cd $HOME/GTD
+if bzr status | grep . > /dev/null
+then
+ bzr commit -m sync --quiet
+fi