pesterchum/pyquirks.py

36 lines
1.2 KiB
Python
Raw Normal View History

import os, sys, imp, re, ostools
2012-11-12 23:52:26 -05:00
from quirks import ScriptQuirks
2014-10-29 02:06:21 -04:00
from PyQt5 import QtGui, QtCore, QtWidgets
2011-06-07 11:48:35 -04:00
2012-11-12 23:52:26 -05:00
class PythonQuirks(ScriptQuirks):
def loadModule(self, name, filename):
return imp.load_source(name, filename)
2011-06-07 11:48:35 -04:00
2012-11-12 23:52:26 -05:00
def getExtension(self):
return '.py'
2011-06-07 11:48:35 -04:00
2012-11-12 23:52:26 -05:00
def modHas(self, module, attr):
if attr == 'commands':
variables = vars(module)
for name, obj in variables.iteritems():
if self.modHas(obj, 'command'):
return True
return hasattr(module, attr)
2011-06-07 11:48:35 -04:00
2012-11-12 23:52:26 -05:00
def register(self, module):
variables = vars(module)
2011-06-07 11:48:35 -04:00
for name, obj in variables.iteritems():
2012-11-12 23:52:26 -05:00
if self.modHas(obj, 'command'):
2011-06-07 11:48:35 -04:00
try:
if not isinstance(obj("test"), basestring):
raise Exception
except:
print "Quirk malformed: %s" % (obj.command)
2014-10-29 02:06:21 -04:00
msgbox = QtWidgets.QMessageBox()
msgbox.setWindowTitle("Error!")
msgbox.setText("Quirk malformed: %s" % (obj.command))
msgbox.exec_()
2011-06-07 11:48:35 -04:00
else:
2012-11-12 23:52:26 -05:00
self.quirks[obj.command] = obj
2011-06-07 11:48:35 -04:00