Skip to content

Commit

Permalink
getopt --> argparse, redid logging, code cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Dpeta committed Sep 6, 2022
1 parent 45320c9 commit ef0898e
Show file tree
Hide file tree
Showing 19 changed files with 224 additions and 347 deletions.
8 changes: 7 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Changelog
(This document uses YYYY-MM-DD)

## [v2.4.3] - 2022-09-05
## [v2.4.3] - 2022-09-06

### Added
- Support for color via IRCv3 metadata draft.
Expand All @@ -11,10 +11,16 @@
### Changed
- Reenabled server certificate validation when using SSL.
- Uses the system's local certificates, so might fail on some installations.
- Redid command-line handling with the argparse module instead of getopt.
- Restructured imports & data directory checks in pesterchum.py

### Fixed
- Error when setting quirk with PyQt5.

### Depreciated
- Disabled the console for now since no one seems to use it and it caused an issue on import.
- Logging.config/configparser logging configuration, not aware of anyone that actually used this. Logging level can still be specified with command line arguments. (-l --logging)

## [v2.4.2] - 2022-08-14

### Added
Expand Down
4 changes: 0 additions & 4 deletions console.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import time
import datetime
import logging
import logging.config

try:
from PyQt6 import QtCore, QtGui, QtWidgets
Expand All @@ -25,11 +24,8 @@
#from version import _pcVersion
from pnc.dep.attrdict import AttrDict

_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')


class ConsoleWindow(QtWidgets.QDialog):
#~class ConsoleWindow(styler.PesterBaseWindow):
# A simple console class, cobbled together from the corpse of another.
Expand Down
10 changes: 5 additions & 5 deletions convo.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import sys
import logging
import logging.config
from string import Template
from time import strftime
from datetime import datetime, timedelta
Expand All @@ -15,14 +14,15 @@

import ostools
from dataobjs import PesterHistory
from parsetools import (convertTags, lexMessage, mecmd, colorBegin, colorEnd,
from parsetools import (convertTags,
lexMessage,
mecmd,
colorBegin,
colorEnd,
smiledict)
import parsetools
from pnc.dep.attrdict import AttrDict


_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')

class PesterTabWindow(QtWidgets.QFrame):
Expand Down
3 changes: 0 additions & 3 deletions dataobjs.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,5 @@
import logging
import logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
try:
from PyQt6 import QtGui
Expand Down
3 changes: 0 additions & 3 deletions irc.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import logging.config
import socket
import random
import time
Expand All @@ -22,8 +21,6 @@
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
Expand Down
3 changes: 0 additions & 3 deletions luaquirks.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
+ 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
Expand All @@ -15,8 +14,6 @@
import ostools
from quirks import ScriptQuirks
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
try:
Expand Down
4 changes: 0 additions & 4 deletions memos.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import logging.config
import re
from string import Template
from datetime import timedelta, datetime
Expand All @@ -21,8 +20,6 @@
mecmd, smiledict)
from logviewer import PesterLogViewer

_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')

# Python 3
Expand Down Expand Up @@ -412,7 +409,6 @@ def __init__(self, channel, timestr, mainwindow, parent=None):

self.textArea = MemoText(self.mainwindow.theme, self)
self.textInput = MemoInput(self.mainwindow.theme, self)
print(self.textInput)
self.textInput.setFocus()

self.miniUserlist = QtWidgets.QPushButton(">\n>", self)
Expand Down
26 changes: 24 additions & 2 deletions ostools.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import os
import sys
import platform

try:
from PyQt6.QtCore import QStandardPaths
except ImportError:
Expand Down Expand Up @@ -32,6 +32,27 @@ def osVer():
elif isLinux():
return " ".join(platform.linux_distribution())

def validateDataDir():
"""Checks if data directory is present"""
# Define paths
datadir = getDataDir()
profile = os.path.join(datadir, "profiles")
quirks = os.path.join(datadir, "quirks")
logs = os.path.join(datadir, "logs")
errorlogs = os.path.join(datadir, "errorlogs")
backup = os.path.join(datadir, "backup")
js_pchum = os.path.join(datadir, "pesterchum.js")

