ait/os/bin/opensecurityd/opensecurity-dialog.py
branchom
changeset 2 c9bf2537109a
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/ait/os/bin/opensecurityd/opensecurity-dialog.py	Tue Nov 12 11:31:34 2013 +0100
     1.3 @@ -0,0 +1,92 @@
     1.4 +#!/bin/env python
     1.5 +# -*- coding: utf-8 -*-
     1.6 +
     1.7 +# ------------------------------------------------------------
     1.8 +# opensecurity-dialog
     1.9 +# 
    1.10 +# an opensecurity dialog
    1.11 +#
    1.12 +# Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    1.13 +#
    1.14 +# Copyright (C) 2013 AIT Austrian Institute of Technology
    1.15 +# AIT Austrian Institute of Technology GmbH
    1.16 +# Donau-City-Strasse 1 | 1220 Vienna | Austria
    1.17 +# http://www.ait.ac.at
    1.18 +#
    1.19 +# This program is free software; you can redistribute it and/or
    1.20 +# modify it under the terms of the GNU General Public License
    1.21 +# as published by the Free Software Foundation version 2.
    1.22 +# 
    1.23 +# This program is distributed in the hope that it will be useful,
    1.24 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.25 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.26 +# GNU General Public License for more details.
    1.27 +# 
    1.28 +# You should have received a copy of the GNU General Public License
    1.29 +# along with this program; if not, write to the Free Software
    1.30 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, 
    1.31 +# Boston, MA  02110-1301, USA.
    1.32 +# ------------------------------------------------------------
    1.33 +
    1.34 +
    1.35 +# ------------------------------------------------------------
    1.36 +# imports
    1.37 +
    1.38 +import argparse
    1.39 +import os
    1.40 +import sys
    1.41 +
    1.42 +from PyQt4 import QtCore
    1.43 +from PyQt4 import QtGui
    1.44 +
    1.45 +# local
    1.46 +from credentials import Credentials
    1.47 +from environment import Environment
    1.48 +from password import Password
    1.49 +
    1.50 +
    1.51 +# ------------------------------------------------------------
    1.52 +# code
    1.53 +
    1.54 +
    1.55 +def main():
    1.56 +    
    1.57 +    # parse command line
    1.58 +    parser = argparse.ArgumentParser(description = 'OpenSecuirty Dialog.')
    1.59 +    parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\' or \'credentials\'')
    1.60 +    parser.add_argument('text', metavar='TEXT', help='text to show')
    1.61 +    args = parser.parse_args()
    1.62 +    
    1.63 +    app = QtGui.QApplication(sys.argv)
    1.64 +    
    1.65 +    # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them
    1.66 +    data_path = Environment("opensecurity").image_path
    1.67 +    for file in os.listdir(data_path):
    1.68 +        if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'):
    1.69 +            QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(data_path, file)))
    1.70 +            
    1.71 +    # we should have now our application icon
    1.72 +    app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64')))
    1.73 +    
    1.74 +    if args.mode == 'password':
    1.75 +        dlg = Password(args.text)
    1.76 +    
    1.77 +    if args.mode == 'credentials':
    1.78 +        dlg = Credentials(args.text)
    1.79 +    
    1.80 +    # pop up the dialog
    1.81 +    dlg.show()
    1.82 +    app.exec_()
    1.83 +    
    1.84 +    # give proper result code
    1.85 +    if dlg.result() == QtGui.QDialog.Accepted:
    1.86 +        res = 0
    1.87 +    else:
    1.88 +        res = 1
    1.89 +    sys.exit(res)
    1.90 +    
    1.91 +
    1.92 +# start
    1.93 +if __name__ == "__main__":
    1.94 +    main()
    1.95 +