Skip to content
manager.py 3.16 KiB
Newer Older
nimrod's avatar
nimrod committed
#!/usr/bin/env python3
from PyQt4 import QtGui
from PyQt4 import QtCore
nimrod's avatar
nimrod committed
#from dcpman.dcp import DCP
#from dcpman import ui #autogenerated file from Qt Designer to setup the window
from dcp import DCP
import ui
nimrod's avatar
nimrod committed
import sys
nimrod's avatar
nimrod committed

class verifyThread(QtCore.QThread):
    '''A seperate thread to verify the DCP (IO intensive).

    Verify the assets of DCP (reads all of the files to
    calculate the hash) in a seperate thread from the GUI to keep the GUI
    responsive. At the end update the verifyLine test to reflect the result.'''
    def run(self):
        '''The action the thread takes.'''
        result = dcp.verify()
        try:
            result = dcp.verify()
            logfile = open (os.path.expanduser ('~') + '/dcpman.log', 'a')
nimrod's avatar
nimrod committed
            if result:
                window.verifyLine.setText('OK')
                print ('DCP verification succeeded for ' + dcp.name, file = logfile)
nimrod's avatar
nimrod committed
            else:
                window.verifyLine.setText('Corrupted!')
                print ('DCP verification failed for ' + dcp.name, file = logfile)
            logfile.f ()
nimrod's avatar
nimrod committed
        except BaseException as exception:
            window.verifyLine.setText(str(exception))


def verify_in_thread():
    '''Verifys the DCP in a differenet thread.

    Firstly disable the button and change the verifyLine to reflect that the
    verification is running (in the same thread to update the window immediately
    then calls the seperate thread to verify the assets of DCP.'''
    window.verifyLine.setText('Verifying, please wait...')
    window.verifyButton.setEnabled(False)
    thread.start()


if __name__ == '__main__':
    logfile = open (os.path.expanduser ('~') + '/dcpman.log', 'a')
nimrod's avatar
nimrod committed
    app = QtGui.QApplication(sys.argv)
    icon = QtGui.QIcon('/usr/share/icons/oxygen/16x16/apps/kmplayer.png')
    app.setWindowIcon(icon)
    directory = QtGui.QFileDialog.getExistingDirectory( \
            caption='Please select the location of the DCP')
    mainwindow = QtGui.QMainWindow()
    window = ui.Ui_MainWindow()
    window.setupUi(mainwindow)
    thread = verifyThread()
    try:
        dcp = DCP(directory)
        print ('Opened DCP in directory ' + directory, file = logfile)
nimrod's avatar
nimrod committed
        try:
            window.nameLine.setText(dcp.name)
            print ('DCP name is ' + dcp.name, file = logfile)
nimrod's avatar
nimrod committed
        except AttributeError:
            window.nameLine.setText(directory.split('/')[-1])
        if dcp.signed:
            print ('DCP is signed', file = logfile)
        else:
            print ('DCP is not signed', file = logfile)
        print ('DCP duration is ' + dcp.duration, file = logfile)
nimrod's avatar
nimrod committed
        if dcp.signed and dcp.duration == 0:
            window.encryptedLine.setText('Most likely')
        elif dcp.signed or dcp.duration == 0:
            window.encryptedLine.setText ('Probably')
nimrod's avatar
nimrod committed
        else:
nimrod's avatar
nimrod committed
            window.encryptedLine.setText('Probably not')
nimrod's avatar
nimrod committed
        window.verifyLine.setText('Click button to start verification')
        window.verifyButton.clicked.connect(verify_in_thread)
    except BaseException as exception:
        window.nameLine.setText(str(exception))
        window.verifyButton.setEnabled(False)
    mainwindow.show()
    mainwindow.activateWindow()
    exit(app.exec_())