Newer
Older
#!/usr/bin/env python3
from PyQt4 import QtGui
from PyQt4 import QtCore
#from dcpman.dcp import DCP
#from dcpman import ui #autogenerated file from Qt Designer to setup the window
from dcp import DCP
import ui
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')
print ('DCP verification succeeded for ' + dcp.name, file = logfile)
print ('DCP verification failed for ' + dcp.name, file = logfile)
logfile.f ()
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')
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)
print ('DCP name is ' + dcp.name, file = logfile)
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)
if dcp.signed and dcp.duration == 0:
window.encryptedLine.setText('Most likely')
elif dcp.signed or dcp.duration == 0:
window.encryptedLine.setText ('Probably')
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_())