Revert "Remove ununsed scripts"
authorJulien Valroff <julien@kirya.net>
Sat, 13 Aug 2011 10:53:42 +0000 (12:53 +0200)
committerJulien Valroff <julien@kirya.net>
Sat, 13 Aug 2011 10:53:42 +0000 (12:53 +0200)
This reverts commit ecd4726a42b2bb4a7df1006788896e34b4ede5a6.

SessionManager.py [new file with mode: 0755]
create_x_infos.sh [new file with mode: 0755]
gmail-abook-contact-converter.py [new file with mode: 0755]
start-daemon.sh [new file with mode: 0755]

diff --git a/SessionManager.py b/SessionManager.py
new file mode 100755 (executable)
index 0000000..6033b07
--- /dev/null
@@ -0,0 +1,197 @@
+#!/usr/bin/python
+"""
+SessionManager
+Copyright (c) 2010--2011, Olivier Mehani <shtrom@ssji.net>
+All rights reserved.
+
+Original source: https://scm.narf.ssji.net/svn/shtrom/browser/default-env/bin/SessionManager.py
+Code documented at http://www.narf.ssji.net/~shtrom/wiki/projets/gnomescreensavernosession
+
+Local changes by Julien Valroff <julien@kirya.net>
+  2011-05:
+    * Use standard python path
+    * Drop GPG-related code
+    * Make the script usable with Debian
+
+$Id$
+A drop-in replacement for org.gnome.SessionManager, doing almost nothing.
+Loosely based on basic instructions at [0,1,2,3,5,6].
+
+[0] http://people.gnome.org/~mccann/gnome-session/docs/gnome-session.html
+[1] http://www.amk.ca/diary/2007/04/rough_notes_python_and_dbus.html
+[2] http://paste.lisp.org/display/45824
+[3] http://www.lamalex.net/2010/03/help-does-anyone-know-how-to-export-properties-with-python-dbus/
+[4] http://thp.io/2007/09/x11-idle-time-and-focused-window-in.html
+[5] http://www.eurion.net/python-snippets/snippet/GConf%3A%20get_set%20values.html
+[6] http://lists.gnupg.org/pipermail/gnupg-users/2006-March/028189.html
+
+Redistribution and use in source and binary forms, with or without
+modification, are permitted provided that the following conditions
+are met:
+1. Redistributions of source code must retain the above copyright notice, this
+list of conditions and the following disclaimer.
+2. Redistributions in binary form must reproduce the above copyright notice,
+this list of conditions and the following disclaimer in the documentation
+and/or other materials provided with the distribution.
+3. Neither the name of Olivier Mehani nor the names of its contributors
+may be used to endorse or promote products derived from this software
+without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
+AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
+ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE
+LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
+CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
+SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
+INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
+CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
+ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
+POSSIBILITY OF SUCH DAMAGE.
+
+"""
+
+__version__ = "$Revision$"
+
+
+import dbus
+import dbus.service
+import dbus.glib
+import gobject
+
+import gtk
+
+import ctypes
+import os
+
+import gconf
+
+import signal
+
+
+ogSM   = 'org.gnome.SessionManager'
+ogSMp  = '/org/gnome/SessionManager'
+ogSMP  = 'org.gnome.SessionManager.Presence'
+ogSMPp = '/org/gnome/SessionManager/Presence'
+
+class SessionManager(dbus.service.Object):
+    def __init__(self):
+        bus_name = dbus.service.BusName(ogSM,
+            bus=dbus.SessionBus())
+        dbus.service.Object.__init__(self, bus_name,
+            ogSMp)
+        self.presence = SessionManagerPresence()
+        #print "%s emulation ready" % ogSM
+
+    def get_smp(self):
+        return self.presence
+
+
+class SessionManagerPresence(dbus.service.Object):
+    PRESENCE_AVAILABLE  = 0
+    PRESENCE_INVISIBLE  = 1
+    PRESENCE_BUSY              = 2
+    PRESENCE_IDLE              = 3
+    
+    status                     = PRESENCE_AVAILABLE
+    status_text                = ""
+
+    def __init__(self):
+        bus_name = dbus.service.BusName(ogSMP,
+            bus=dbus.SessionBus())
+        dbus.service.Object.__init__(self, bus_name,
+            ogSMPp)
+        #print "%s emulation ready" % ogSMP
+
+    @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
+        in_signature='s', out_signature='a{sv}')
+    def GetAll(self, interface_name):
+        #print "%s.GetAll(%s)" % (ogSMP, interface_name)
+        return {'status':              dbus.UInt32(self.status),
+            'status-text':  self.status_text,
+            }
+    @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
+        in_signature='ss', out_signature='v')
+    def Get(self, interface_name, property_name):
+        #print "%s.Get(%s, %s)" % (ogSMP, interface_name, property_name)
+        #print " -> %s" % str(self.GetAll(interface_name)[property_name])
+        return self.GetAll(interface_name)[property_name]
+    @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE,
+        in_signature='ssv')
+    def Set(self, interface_name, property_name, value):
+        #print "%s.Set(%s, %s, %s)" % \
+        #      (ogSMP, interface_name, property_name, value)
+        pass
+
+    @dbus.service.method(dbus_interface=ogSMP, in_signature='u')
+    def SetStatus(self, status):
+        self.status = status
+
+    @dbus.service.method(dbus_interface=ogSMP, in_signature='u')
+    def SetStatusText(self, status_text):
+        self.status_text = status_text
+
+    @dbus.service.signal(dbus_interface=ogSMP, signature='u')
+    def StatusChanged(self, status):
+        self.SetStatus(status)
+
+    @dbus.service.signal(dbus_interface=ogSMP, signature='s')
+    def StatusTextChanged(self, status_text):
+        self.SetStatusText(status_text)
+
+
+class XScreenSaverIdleChecker():
+    class XScreenSaverInfo(ctypes.Structure):
+        """ typedef struct { ... } XScreenSaverInfo; """
+        _fields_ = [('window',   ctypes.c_ulong), # screen saver window
+            ('state',     ctypes.c_int),   # off,on,disabled
+            ('kind',           ctypes.c_int),   # blanked,internal,external
+            ('since',     ctypes.c_ulong), # milliseconds
+            ('idle',           ctypes.c_ulong), # milliseconds
+            ('event_mask',  ctypes.c_ulong)] # events
+        
+    def __init__(self, idle_timeout):
+        self.idle_timeout = idle_timeout
+        self.idle      = False
+        self.xlib      = ctypes.cdll.LoadLibrary('libX11.so.6')
+        self.dpy       = self.xlib.XOpenDisplay(os.environ['DISPLAY'])
+        self.root      = self.xlib.XDefaultRootWindow(self.dpy)
+        self.xss       = ctypes.cdll.LoadLibrary('libXss.so.1')
+        self.xss.XScreenSaverAllocInfo.restype \
+                = ctypes.POINTER(self.XScreenSaverInfo)
+        print ("XScreenSaverIdleChecker ready with timeout %d" % idle_timeout)
+    
+    def check_idle(self, smp):
+        #print "Checking idleness..."
+        xss_info = self.xss.XScreenSaverAllocInfo()
+        self.xss.XScreenSaverQueryInfo(self.dpy, self.root, xss_info)
+        idle = xss_info.contents.idle/1000
+        
+        if idle >= self.idle_timeout:
+            if not self.idle:
+                print "Becoming idle"
+                self.idle = True
+                smp.StatusChanged(smp.PRESENCE_IDLE)
+        else:
+            if self.idle:
+                print "Not idle anymore"
+                self.idle = False
+                smp.StatusChanged(smp.PRESENCE_AVAILABLE)
+        
+        gobject.timeout_add(10000, self.check_idle, smp)
+    
+
+gclient = gconf.client_get_default()
+gvalue = gclient.get('/apps/gnome-screensaver/idle_delay')
+if gvalue is not None:
+    idle_delay = gvalue.get_int() * 60
+else:
+    # 5 minutes
+    idle_delay = 300
+
+sessmgr = SessionManager()
+
+xssic = XScreenSaverIdleChecker(idle_delay)
+xssic.check_idle(sessmgr.get_smp())
+
+gtk.main()
diff --git a/create_x_infos.sh b/create_x_infos.sh
new file mode 100755 (executable)
index 0000000..4a1dbaf
--- /dev/null
@@ -0,0 +1,6 @@
+#!/bin/sh
+# Export the dbus session address on startup so it can be used by cron
+touch $HOME/.Xdbus
+chmod 600 $HOME/.Xdbus
+env | grep DBUS_SESSION_BUS_ADDRESS > $HOME/.Xdbus
+echo 'export DBUS_SESSION_BUS_ADDRESS' >> $HOME/.Xdbus
diff --git a/gmail-abook-contact-converter.py b/gmail-abook-contact-converter.py
new file mode 100755 (executable)
index 0000000..7155725
--- /dev/null
@@ -0,0 +1,35 @@
+#!/usr/bin/python
+# adr_conv.py
+#
+# Converts a vCard address book into abook addressbook format
+#
+# Author:   Gavin Costello
+# Date:     19.02.2009
+name = '';
+phone = '';
+email = '';
+count = 0;
+
+cfile = open('contacts.vcf', 'r')
+for line in cfile.readlines():
+    if (line.startswith('FN')):
+        count += 1
+        name = line.split(':')[1]
+        print
+        print u'[%d]' % count
+        print u'name=%s' % unicode(name, "utf-8"),
+    if (line.startswith('EMAIL')):
+        email = line.split(':')[1]
+        print u'email=%s' % email,
+    if (line.startswith('TEL')):
+        tel = line.split(';')[1]
+        fulltype = tel.split('=')[1]
+        type = fulltype.split(':')[0]
+        #print u'type=%s' % type,
+        phone = line.split(':')[1]
+        if (type.endswith('CELL')):
+            print u'mobile=%s' % phone,
+        elif (type.endswith('HOME')):
+            print u'phone=%s' % phone,
+        elif (type.endswith('WORK')):
+            print u'work=%s' % phone,
diff --git a/start-daemon.sh b/start-daemon.sh
new file mode 100755 (executable)
index 0000000..7cdc5cd
--- /dev/null
@@ -0,0 +1,36 @@
+#!/bin/sh
+
+set -efu
+
+ionice_class=
+ionice_priority=
+nice=
+
+while getopts c:p:n: f; do
+    case $f in
+    c) ionice_class=$OPTARG;;
+    p) ionice_priority=$OPTARG;;
+    n) nice=$OPTARG;;
+    *) exit 2;;
+    esac
+done
+shift $((OPTIND - 1))
+
+cmd=$*
+io=
+
+if pgrep -u "$(id -u)" -xf -- "$cmd" >/dev/null 2>&1; then
+    exit 0
+fi
+
+if type ionice >/dev/null 2>&1; then
+    [ -n "$ionice_class" ]    && { io=1; cmd="-c $ionice_class $cmd"; }
+    [ -n "$ionice_priority" ] && { io=1; cmd="-n $ionice_priority $cmd"; }
+    [ -n "$io" ] && cmd="ionice $cmd"
+fi
+
+if type nice >/dev/null 2>&1; then
+    [ -n "$nice" ] && cmd="nice -n $nice $cmd"
+fi
+
+exec nohup $cmd >/dev/null 2>&1 &