~guadalinex-members/hermeshardware/unstable

« back to all changes in this revision

Viewing changes to actors/gempluscardreader.py

  • Committer: David Amian
  • Date: 2010-04-27 12:06:32 UTC
  • Revision ID: amialinux@gmail.com-20100427120632-i776520zuq9g3hi4
Updated to unstable branch format

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# -*- coding: utf-8 -*-
2
 
 
3
 
#Módulo gempluscardreader- Módulo que implementa el "actor hardware" para los
4
 
#lectores de tarjetas Gemplus GemPC Twin.
5
 
#
6
 
# Authors:
7
 
#     David Amián Valle <amialinux@gmail.com
8
 
#
9
 
# [es] Modulo gempluscardreader - Implementación del "actor hardware" para
10
 
#         lectores de tarjetas Gemplus GemPC Twin
11
 
# [en] gempluscardreader Module - Gemplus GemPC Twin cardreader devices Actor
12
 
# class implementation
13
 
#
14
 
# Copyright (C) 2009 Junta de Andalucía
15
 
#
16
 
# ----------------------------[es]---------------------------------------------
17
 
#
18
 
# Este fichero es parte de Detección de Hardware de Guadalinex V6
19
 
#
20
 
# Este programa es software libre: puede redistribuirlo y/o modificarlo bajo
21
 
# los términos de la Licencia Pública General version 3 de GNU según
22
 
# es publicada por la Free Software Foundation.
23
 
#
24
 
# Este programa se distribuye con la esperanza de que será útil, pero
25
 
# SIN NINGUNA GARANTÍA, incluso sin la garantías implicitas de
26
 
# MERCANTILIZACION, CALIDAD SATISFACTORIA o de CONVENIENCIA PARA UN PROPÓSITO
27
 
# PARTICULAR. Véase la Licencia Pública General de GNU para más detalles.
28
 
#
29
 
# Debería haber recibido una copia de la Licencia Pública General
30
 
# junto con este programa; si no ha sido así,
31
 
# visite <http://www.gnu.org/licenses/>
32
 
# o escriba a la Free Software Foundation, Inc.,
33
 
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA.
34
 
#
35
 
# ----------------------------[en]---------------------------------------------
36
 
#
37
 
# This file is part of Guadalinex V6 Hardware Detection.
38
 
#
39
 
# This program is free software: you can redistribute it and/or modify it
40
 
# under the terms of the GNU General Public License version 3, as published
41
 
# by the Free Software Foundation.
42
 
#
43
 
# This program is distributed in the hope that it will be useful, but
44
 
# WITHOUT ANY WARRANTY; without even the implied warranties of
45
 
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
46
 
# PURPOSE.  See the GNU General Public License for more details.
47
 
#
48
 
# You should have received a copy of the GNU General Public License
49
 
# along with this program; if not, visit <http://www.gnu.org/licenses/>
50
 
# or write to the Free Software Foundation, Inc.,
51
 
# 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
52
 
 
53
 
import commands
54
 
import os
55
 
import os.path
56
 
 
57
 
from deviceactor import PkgDeviceActor
58
 
from utils.pkginstaller import PkgInstaller
59
 
from utils import get_sudo
60
 
from gettext import gettext as _
61
 
 
62
 
CERTMANAGER_CMD = '/usr/bin/certmanager.py'
63
 
 
64
 
 
65
 
class Actor(PkgDeviceActor):
66
 
    """
67
 
    [es] Implementación de la clase Actor para dispositivos lectores de
68
 
            tarjetas Gemplus GemPC Twin.
69
 
    ---------------------------------------------------------------------------
70
 
    [en]  Gemplus GemPC Twin cardreader devices Actor class implementation
71
 
    """
72
 
    __required__ = {
73
 
            "info.subsystem": "usb_device",
74
 
            "usb_device.vendor_id":0x8E6,
75
 
            "usb_device.product_id":0x3437}
76
 
 
77
 
    __icon_path__  = os.path.abspath('actors/img/gempctwin.png')
78
 
    __iconoff_path__ = os.path.abspath('actors/img/gempctwinoff.png')
79
 
    __device_title__ = _("Gemplus GemPC Twin")
80
 
    __device_conn_description__ = _("Card reader detected")
81
 
    __device_disconn_description__ = _("Card reader disconnected")
82
 
 
83
 
    def on_added(self):
84
 
        actions = {}
85
 
        def configure_dnie():
86
 
            os.system('%s --install-dnie' % CERTMANAGER_CMD)
87
 
 
88
 
        def configure_ceres():
89
 
            os.system('%s --install-ceres' % CERTMANAGER_CMD)
90
 
 
91
 
        if os.path.exists(CERTMANAGER_CMD):
92
 
            actions[_("Configure DNIe")] = configure_dnie
93
 
            actions[_("Configure FNMT-Ceres card")] = configure_ceres
94
 
 
95
 
        def add_user_to_scard():
96
 
            import pwd
97
 
            # The os.getlogin() raises OSError: [Errno 25]
98
 
            # Moved to getpwuid
99
 
            user = pwd.getpwuid(os.geteuid())[0]
100
 
            # [es] Obtenemos acceso en modo administrador
101
 
            # [en] get root access
102
 
            if get_sudo():
103
 
                cmd = '/usr/bin/gksudo /usr/sbin/adduser %s scard' % user
104
 
                status, output = commands.getstatusoutput(cmd)
105
 
                self.msg_render.show_info(_('Session restart needed'),
106
 
                                          _('You must restart your session to apply the changes'))
107
 
 
108
 
        status, output = commands.getstatusoutput('/usr/bin/groups')
109
 
        if 'scard' not in output:
110
 
            actions[_("Add user to scard group")] = add_user_to_scard
111
 
 
112
 
        self.msg_render.show(self.__device_title__, 
113
 
                             self.__device_conn_description__,
114
 
                             self.__icon_path__, actions=actions)
115