OpenSecurity/bin/opensecurity_dialog.pyw
author Oliver Maurhart <oliver.maurhart@ait.ac.at>
Wed, 29 Oct 2014 15:18:22 +0100
changeset 240 d7ef04254e9c
parent 134 f1c1c06c947d
permissions -rwxr-xr-x
lizenz fixed in all files
     1 #!/bin/env python
     2 # -*- coding: utf-8 -*-
     3 
     4 # ------------------------------------------------------------
     5 # opensecurity-dialog
     6 # 
     7 # an opensecurity dialog
     8 #
     9 # Autor: Oliver Maurhart, <oliver.maurhart@ait.ac.at>
    10 #
    11 # Copyright 2013-2014 X-Net and AIT Austrian Institute of Technology
    12 # 
    13 # 
    14 #     X-Net Services GmbH
    15 #     Elisabethstrasse 1
    16 #     4020 Linz
    17 #     AUSTRIA
    18 #     https://www.x-net.at
    19 # 
    20 #     AIT Austrian Institute of Technology
    21 #     Donau City Strasse 1
    22 #     1220 Wien
    23 #     AUSTRIA
    24 #     http://www.ait.ac.at
    25 # 
    26 # 
    27 # Licensed under the Apache License, Version 2.0 (the "License");
    28 # you may not use this file except in compliance with the License.
    29 # You may obtain a copy of the License at
    30 # 
    31 #    http://www.apache.org/licenses/LICENSE-2.0
    32 # 
    33 # Unless required by applicable law or agreed to in writing, software
    34 # distributed under the License is distributed on an "AS IS" BASIS,
    35 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
    36 # See the License for the specific language governing permissions and
    37 # limitations under the License.
    38 # ------------------------------------------------------------
    39 
    40 
    41 # ------------------------------------------------------------
    42 # imports
    43 
    44 import argparse
    45 import os
    46 import sys
    47 
    48 from PyQt4 import QtCore
    49 from PyQt4 import QtGui
    50 
    51 # local
    52 from ui import *
    53 
    54 
    55 # ------------------------------------------------------------
    56 # code
    57 
    58 
    59 def main():
    60     
    61     # parse command line
    62     parser = argparse.ArgumentParser(description = 'OpenSecurity Dialog.')
    63     parser.add_argument('mode', metavar='MODE', help='dialog mode: \'password\', \'credentials\', \'keyfile\', \'notification-information\', \'notification-warning\' or \'notification-critical\'')
    64     parser.add_argument('text', metavar='TEXT', help='text to show')
    65     args = parser.parse_args()
    66     
    67     a = QtGui.QApplication(sys.argv)
    68     
    69     if args.mode == 'password':
    70         d = PasswordDialog(args.text)
    71     
    72     if args.mode == 'credentials':
    73         d = CredentialsDialog(args.text)
    74     
    75     if args.mode == 'keyfile':
    76         d = KeyfileDialog(args.text)
    77     
    78     if args.mode == 'notification-information':
    79         d = NotificationDialog('OpenSecurity Information', args.text)
    80     
    81     if args.mode == 'notification-warning':
    82         d = NotificationDialog('OpenSecurity Warning', args.text)
    83     
    84     if args.mode == 'notification-critical':
    85         d = NotificationDialog('OpenSecurity Critical Message', args.text)
    86         
    87     if not 'd' in locals():
    88         sys.stderr.write('unknown mode. type --help for help\n')
    89         sys.exit(1)
    90     
    91     # pop up the dialog
    92     d.show()
    93     a.exec_()
    94     
    95     # give proper result code
    96     if d.result() == QtGui.QDialog.Accepted:
    97         res = 0
    98     else:
    99         res = 1
   100     sys.exit(res)
   101     
   102 
   103 # start
   104 if __name__ == "__main__":
   105     main()
   106