Create installation script using distutils

This commit is contained in:
Matthias Schiffer 2013-04-12 18:44:55 +02:00
parent 4659883ba0
commit 6636cbff81
15 changed files with 405 additions and 157 deletions

1
.gitignore vendored
View file

@ -1,2 +1,3 @@
*~
__pycache__
/build

5
bin/pylock Executable file
View file

@ -0,0 +1,5 @@
#!/usr/bin/env python3
from pylock import Main
Main.main()

4
etc/pylock.conf Normal file
View file

@ -0,0 +1,4 @@
[pylock]
#theme = Adwaita
#logout_timeout = 600
#logout_command = xfce4-session-logout -l

View file

@ -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 <mschiffer@universe-factory.net>\n"
"Language-Team: German <de@li.org>\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 <i>{username}</i>."
msgstr "Dieser Computer ist zur Zeit vom Benutzer <i>{username}</i> gesperrt."
#: LockWindow.py:73
#: ../pylock/LockWindow.py:123
msgid ""
"This computer is currently locked by the user <i>{username}</i>.\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 <i>{username}</i> 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 <i>{username}</i>.\n"
"The user can be logged out now."
@ -44,6 +36,14 @@ msgstr ""
"Dieser Computer ist zur Zeit vom Benutzer <i>{username}</i> 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"

View file

@ -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 <EMAIL@ADDRESS>\n"
"Language-Team: LANGUAGE <LL@li.org>\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 <i>{username}</i>."
msgstr ""
#: LockWindow.py:73
#: ../pylock/LockWindow.py:127
msgid ""
"This computer is currently locked by the user <i>{username}</i>.\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 <i>{username}</i>.\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 ""

129
pylock.py
View file

@ -1,129 +0,0 @@
#!/usr/bin/env python3
# Copyright (c) 2012, Matthias Schiffer <mschiffer@universe-factory.net>
# 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()

View file

@ -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')

126
pylock/Main.py Normal file
View file

@ -0,0 +1,126 @@
#!/usr/bin/env python3
# Copyright (c) 2012, Matthias Schiffer <mschiffer@universe-factory.net>
# 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()

0
pylock/__init__.py Normal file
View file

208
pylock/data/bg.svg Normal file
View file

