From 6636cbff81061bc270e4d21659fa3fba8eb3c87b Mon Sep 17 00:00:00 2001 From: Matthias Schiffer Date: Fri, 12 Apr 2013 18:44:55 +0200 Subject: [PATCH] Create installation script using distutils --- .gitignore | 1 + bin/pylock | 5 + etc/pylock.conf | 4 + po/de.po | 26 ++-- po/pylock.pot | 26 ++-- pylock.py | 129 ---------------- LockWindow.py => pylock/LockWindow.py | 8 +- Locker.py => pylock/Locker.py | 0 pylock/Main.py | 126 ++++++++++++++++ Selection.py => pylock/Selection.py | 0 pylock/__init__.py | 0 pylock/data/bg.svg | 208 ++++++++++++++++++++++++++ unlock.ui => pylock/data/unlock.ui | 0 pam.py => pylock/pam.py | 0 setup.py | 29 ++++ 15 files changed, 405 insertions(+), 157 deletions(-) create mode 100755 bin/pylock create mode 100644 etc/pylock.conf delete mode 100644 pylock.py rename LockWindow.py => pylock/LockWindow.py (96%) rename Locker.py => pylock/Locker.py (100%) create mode 100644 pylock/Main.py rename Selection.py => pylock/Selection.py (100%) create mode 100644 pylock/__init__.py create mode 100644 pylock/data/bg.svg rename unlock.ui => pylock/data/unlock.ui (100%) rename pam.py => pylock/pam.py (100%) create mode 100755 setup.py diff --git a/.gitignore b/.gitignore index 9b5e2e8..41f3d6d 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,3 @@ *~ __pycache__ +/build diff --git a/bin/pylock b/bin/pylock new file mode 100755 index 0000000..88652cd --- /dev/null +++ b/bin/pylock @@ -0,0 +1,5 @@ +#!/usr/bin/env python3 + +from pylock import Main + +Main.main() diff --git a/etc/pylock.conf b/etc/pylock.conf new file mode 100644 index 0000000..13c18f2 --- /dev/null +++ b/etc/pylock.conf @@ -0,0 +1,4 @@ +[pylock] +#theme = Adwaita +#logout_timeout = 600 +#logout_command = xfce4-session-logout -l diff --git a/po/de.po b/po/de.po index 9320df1..d5a83ba 100644 --- a/po/de.po +++ b/po/de.po @@ -7,7 +7,7 @@ msgid "" msgstr "" "Project-Id-Version: pylock 0.1\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-02-01 19:25+0100\n" +"POT-Creation-Date: 2013-04-12 16:37+0200\n" "PO-Revision-Date: 2012-02-01 19:30+0100\n" "Last-Translator: Matthias Schiffer \n" "Language-Team: German \n" @@ -16,19 +16,11 @@ msgstr "" "Content-Type: text/plain; charset=UTF-8\n" "Content-Transfer-Encoding: 8bit\n" -#: unlock.ui:115 unlock.ui:113 -msgid "Unlock" -msgstr "Entsperren" - -#: unlock.ui:132 unlock.ui:129 -msgid "Logout" -msgstr "Ausloggen" - -#: LockWindow.py:69 +#: ../pylock/LockWindow.py:119 msgid "This computer is currently locked by the user {username}." msgstr "Dieser Computer ist zur Zeit vom Benutzer {username} gesperrt." -#: LockWindow.py:73 +#: ../pylock/LockWindow.py:123 msgid "" "This computer is currently locked by the user {username}.\n" "The user can be logged out in {minutes:02}:{seconds:02} minutes." @@ -36,7 +28,7 @@ msgstr "" "Dieser Computer ist zur Zeit vom Benutzer {username} gesperrt.\n" "Der Benutzer kann in {minutes:02}:{seconds:02} Minuten ausgeloggt werden." -#: LockWindow.py:78 +#: ../pylock/LockWindow.py:128 msgid "" "This computer is currently locked by the user {username}.\n" "The user can be logged out now." @@ -44,6 +36,14 @@ msgstr "" "Dieser Computer ist zur Zeit vom Benutzer {username} gesperrt.\n" "Der Benutzer kann jetzt ausgeloggt werden." -#: unlock.ui:63 +#: ../unlock.ui.h:1 msgid "Password:" msgstr "Passwort:" + +#: ../unlock.ui.h:2 +msgid "Unlock" +msgstr "Entsperren" + +#: ../unlock.ui.h:3 +msgid "Logout" +msgstr "Ausloggen" diff --git a/po/pylock.pot b/po/pylock.pot index 0cb9ab8..1a5dcd9 100644 --- a/po/pylock.pot +++ b/po/pylock.pot @@ -8,7 +8,7 @@ msgid "" msgstr "" "Project-Id-Version: PACKAGE VERSION\n" "Report-Msgid-Bugs-To: \n" -"POT-Creation-Date: 2012-02-01 19:25+0100\n" +"POT-Creation-Date: 2013-04-12 18:43+0200\n" "PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n" "Last-Translator: FULL NAME \n" "Language-Team: LANGUAGE \n" @@ -17,30 +17,30 @@ msgstr "" "Content-Type: text/plain; charset=CHARSET\n" "Content-Transfer-Encoding: 8bit\n" -#: unlock.ui:115 unlock.ui:113 -msgid "Unlock" -msgstr "" - -#: unlock.ui:132 unlock.ui:129 -msgid "Logout" -msgstr "" - -#: LockWindow.py:69 +#: ../pylock/LockWindow.py:123 msgid "This computer is currently locked by the user {username}." msgstr "" -#: LockWindow.py:73 +#: ../pylock/LockWindow.py:127 msgid "" "This computer is currently locked by the user {username}.\n" "The user can be logged out in {minutes:02}:{seconds:02} minutes." msgstr "" -#: LockWindow.py:78 +#: ../pylock/LockWindow.py:132 msgid "" "This computer is currently locked by the user {username}.\n" "The user can be logged out now." msgstr "" -#: unlock.ui:63 +#: ../pylock/data/unlock.ui.h:1 msgid "Password:" msgstr "" + +#: ../pylock/data/unlock.ui.h:2 +msgid "Unlock" +msgstr "" + +#: ../pylock/data/unlock.ui.h:3 +msgid "Logout" +msgstr "" diff --git a/pylock.py b/pylock.py deleted file mode 100644 index 32e9149..0000000 --- a/pylock.py +++ /dev/null @@ -1,129 +0,0 @@ -#!/usr/bin/env python3 - - -# Copyright (c) 2012, Matthias Schiffer -# All rights reserved. -# -# 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. -# -# 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 HOLDER 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. - - -import signal -import sys -import os -import pwd -import locale -import configparser - -from gi.repository import Gtk, GLib - -from Locker import Locker -from LockWindow import LockWindow -import Selection -import pam - - -CONFIG_FILE = '/etc/pylock.conf' - - -_ = locale.gettext - - -configParser = configparser.ConfigParser() -configParser.read_file(open(CONFIG_FILE)) - -config = configParser['pylock'] -username = pwd.getpwuid(os.getuid())[0] - - -def handler(signum, frame): - Gtk.main_quit() - - -signal.signal(signal.SIGINT, handler) -signal.signal(signal.SIGTERM, handler) -signal.signal(signal.SIGQUIT, handler) - - -locale.setlocale(locale.LC_ALL, '') -locale.textdomain('pylock') - -Gtk.Settings.get_default().set_property('gtk-theme-name', config['theme']) - - -def waitForSelection(): - if Selection.get() != 0: - return True - - Gtk.main_quit() - return False - -if Selection.get() != 0: - GLib.timeout_add_seconds(1, waitForSelection) - Gtk.main() - exit(0) - - -window = LockWindow() - -if not Selection.acquire(window): - print('Unable to register pylock at X server', file=sys.stderr) - exit(1) - - -def lock(timeLeft): - window.updateLockMessage(username, timeLeft) - return window.lock() - -def logout(): - try: - os.system(config['logout_command']) - except: - pass - - window.reset(False) - -def updateTimeout(timeLeft): - window.updateLockMessage(username, timeLeft) - -if not ('logout_timeout' in config and 'logout_command' in config): - locker = Locker(lock, window.unlock) -else: - locker = Locker(lock, window.unlock, int(config['logout_timeout']), logout, updateTimeout) - -pamAuth = pam.pam() - -def tryUnlock(w, password): - if pamAuth.authenticate(username, password): - locker.unlock() - Gtk.main_quit() - else: - window.reset() - window.setAuthMessage(pamAuth.reason) - - return True - - -window.connect('logout', lambda w: locker.logout()) -window.connect('tryUnlock', tryUnlock) - -GLib.idle_add(lambda: locker.lock()) - -Gtk.main() diff --git a/LockWindow.py b/pylock/LockWindow.py similarity index 96% rename from LockWindow.py rename to pylock/LockWindow.py index a3afcc9..bb4d0e4 100644 --- a/LockWindow.py +++ b/pylock/LockWindow.py @@ -23,6 +23,7 @@ import sys +import os import locale from gi.repository import Gtk, Gdk, GObject, GLib @@ -31,6 +32,9 @@ from gi.repository import Gtk, Gdk, GObject, GLib _ = locale.gettext +PACKAGE_DIR = os.path.dirname(__file__) + + class LockWindow(Gtk.Window): __gsignals__ = { 'logout': (GObject.SIGNAL_RUN_FIRST, None, ()), @@ -47,7 +51,7 @@ class LockWindow(Gtk.Window): self.overlay = Gtk.Overlay() self.add(self.overlay) - self.bg = Gtk.Image.new_from_file("bg.svg") + self.bg = Gtk.Image.new_from_file(os.path.join(PACKAGE_DIR, 'data/bg.svg')) self.overlay.add(self.bg) self.realize() @@ -59,7 +63,7 @@ class LockWindow(Gtk.Window): builder = Gtk.Builder() - if not builder.add_from_file("unlock.ui"): + if not builder.add_from_file(os.path.join(PACKAGE_DIR, 'data/unlock.ui')): sys.exit(1) self.unlockWindow = builder.get_object('unlock_window') diff --git a/Locker.py b/pylock/Locker.py similarity index 100% rename from Locker.py rename to pylock/Locker.py diff --git a/pylock/Main.py b/pylock/Main.py new file mode 100644 index 0000000..7a2cbb9 --- /dev/null +++ b/pylock/Main.py @@ -0,0 +1,126 @@ +#!/usr/bin/env python3 + + +# Copyright (c) 2012, Matthias Schiffer +# All rights reserved. +# +# 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. +# +# 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 HOLDER 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. + + +import signal +import sys +import os +import pwd +import locale +import configparser + +from gi.repository import Gtk, GLib + +from .Locker import Locker +from .LockWindow import LockWindow +from . import Selection +from . import pam + + +CONFIG_FILE = '/etc/pylock.conf' + + +_ = locale.gettext + + +def main(): + configParser = configparser.ConfigParser() + configParser.read_file(open(CONFIG_FILE)) + + config = configParser['pylock'] + username = pwd.getpwuid(os.getuid())[0] + + def signalHandler(signum, frame): + Gtk.main_quit() + + signal.signal(signal.SIGINT, signalHandler) + signal.signal(signal.SIGTERM, signalHandler) + signal.signal(signal.SIGQUIT, signalHandler) + + locale.setlocale(locale.LC_ALL, '') + locale.textdomain('pylock') + + if 'theme' in config: + Gtk.Settings.get_defalt().set_property('gtk-theme-name', config['theme']) + + def waitForSelection(): + if Selection.get() != 0: + return True + + Gtk.main_quit() + return False + + + if Selection.get() != 0: + GLib.timeout_add_seconds(1, waitForSelection) + Gtk.main() + sys.exit(0) + + window = LockWindow() + + if not Selection.acquire(window): + print('Unable to register pylock at X server', file=sys.stderr) + sys.exit(1) + + + def lock(timeLeft): + window.updateLockMessage(username, timeLeft) + return window.lock() + + def logout(): + try: + os.system(config['logout_command']) + except: + pass + + window.reset(False) + + def updateTimeout(timeLeft): + window.updateLockMessage(username, timeLeft) + + if not ('logout_timeout' in config and 'logout_command' in config): + locker = Locker(lock, window.unlock) + else: + locker = Locker(lock, window.unlock, int(config['logout_timeout']), logout, updateTimeout) + + pamAuth = pam.pam() + + def tryUnlock(w, password): + if pamAuth.authenticate(username, password): + locker.unlock() + Gtk.main_quit() + else: + window.reset() + window.setAuthMessage(pamAuth.reason) + + return True + + window.connect('logout', lambda w: locker.logout()) + window.connect('tryUnlock', tryUnlock) + + GLib.idle_add(lambda: locker.lock()) + + Gtk.main() diff --git a/Selection.py b/pylock/Selection.py similarity index 100% rename from Selection.py rename to pylock/Selection.py diff --git a/pylock/__init__.py b/pylock/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/pylock/data/bg.svg b/pylock/data/bg.svg new file mode 100644 index 0000000..78e3972 --- /dev/null +++ b/pylock/data/bg.svg @@ -0,0 +1,208 @@ + + + +image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +Bei Problemen melden Sie sich bitte per E-Mail anpool-hotline@itsc.uni-luebeck.deoder telefonisch unter derinternen Nummer 5004. + + \ No newline at end of file diff --git a/unlock.ui b/pylock/data/unlock.ui similarity index 100% rename from unlock.ui rename to pylock/data/unlock.ui diff --git a/pam.py b/pylock/pam.py similarity index 100% rename from pam.py rename to pylock/pam.py diff --git a/setup.py b/setup.py new file mode 100755 index 0000000..9034f0e --- /dev/null +++ b/setup.py @@ -0,0 +1,29 @@ +#!/usr/bin/env python3 + +import distutils +import DistUtilsExtra.auto +import os + + +class install_pylock(distutils.command.install.install): + def run(self): + distutils.dir_util.copy_tree('etc', os.path.join(self.root, '/etc'), + preserve_times=0, preserve_symlinks=1, verbose=1) + + distutils.command.install.install.run(self) + +DistUtilsExtra.auto.setup( + name = 'pylock', + version = '1', + + data_files = [], + + packages = ['pylock'], + package_data = { + 'pylock': ['data/unlock.ui', 'data/bg.svg'], + }, + + cmdclass = { + 'install': install_pylock, + }, +)