om@2: #!/bin/env python om@2: # -*- coding: utf-8 -*- om@2: om@2: # ------------------------------------------------------------ om@2: # opensecurity-dialog om@2: # om@2: # an opensecurity dialog om@2: # om@2: # Autor: Oliver Maurhart, om@2: # om@2: # Copyright (C) 2013 AIT Austrian Institute of Technology om@2: # AIT Austrian Institute of Technology GmbH om@2: # Donau-City-Strasse 1 | 1220 Vienna | Austria om@2: # http://www.ait.ac.at om@2: # om@2: # This program is free software; you can redistribute it and/or om@2: # modify it under the terms of the GNU General Public License om@2: # as published by the Free Software Foundation version 2. om@2: # om@2: # This program is distributed in the hope that it will be useful, om@2: # but WITHOUT ANY WARRANTY; without even the implied warranty of om@2: # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the om@2: # GNU General Public License for more details. om@2: # om@2: # You should have received a copy of the GNU General Public License om@2: # along with this program; if not, write to the Free Software om@2: # Foundation, Inc., 51 Franklin Street, Fifth Floor, om@2: # Boston, MA 02110-1301, USA. om@2: # ------------------------------------------------------------ om@2: om@2: om@2: # ------------------------------------------------------------ om@2: # imports om@2: om@2: import argparse om@2: import os om@2: import sys om@2: om@2: from PyQt4 import QtCore om@2: from PyQt4 import QtGui om@2: om@2: # local om@2: from credentials import Credentials om@2: from environment import Environment om@2: from password import Password om@2: om@2: om@2: # ------------------------------------------------------------ om@2: # code om@2: om@2: om@2: def main(): om@2: om@2: # parse command line om@2: parser = argparse.ArgumentParser(description = 'OpenSecuirty Dialog.') om@2: parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\' or \'credentials\'') om@2: parser.add_argument('text', metavar='TEXT', help='text to show') om@2: args = parser.parse_args() om@2: om@2: app = QtGui.QApplication(sys.argv) om@2: om@2: # prebuild the pixmap cache: fetch all jpg, png and jpeg images and load them om@2: data_path = Environment("opensecurity").image_path om@2: for file in os.listdir(data_path): om@2: if file.lower().rpartition('.')[2] in ('jpg', 'png', 'jpeg'): om@2: QtGui.QPixmapCache.insert(file.lower().rpartition('.')[0], QtGui.QPixmap(os.path.join(data_path, file))) om@2: om@2: # we should have now our application icon om@2: app.setWindowIcon(QtGui.QIcon(QtGui.QPixmapCache.find('opensecurity_icon_64'))) om@2: om@2: if args.mode == 'password': om@2: dlg = Password(args.text) om@2: om@2: if args.mode == 'credentials': om@2: dlg = Credentials(args.text) om@2: om@2: # pop up the dialog om@2: dlg.show() om@2: app.exec_() om@2: om@2: # give proper result code om@2: if dlg.result() == QtGui.QDialog.Accepted: om@2: res = 0 om@2: else: om@2: res = 1 om@2: sys.exit(res) om@2: om@2: om@2: # start om@2: if __name__ == "__main__": om@2: main() om@2: