Changes to imports, contants, shebang, luaquirks, pynotify, oyoyo.

- Removed unnecessary imports.
    - Reorganized import order.
    - Removed legacy import conditions.
    - Added python3 shebang to pesterchum.py
    - Set QString to always be str, Python 2 is not supported.
    - Depreciated luaquirks.
    - Added ValueError to write exception block
    - Set "pynotify" to always be none, even if pynotify succesfully imported, since pynotify implementation is broken.
This commit is contained in:
Dpeta 2022-03-20 00:48:19 +01:00
parent cb1e2e051e
commit 9d0f074bbe
20 changed files with 159 additions and 125 deletions

View file

@ -9,12 +9,7 @@ from os import remove
import dataobjs, generic, memos, parsetools, ostools
from version import _pcVersion
try:
from pnc.attrdict import AttrDict
except ImportError:
# Fall back on the old location, just in case
from pnc.dep.attrdict import AttrDict
from pnc.dep.attrdict import AttrDict
#~from styling import styler
_datadir = ostools.getDataDir()

View file

@ -1,4 +1,5 @@
import logging, logging.config
import logging
import logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
@ -19,11 +20,7 @@ from parsetools import convertTags, lexMessage, mecmd, colorBegin, colorEnd, \
import parsetools
import pnc.lexercon as lexercon
try:
from pnc.attrdict import AttrDict
except ImportError:
# Fall back on the old location - just in case
from pnc.dep.attrdict import AttrDict
from pnc.dep.attrdict import AttrDict
class PesterTabWindow(QtWidgets.QFrame):
def __init__(self, mainwindow, parent=None, convo="convo"):

View file

@ -1,4 +1,5 @@
import logging, logging.config
import logging
import logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")

32
irc.py
View file

@ -1,27 +1,27 @@
import logging, logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
from PyQt5 import QtCore, QtGui
from oyoyo.client import IRCClient
from oyoyo.cmdhandler import DefaultCommandHandler
from oyoyo import helpers, services
import random
import logging
import logging.config
import socket
import random
from time import time
from PyQt5 import QtCore, QtGui
import ostools
from mood import Mood
from dataobjs import PesterProfile
from generic import PesterList
from version import _pcVersion
import ostools
try:
QString = unicode
except NameError:
# Python 3
QString = str
from oyoyo.client import IRCClient
from oyoyo.cmdhandler import DefaultCommandHandler
from oyoyo import helpers, services
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
# Python 3
QString = str
#if ostools.isOSXBundle():
# logging.basicConfig(level=logging.WARNING)

View file

@ -1,15 +1,36 @@
import logging, logging.config
"""
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
import ostools
from quirks import ScriptQuirks
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
import os, sys, re, ostools
try:
import lua
except ImportError:
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))
lua = None
from quirks import ScriptQuirks
from PyQt5 import QtCore, QtGui, QtWidgets
class LuaQuirks(ScriptQuirks):
def loadModule(self, name, filename):
@ -20,10 +41,13 @@ class LuaQuirks(ScriptQuirks):
CurrentDir = os.getcwd()
os.chdir('quirks')
lua.globals().package.path = filename.replace(name+".lua", "?.lua")
try:
return lua.require(name)
except Error as e:
PchumLog.error(e)
except Exception as e:
PchumLog.warning(e)
return None
finally:
os.chdir(CurrentDir)
@ -32,7 +56,7 @@ class LuaQuirks(ScriptQuirks):
return '.lua'
def modHas(self, module, attr):
return module[attr] is not None
return attr in module
def register(self, module):
class Wrapper(object):
@ -45,7 +69,8 @@ class LuaQuirks(ScriptQuirks):
os.chdir('quirks')
try:
return self.module.commands[self.name](lua.globals().tostring(text))
except:
except Exception as e:
PchumLog.warning(e)
return None
finally:
os.chdir(CurrentDir)
@ -70,4 +95,4 @@ class LuaQuirks(ScriptQuirks):
msgbox.exec_()
else:
self.quirks[name] = CommandWrapper
"""

View file

@ -1,28 +1,28 @@
import logging, logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
from string import Template
import logging
import logging.config
import re
from string import Template
from copy import copy
from PyQt5 import QtCore, QtGui, QtWidgets
from datetime import time, timedelta, datetime
from PyQt5 import QtCore, QtGui, QtWidgets
import ostools
import parsetools
from mood import Mood
from dataobjs import PesterProfile, PesterHistory
from generic import PesterIcon, RightClickList, mysteryTime
from convo import PesterConvo, PesterInput, PesterText, PesterTabWindow
from parsetools import convertTags, addTimeInitial, timeProtocol, \
lexMessage, colorBegin, colorEnd, mecmd, smiledict
import parsetools
from logviewer import PesterLogViewer
try:
QString = unicode
except NameError:
# Python 3
QString = str
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
# Python 3
QString = str
def delta2txt(d, format="pc"):
if type(d) is mysteryTime:

View file

@ -1,17 +1,15 @@
from PyQt5 import QtCore, QtGui, QtWidgets
import re, ostools
import re
from os import remove
from PyQt5 import QtCore, QtGui, QtWidgets
import ostools
from generic import RightClickList, RightClickTree, MultiTextDialog, NoneSound
from dataobjs import pesterQuirk, PesterProfile
from memos import TimeSlider, TimeInput
from version import _pcVersion
try:
QString = unicode
except NameError:
# Python 3
QString = str
QString = str
_datadir = ostools.getDataDir()

View file

@ -1,5 +1,7 @@
import os, sys
import os
import sys
import platform
from PyQt5.QtGui import QDesktopServices
from PyQt5.QtCore import QStandardPaths

View file

@ -15,7 +15,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import logging, logging.config
import logging
import logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
@ -27,11 +28,9 @@ import sys
import time
import os
import traceback
import ostools
import ssl
import json
import select
_datadir = ostools.getDataDir()
from oyoyo.parse import *
from oyoyo import helpers
@ -159,7 +158,7 @@ class IRCClient:
for x in ready_to_write:
x.sendall(msg + bytes("\r\n", "UTF-8"))
break
except socket.error as e:
except (socket.error, ValueError) as e:# "file descriptor cannot be a negative integer"
retry += 1
PchumLog.warning("socket.error (retry %s) %s" % (str(retry), str(e)))
except socket.error as se:
@ -210,7 +209,7 @@ class IRCClient:
if self._end:
break
raise e
except socket.error as e:
except (socket.error, ValueError) as e:
PchumLog.warning("conn socket.error %s in %s" % (e, self))
if self._end:
break

View file

@ -14,7 +14,8 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import logging, logging.config
import logging
import logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")

View file

@ -17,7 +17,8 @@
""" contains helper functions for common irc commands """
import logging, logging.config
import logging
import logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")

View file

@ -15,7 +15,8 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import logging, logging.config
import logging
import logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")

View file

@ -1,32 +1,29 @@
import logging, logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
import logging
import logging.config
import re
import random
import ostools
import collections
from copy import copy
from datetime import timedelta
from PyQt5 import QtCore, QtGui, QtWidgets
import dataobjs
import ostools
# karxi: My own contribution to this - a proper lexer.
import pnc.lexercon as lexercon
from generic import mysteryTime
from quirks import ScriptQuirks
from pyquirks import PythonQuirks
from luaquirks import LuaQuirks
import dataobjs
#from luaquirks import LuaQuirks
# karxi: My own contribution to this - a proper lexer.
import pnc.lexercon as lexercon
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
# I'll clean up the things that are no longer needed once the transition is
# actually finished.
try:
QString = unicode
except NameError:
# Python 3
QString = str
QString = str
_ctag_begin = re.compile(r'(?i)<c=(.*?)>')
_gtag_begin = re.compile(r'(?i)<g[a-f]>')
@ -45,7 +42,7 @@ _honk = re.compile(r"(?i)\bhonk\b")
quirkloader = ScriptQuirks()
quirkloader.add(PythonQuirks())
quirkloader.add(LuaQuirks())
#quirkloader.add(LuaQuirks())
quirkloader.loadAll()
# Quirks are already listed in quirks.py, so logging is redundant here.
#PchumLog.debug(quirkloader.funcre())

View file

@ -1,15 +1,12 @@
# Pesterchum :3c
#!/usr/bin/env python3
import sys
import os
import shutil
import getopt
import configparser
try:
QString = unicode
except NameError:
# Python 3
QString = str
# Python 3
QString = str
if os.path.dirname(sys.argv[0]):
os.chdir(os.path.dirname(sys.argv[0]))
@ -39,12 +36,7 @@ try:
import json
except:
pass
try:
from pnc.attrdict import AttrDict
except ImportError:
# Fall back on the old location - just in case
#PchumLog.warning("Couldn't load attrdict from new loc; falling back")
from pnc.dep.attrdict import AttrDict
from pnc.dep.attrdict import AttrDict
reqmissing = []
optmissing = []

View file

@ -1,11 +1,7 @@
import logging, logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
import logging
import logging.config
import os
import sys
from string import Template
import json
import re
import codecs
@ -13,8 +9,10 @@ import platform
import datetime
import shutil
import zipfile
from string import Template
from datetime import *
from time import strftime, time
from PyQt5 import QtCore, QtGui, QtWidgets
import ostools
@ -23,6 +21,9 @@ from dataobjs import PesterProfile, pesterQuirk, pesterQuirks
from parsetools import convertTags, addTimeInitial, themeChecker, ThemeException
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
class PesterLog(object):
def __init__(self, handle, parent=None):

View file

@ -1,11 +1,18 @@
import logging, logging.config
import os
import sys
import imp
import re
import logging
import logging.config
from PyQt5 import QtCore, QtGui, QtWidgets
import ostools
from quirks import ScriptQuirks
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
import os, sys, imp, re, ostools
from quirks import ScriptQuirks
from PyQt5 import QtCore, QtGui, QtWidgets
class PythonQuirks(ScriptQuirks):
def loadModule(self, name, filename):

View file

@ -1,4 +1,5 @@
import os, socket
import os
import socket
class TwmnError(Exception):
UNWN_ERR = -1

View file

@ -1,10 +1,16 @@
import logging, logging.config
import os
import sys
import re
import logging
import logging.config
from PyQt5 import QtCore, QtGui, QtWidgets
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
import os, sys, re, ostools
from PyQt5 import QtCore, QtGui, QtWidgets
class ScriptQuirks(object):
def __init__(self):

View file

@ -1,9 +1,13 @@
import logging, logging.config
import logging
import logging.config
from PyQt5 import QtCore, QtGui, QtWidgets
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
from PyQt5 import QtCore, QtGui, QtWidgets
RANDNICK = "randomEncounter"

View file

@ -1,18 +1,24 @@
import logging, logging.config
import os
import time
import inspect
import logging
import logging.config
from PyQt5 import QtCore, QtGui, QtWidgets
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
import inspect
#import threading
import time, os
import ostools
from PyQt5 import QtCore, QtGui, QtWidgets
try:
import pynotify
except:
pynotify = None
#try:
# import pynotify
#except:
# pynotify = None
# Pynotify is broken.
pynotify = None
class DefaultToast(object):
def __init__(self, machine, title, msg, icon):