2022-03-19 19:48:19 -04:00
|
|
|
"""
|
|
|
|
Okay so, this definitely doesn't work in its current state-
|
|
|
|
Probably broke when transitioning to Python 3? Might've been broken for longer-
|
|
|
|
Hard for me to work on this since I know absolutely nothing about lua, plus I'm not sure what 'lua' library this was originally supposed to work with.
|
|
|
|
+ I asked and there doesn't seem to be a single person who actually used this 💀
|
|
|
|
|
|
|
|
import logging
|
|
|
|
import logging.config
|
|
|
|
import os
|
|
|
|
import sys
|
|
|
|
import re
|
|
|
|
|
|
|
|
from PyQt5 import QtCore, QtGui, QtWidgets
|
|
|
|
|
2021-12-01 12:29:17 -05:00
|
|
|
import ostools
|
2022-03-19 19:48:19 -04:00
|
|
|
from quirks import ScriptQuirks
|
|
|
|
|
2021-12-01 12:29:17 -05:00
|
|
|
_datadir = ostools.getDataDir()
|
|
|
|
logging.config.fileConfig(_datadir + "logging.ini")
|
2021-08-10 16:45:48 -04:00
|
|
|
PchumLog = logging.getLogger('pchumLogger')
|
2022-03-19 19:48:19 -04:00
|
|
|
|
2012-11-12 23:52:26 -05:00
|
|
|
try:
|
2022-03-19 19:48:19 -04:00
|
|
|
try:
|
|
|
|
import lua
|
|
|
|
except ImportError:
|
|
|
|
import lupa
|
|
|
|
from lupa import LuaRuntime
|
|
|
|
|
|
|
|
lua = LuaRuntime(unpack_returned_tuples=True)
|
|
|
|
PchumLog.info("Lua \"successfully\" imported.")
|
|
|
|
except ImportError as e:
|
|
|
|
PchumLog.warning("No lua library. " + str(e))
|
2012-11-12 23:52:26 -05:00
|
|
|
lua = None
|
|
|
|
|
|
|
|
class LuaQuirks(ScriptQuirks):
|
|
|
|
def loadModule(self, name, filename):
|
|
|
|
if lua is None:
|
|
|
|
return None
|
2013-02-10 12:49:44 -05:00
|
|
|
|
|
|
|
lua.globals().package.loaded[name] = None
|
2013-02-26 01:02:30 -05:00
|
|
|
|
2013-02-10 12:49:44 -05:00
|
|
|
CurrentDir = os.getcwd()
|
|
|
|
os.chdir('quirks')
|
2022-03-19 19:48:19 -04:00
|
|
|
|
|
|
|
lua.globals().package.path = filename.replace(name+".lua", "?.lua")
|
|
|
|
|
2013-02-10 12:49:44 -05:00
|
|
|
try:
|
|
|
|
return lua.require(name)
|
2022-03-19 19:48:19 -04:00
|
|
|
except Exception as e:
|
|
|
|
PchumLog.warning(e)
|
2013-02-10 12:49:44 -05:00
|
|
|
return None
|
|
|
|
finally:
|
|
|
|
os.chdir(CurrentDir)
|
2012-11-12 23:52:26 -05:00
|
|
|
|
|
|
|
def getExtension(self):
|
|
|
|
return '.lua'
|
|
|
|
|
|
|
|
def modHas(self, module, attr):
|
2022-03-19 19:48:19 -04:00
|
|
|
return attr in module
|
2012-11-12 23:52:26 -05:00
|
|
|
|
|
|
|
def register(self, module):
|
|
|
|
class Wrapper(object):
|
|
|
|
def __init__(self, module, name):
|
|
|
|
self.module = module
|
|
|
|
self.name = name
|
|
|
|
|
|
|
|
def __call__(self, text):
|
2013-02-10 12:49:44 -05:00
|
|
|
CurrentDir = os.getcwd()
|
|
|
|
os.chdir('quirks')
|
|
|
|
try:
|
|
|
|
return self.module.commands[self.name](lua.globals().tostring(text))
|
2022-03-19 19:48:19 -04:00
|
|
|
except Exception as e:
|
|
|
|
PchumLog.warning(e)
|
2013-02-10 12:49:44 -05:00
|
|
|
return None
|
|
|
|
finally:
|
|
|
|
os.chdir(CurrentDir)
|
2012-11-12 23:52:26 -05:00
|
|
|
|
|
|
|
for name in module.commands:
|
2013-02-10 12:49:44 -05:00
|
|
|
CommandWrapper = Wrapper(module,name)
|
2012-11-12 23:52:26 -05:00
|
|
|
try:
|
2021-03-23 17:36:43 -04:00
|
|
|
if not isinstance(CommandWrapper("test"), str):
|
2012-11-12 23:52:26 -05:00
|
|
|
raise Exception
|
|
|
|
except:
|
2021-03-25 13:41:07 -04:00
|
|
|
#print("Quirk malformed: %s" % (name))
|
2021-08-10 16:45:48 -04:00
|
|
|
PchumLog.error("Quirk malformed: %s" % (name))
|
2021-03-25 13:41:07 -04:00
|
|
|
|
|
|
|
# Since this is executed before QApplication is constructed,
|
|
|
|
# This prevented pesterchum from starting entirely when a quirk was malformed :/
|
|
|
|
# (QWidget: Must construct a QApplication before a QWidget)
|
|
|
|
|
|
|
|
if QtWidgets.QApplication.instance() != None:
|
|
|
|
msgbox = QtWidgets.QMessageBox()
|
|
|
|
msgbox.setWindowTitle("Error!")
|
|
|
|
msgbox.setText("Quirk malformed: %s" % (name))
|
|
|
|
msgbox.exec_()
|
2012-11-12 23:52:26 -05:00
|
|
|
else:
|
2013-02-10 12:49:44 -05:00
|
|
|
self.quirks[name] = CommandWrapper
|
2022-03-19 19:48:19 -04:00
|
|
|
"""
|