@ -0,0 +1,208 @@
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!-- Created with Inkscape (http://www.inkscape.org/) -->
<svg
xmlns:dc="http://purl.org/dc/elements/1.1/"
xmlns:cc="http://creativecommons.org/ns#"
xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
xmlns:svg="http://www.w3.org/2000/svg"
xmlns="http://www.w3.org/2000/svg"
xmlns:xlink="http://www.w3.org/1999/xlink"
xmlns:sodipodi="http://sodipodi.sourceforge.net/DTD/sodipodi-0.dtd"
xmlns:inkscape="http://www.inkscape.org/namespaces/inkscape"
version="1.1"
width="1680"
height="1050"
viewBox="0 0 1680 1050"
id="svg2"
xml:space="preserve"
inkscape:version="0.48.2 r9819"
sodipodi:docname="bg.svg"><sodipodi:namedview
pagecolor="#ffffff"
bordercolor="#666666"
borderopacity="1"
objecttolerance="10"
gridtolerance="10"
guidetolerance="10"
inkscape:pageopacity="0"
inkscape:pageshadow="2"
inkscape:window-width="1280"
inkscape:window-height="776"
id="namedview3016"
showgrid="false"
inkscape:zoom="0.23166667"
inkscape:cx="349.5177"
inkscape:cy="787.53453"
inkscape:window-x="0"
inkscape:window-y="24"
inkscape:window-maximized="0"
inkscape:current-layer="layer1" /><metadata
id="metadata129"><rdf:RDF><cc:Work
rdf:about=""><dc:format>image/svg+xml</dc:format><dc:type
rdf:resource="http://purl.org/dc/dcmitype/StillImage" /><dc:title /></cc:Work></rdf:RDF></metadata><defs
id="defs127">
<linearGradient
x1="960.00049"
y1="878.5"
x2="960.00049"
y2="291.50049"
id="linearGradient3223"
xlink:href="#SVGID_1_"
gradientUnits="userSpaceOnUse" />
<linearGradient
inkscape:collect="always"
xlink:href="#SVGID_1_"
id="linearGradient3811"
gradientUnits="userSpaceOnUse"
x1="960.00049"
y1="878.5"
x2="960.00049"
y2="291.50049" />
<linearGradient
x1="960.00049"
y1="878.5"
x2="960.00049"
y2="291.50049"
id="SVGID_1_"
gradientUnits="userSpaceOnUse">
<stop
id="stop20"
style="stop-color:#50acc5;stop-opacity:0.80000001"
offset="0" />
<stop
id="stop22"
style="stop-color:#388da2;stop-opacity:0.81980002"
offset="0.0148" />
<stop
id="stop24"
style="stop-color:#247385;stop-opacity:0.84420002"
offset="0.0331" />
<stop
id="stop26"
style="stop-color:#166071;stop-opacity:0.87110001"
offset="0.0533" />
<stop
id="stop28"
style="stop-color:#0b5363;stop-opacity:0.9016"
offset="0.0762" />
<stop
id="stop30"
style="stop-color:#044d5c;stop-opacity:0.93849999"
offset="0.1039" />
<stop
id="stop32"
style="stop-color:#104b5a;stop-opacity:1;"
offset="0.15000001" />
<stop
id="stop34"
style="stop-color:#104b5a;stop-opacity:1;"
offset="0.85000002" />
<stop
id="stop36"
style="stop-color:#044d5c;stop-opacity:0.93529999"
offset="0.89859998" />
<stop
id="stop38"
style="stop-color:#0b5363;stop-opacity:0.8987"
offset="0.926" />
<stop
id="stop40"
style="stop-color:#165f70;stop-opacity:0.86919999"
offset="0.94809997" />
<stop
id="stop42"
style="stop-color:#237184;stop-opacity:0.84350002"
offset="0.96740001" />
<stop
id="stop44"
style="stop-color:#368ba0;stop-opacity:0.8204"
offset="0.98470002" />
<stop
id="stop46"
style="stop-color:#50acc5;stop-opacity:0.80000001"
offset="1" />
</linearGradient>
<linearGradient
inkscape:collect="always"
xlink:href="#SVGID_1_"
id="linearGradient3830"
gradientUnits="userSpaceOnUse"
x1="960.00049"
y1="878.5"
x2="960.00049"
y2="291.50049"
gradientTransform="matrix(1.1474185,0,0,0.85490494,-261.52174,174.07496)" /></defs>
<g
id="Hilfslinien_Center"
style="display:none"
transform="translate(0,-150)">
</g>
<g
inkscape:groupmode="layer"
id="layer1"
inkscape:label="Layer"
transform="translate(0,-150)"><rect
style="fill:#104b5a;fill-opacity:1"
id="rect5"
y="150"
x="0"
height="1050"
width="1680" /><path
d="m 1326.2174,920.83442 c 0,2.35099 -2.5816,4.27453 -5.7371,4.27453 H 359.51967 c -3.1554,0 -5.73709,-1.92354 -5.73709,-4.27453 V 427.55427 c 0,-2.35098 2.58169,-4.27452 5.73709,-4.27452 h 960.96063 c 3.1555,0 5.7371,1.92354 5.7371,4.27452 v 493.28015 z"
id="path48"
style="opacity:0.5;fill:url(#linearGradient3830)"
inkscape:connector-curvature="0" /><path
d="m 1326.2174,920.83442 c 0,2.35099 -2.5816,4.27453 -5.7371,4.27453 H 359.51967 c -3.1554,0 -5.73709,-1.92354 -5.73709,-4.27453 V 427.55427 c 0,-2.35098 2.58169,-4.27452 5.73709,-4.27452 h 960.96063 c 3.1555,0 5.7371,1.92354 5.7371,4.27452 v 493.28015 z"
id="path50"
style="fill:none;stroke:#50acc5;stroke-width:0.4952105;stroke-linejoin:round;stroke-miterlimit:10"
inkscape:connector-curvature="0" /><g
id="Hilfslinien_Login"
transform="translate(-120,75)">
</g><text
xml:space="preserve"
style="font-size:14px;font-style:normal;font-weight:normal;line-height:129.99999523%;letter-spacing:0px;word-spacing:0px;fill:#ffffff;fill-opacity:1;stroke:none;font-family:Sans"
x="839.86035"
y="1006.295"
id="text3011"
sodipodi:linespacing="130%"><tspan
sodipodi:role="line"
id="tspan3013"
x="839.86035"
y="1006.295"
style="font-size:22px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:center;line-height:129.99999523%;writing-mode:lr-tb;text-anchor:middle;font-family:Sans;-inkscape-font-specification:Sans Bold">Bei Problemen melden Sie sich bitte per E-Mail an</tspan><tspan
sodipodi:role="line"
x="839.86035"
y="1034.895"
id="tspan3015"
style="font-size:22px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:center;line-height:129.99999523%;writing-mode:lr-tb;text-anchor:middle;font-family:Sans;-inkscape-font-specification:Sans Bold" /><tspan
sodipodi:role="line"
x="839.86035"
y="1063.495"
id="tspan3017"
style="font-size:22px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:center;line-height:129.99999523%;writing-mode:lr-tb;text-anchor:middle;font-family:Sans;-inkscape-font-specification:Sans Bold">pool-hotline@itsc.uni-luebeck.de</tspan><tspan
sodipodi:role="line"
x="839.86035"
y="1092.095"
id="tspan3019"
style="font-size:22px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:center;line-height:129.99999523%;writing-mode:lr-tb;text-anchor:middle;font-family:Sans;-inkscape-font-specification:Sans Bold" /><tspan
sodipodi:role="line"
x="839.86035"
y="1120.6949"
id="tspan3021"
style="font-size:22px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:center;line-height:129.99999523%;writing-mode:lr-tb;text-anchor:middle;font-family:Sans;-inkscape-font-specification:Sans Bold">oder telefonisch unter der</tspan><tspan
sodipodi:role="line"
x="839.86035"
y="1149.2949"
id="tspan3023"
style="font-size:22px;font-style:normal;font-variant:normal;font-weight:bold;font-stretch:normal;text-align:center;line-height:129.99999523%;writing-mode:lr-tb;text-anchor:middle;font-family:Sans;-inkscape-font-specification:Sans Bold">internen Nummer 5004.</tspan></text>
</g></svg>

After

Width:  |  Height:  |  Size: 7.2 KiB

29
setup.py Executable file
View file

@ -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,
},
)