ait/os/bin/opensecurityd/opensecurity-dialog.py
author om
Tue, 12 Nov 2013 11:31:34 +0100
branchom
changeset 2 c9bf2537109a
permissions -rwxr-xr-x
added C/C++ and Python sources
om@2
     1
#!/bin/env python
om@2
     2
# -*- coding: utf-8 -*-
om@2
     3
om@2
     4
# ------------------------------------------------------------
om@2
     5
# opensecurity-dialog
om@2
     6
# 
om@2
     7
# an opensecurity dialog
om@2
     8
#
om@2
     9
# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
om@2
    10
#
om@2
    11
# Copyright (C) 2013 AIT Austrian Institute of Technology
om@2
    12
# AIT Austrian Institute of Technology GmbH
om@2
    13
# Donau-City-Strasse 1 | 1220 Vienna | Austria
om@2
    14
# http://www.ait.ac.at
om@2
    15
#
om@2
    16
# This program is free software; you can redistribute it and/or
om@2
    17
# modify it under the terms of the GNU General Public License
om@2
    18
# as published by the Free Software Foundation version 2.
om@2
    19
# 
om@2
    20
# This program is distributed in the hope that it will be useful,
om@2
    21
# but WITHOUT ANY WARRANTY; without even the implied warranty of
om@2
    22
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
om@2
    23
# GNU General Public License for more details.
om@2
    24
# 
om@2
    25
# You should have received a copy of the GNU General Public License
om@2
    26
# along with this program; if not, write to the Free Software
om@2
    27
# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
om@2
    28
# Boston, MA  02110-1301, USA.
om@2
    29
# ------------------------------------------------------------
om@2
    30
om@2
    31
om@2
    32
# ------------------------------------------------------------
om@2
    33
# imports
om@2
    34
om@2
    35
import argparse
om@2
    36
import os
om@2
    37
import sys
om@2
    38
om@2
    39
from PyQt4 import QtCore
om@2
    40
from PyQt4 import QtGui
om@2
    41
om@2
    42
# local
om@2
    43
from credentials import Credentials
om@2
    44
from environment import Environment
om@2
    45
from password import Password
om@2
    46
om@2
    47
om@2
    48
# ------------------------------------------------------------
om@2
    49
# code
om@2
    50
om@2
    51
om@2
    52
def main():
om@2
    53
    
om@2
    54
    # parse command line
om@2
    55
    parser = argparse.ArgumentParser(description = 'OpenSecuirty Dialog.')
om@2
    56
    parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\' or \'credentials\'')
om@2
    57
    parser.add_argument('text', metavar='TEXT', help='text to show')
om@2
    58
    args = parser.parse_args()
om@2
    59
    
om@2
    60
    app = QtGui.QApplication(sys.argv)
om@2
    61
    
om@2
    62
    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
om@2
    63
    data_path = Environment("opensecurity").image_path
om@2
    64
    for file in os.listdir(data_path):
om@2
    65
        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
om@2
    66
            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(data_path, file)))
om@2
    67
            
om@2
    68
    # we should have now our application icon
om@2
    69
    app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')))
om@2
    70
    
om@2
    71
    if args.mode == 'password':
om@2
    72
        dlg = Password(args.text)
om@2
    73
    
om@2
    74
    if args.mode == 'credentials':
om@2
    75
        dlg = Credentials(args.text)
om@2
    76
    
om@2
    77
    # pop up the dialog
om@2
    78
    dlg.show()
om@2
    79
    app.exec_()
om@2
    80
    
om@2
    81
    # give proper result code
om@2
    82
    if dlg.result() == QtGui.QDialog.Accepted:
om@2
    83
        res = 0
om@2
    84
    else:
om@2
    85
        res = 1
om@2
    86
    sys.exit(res)
om@2
    87
    
om@2
    88
om@2
    89
# start
om@2
    90
if __name__ == "__main__":
om@2
    91
    main()
om@2
    92