dirs = [datadir, profile, quirks, logs, errorlogs, backup]
for d in dirs:
if (os.path.isdir(d) == False) or (os.path.exists(d) == False):
os.makedirs(d, exist_ok=True)

# pesterchum.js
if not os.path.exists(js_pchum):
with open(js_pchum, 'w') as f:
f.write("{}")

def getDataDir():
# Temporary fix for non-ascii usernames
# If username has non-ascii characters, just store userdata
Expand All @@ -43,5 +64,6 @@ def getDataDir():
return os.path.join(QStandardPaths.writableLocation(QStandardPaths.StandardLocation.HomeLocation), ".pesterchum/")
else:
return os.path.join(QStandardPaths.writableLocation(QStandardPaths.StandardLocation.AppLocalDataLocation), "pesterchum/")
except UnicodeDecodeError:
except UnicodeDecodeError as e:
print(e)
return ''
6 changes: 1 addition & 5 deletions oyoyo/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,6 @@
# THE SOFTWARE.

import logging
import logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')

import logging
Expand Down Expand Up @@ -326,7 +322,7 @@ def conn(self):

for el in data:
tags, prefix, command, args = parse_raw_irc_command(el)
print(tags, prefix, command, args)
#print(tags, prefix, command, args)
try:
# Only need tags with tagmsg
if command.upper() == "TAGMSG":
Expand Down
9 changes: 2 additions & 7 deletions oyoyo/cmdhandler.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,18 +15,13 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
import logging
import logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')

import inspect
import logging

from oyoyo import helpers
from oyoyo.parse import parse_nick

PchumLog = logging.getLogger('pchumLogger')

def protected(func):
""" decorator to protect functions from being called """
func.protected = True
Expand Down
7 changes: 2 additions & 5 deletions oyoyo/helpers.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,13 +18,10 @@
""" contains helper functions for common irc commands """

import logging
import logging.config
import ostools
_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')
import random

PchumLog = logging.getLogger('pchumLogger')

def msg(cli, user, msg):
for line in msg.split('\n'):
cli.send("PRIVMSG", user, ":%s" % line)
Expand Down
4 changes: 0 additions & 4 deletions oyoyo/parse.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,9 @@
# THE SOFTWARE.

import logging
import logging.config

import ostools
from oyoyo.ircevents import numeric_events

_datadir = ostools.getDataDir()
logging.config.fileConfig(_datadir + "logging.ini")
PchumLog = logging.getLogger('pchumLogger')

def parse_raw_irc_command(element):
Expand Down
21 changes: 10 additions & 11 deletions parsetools.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import logging
import logging.config
import re
import collections
from copy import copy
Expand All @@ -20,8 +19,6 @@
from pyquirks import PythonQuirks
#from luaquirks import LuaQuirks

_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
Expand All @@ -42,16 +39,18 @@
_format_begin = re.compile(r'(?i)<([ibu])>')
_format_end = re.compile(r'(?i)</([ibu])>')
_honk = re.compile(r"(?i)\bhonk\b")
_groupre = re.compile(r"\\([0-9]+)")

quirkloader = ScriptQuirks()
quirkloader.add(PythonQuirks())
#quirkloader.add(LuaQuirks())
quirkloader.loadAll()
# Quirks are already listed in quirks.py, so logging is redundant here.
#PchumLog.debug(quirkloader.funcre())
quirkloader.funcre()
_functionre = re.compile(r"%s" % quirkloader.funcre())
_groupre = re.compile(r"\\([0-9]+)")
_functionre = None

def loadQuirks():
global quirkloader, _functionre
quirkloader.add(PythonQuirks())
#quirkloader.add(LuaQuirks())
quirkloader.loadAll()
quirkloader.funcre()
_functionre = re.compile(r"%s" % quirkloader.funcre())

def reloadQuirkFunctions():
quirkloader.loadAll()
Expand Down
Loading

0 comments on commit ef0898e

Please sign in to comment.