3
0
mirror of https://github.com/jlu5/PyLink.git synced 2025-02-18 22:40:44 +01:00

New import paths for properly installed pylinkirc

This commit is contained in:
James Lu 2016-06-20 18:18:54 -07:00
parent 5f9c14ca18
commit 481d70eff8
25 changed files with 61 additions and 157 deletions

View File

@ -17,10 +17,8 @@ import hashlib
from copy import deepcopy from copy import deepcopy
import inspect import inspect
from log import * from . import world, utils, structures
import world from .log import *
import utils
import structures
### Exceptions ### Exceptions

View File

@ -17,7 +17,7 @@ import yaml
import sys import sys
from collections import defaultdict from collections import defaultdict
import world from . import world
global testconf global testconf
testconf = {'bot': testconf = {'bot':

View File

@ -7,11 +7,8 @@ import sys
import signal import signal
import os import os
import utils from . import utils, conf, classes, world
import conf from .log import log
import classes
from log import log
import world
def _shutdown(irc=None): def _shutdown(irc=None):
"""Shuts down the Pylink daemon.""" """Shuts down the Pylink daemon."""

4
log.py
View File

@ -9,9 +9,9 @@ access the global logger object by importing "log" from this module
import logging import logging
import sys import sys
import os import os
import world
from conf import conf, confname from . import world
from .conf import conf, confname
stdout_level = conf['logging'].get('stdout') or 'INFO' stdout_level = conf['logging'].get('stdout') or 'INFO'

View File

@ -2,13 +2,8 @@
bots.py: Spawn virtual users/bots on a PyLink server and make them interact bots.py: Spawn virtual users/bots on a PyLink server and make them interact
with things. with things.
""" """
from pylinkirc import utils
import sys from pylinkirc.log import log
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import utils
from log import log
@utils.add_cmd @utils.add_cmd
def spawnclient(irc, source, args): def spawnclient(irc, source, args):

View File

@ -1,11 +1,8 @@
""" """
Changehost plugin - automatically changes the hostname of matching users. Changehost plugin - automatically changes the hostname of matching users.
""" """
from pylinkirc import utils, world
# Import hacks to access utils and log. from pylinkirc.log import log
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import string import string
@ -13,10 +10,6 @@ import string
# (pip install ircmatch) # (pip install ircmatch)
import ircmatch import ircmatch
import utils
import world
from log import log
# Characters allowed in a hostname. # Characters allowed in a hostname.
allowed_chars = string.ascii_letters + '-./:' + string.digits allowed_chars = string.ascii_letters + '-./:' + string.digits

View File

@ -1,12 +1,8 @@
# commands.py: base PyLink commands # commands.py: base PyLink commands
import sys
import os
from time import ctime from time import ctime
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__)))) from pylinkirc import utils
import utils from pylinkirc.log import log
from log import log
import world
@utils.add_cmd @utils.add_cmd
def status(irc, source, args): def status(irc, source, args):

View File

@ -1,10 +1,6 @@
# ctcp.py: Handles basic CTCP requests. # ctcp.py: Handles basic CTCP requests.
import sys from pylinkirc import utils
import os from pylinkirc.log import log
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import utils
from log import log
def handle_ctcpversion(irc, source, args): def handle_ctcpversion(irc, source, args):
""" """

View File

@ -1,12 +1,6 @@
# example.py: An example PyLink plugin. # example.py: An example PyLink plugin.
from pylinkirc import utils
# These two lines add PyLink's root directory to the PATH, so that importing things like from pylinkirc.log import log
# 'utils' and 'log' work.
import sys, os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import utils
from log import log
import random import random

View File

@ -2,16 +2,11 @@
exec.py: Provides commands for executing raw code and debugging PyLink. exec.py: Provides commands for executing raw code and debugging PyLink.
""" """
import sys from pylinkirc import utils, world
import os from pylinkirc.log import log
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import utils
from log import log
# These imports are not strictly necessary, but make the following modules # These imports are not strictly necessary, but make the following modules
# easier to access through eval and exec. # easier to access through eval and exec.
import world
import threading import threading
import re import re
import time import time

View File

@ -1,11 +1,6 @@
# fantasy.py: Adds FANTASY command support, to allow calling commands in channels # fantasy.py: Adds FANTASY command support, to allow calling commands in channels
import sys from pylinkirc import utils, world
import os from pylinkirc.log import log
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import utils
import world
from log import log
def handle_fantasy(irc, source, command, args): def handle_fantasy(irc, source, command, args):
"""Fantasy command handler.""" """Fantasy command handler."""

View File

@ -1,18 +1,13 @@
""" """
games.py: Create a bot that provides game functionality (dice, 8ball, etc). games.py: Create a bot that provides game functionality (dice, 8ball, etc).
""" """
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import random import random
import urllib.request import urllib.request
import urllib.error import urllib.error
from xml.etree import ElementTree from xml.etree import ElementTree
import utils from pylinkirc import utils
from log import log from pylinkirc.log import log
import world
gameclient = utils.registerService("Games", manipulatable=True) gameclient = utils.registerService("Games", manipulatable=True)
reply = gameclient.reply # TODO find a better syntax for ServiceBot.reply() reply = gameclient.reply # TODO find a better syntax for ServiceBot.reply()

View File

@ -1,14 +1,8 @@
"""Networks plugin - allows you to manipulate connections to various configured networks.""" """Networks plugin - allows you to manipulate connections to various configured networks."""
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import threading import threading
import utils from pylinkirc import utils, world
import world from pylinkirc.log import log
from log import log
@utils.add_cmd @utils.add_cmd
def disconnect(irc, source, args): def disconnect(irc, source, args):

View File

@ -2,11 +2,6 @@
opercmds.py: Provides a subset of network management commands. opercmds.py: Provides a subset of network management commands.
""" """
import sys
import os
# Add the base PyLink folder to path, so we can import utils and log.
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
# ircmatch library from https://github.com/mammon-ircd/ircmatch # ircmatch library from https://github.com/mammon-ircd/ircmatch
# (pip install ircmatch) # (pip install ircmatch)
try: try:
@ -14,8 +9,8 @@ try:
except ImportError: except ImportError:
ircmatch = None ircmatch = None
import utils from pylinkirc import utils
from log import log from pylinkirc.log import log
@utils.add_cmd @utils.add_cmd
def checkban(irc, source, args): def checkban(irc, source, args):

View File

@ -1,17 +1,12 @@
# relay.py: PyLink Relay plugin # relay.py: PyLink Relay plugin
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
import pickle import pickle
import time import time
import threading import threading
import string import string
from collections import defaultdict from collections import defaultdict
import utils from pylinkirc import utils, world
from log import log from pylinkirc.log import log
import world
### GLOBAL (statekeeping) VARIABLES ### GLOBAL (statekeeping) VARIABLES
relayusers = defaultdict(dict) relayusers = defaultdict(dict)

View File

@ -1,12 +1,8 @@
# servprotect.py: Protects against KILL and nick collision floods # servprotect.py: Protects against KILL and nick collision floods
import sys
import os
sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
from expiringdict import ExpiringDict from expiringdict import ExpiringDict
import utils from pylinkirc import utils
from log import log from pylinkirc.log import log
# TODO: make length and time configurable # TODO: make length and time configurable
savecache = ExpiringDict(max_len=5, max_age_seconds=10) savecache = ExpiringDict(max_len=5, max_age_seconds=10)

View File

@ -3,13 +3,10 @@ import sys
import os import os
import re import re
curdir = os.path.dirname(__file__) from pylinkirc import utils
sys.path += [curdir, os.path.dirname(curdir)] from pylinkirc.log import log
import utils from pylinkirc.classes import *
from log import log from pylinkirc.protocols.ts6 import *
from classes import *
from ts6 import *
class HybridProtocol(TS6Protocol): class HybridProtocol(TS6Protocol):
def __init__(self, irc): def __init__(self, irc):

View File

@ -8,14 +8,10 @@ import os
import re import re
import threading import threading
# Import hacks to access utils and classes... from pylinkirc import utils
curdir = os.path.dirname(__file__) from pylinkirc.classes import *
sys.path += [curdir, os.path.dirname(curdir)] from pylinkirc.log import log
import utils from pylinkirc.protocols.ts6_common import *
from log import log
from classes import *
from ts6_common import *
class InspIRCdProtocol(TS6BaseProtocol): class InspIRCdProtocol(TS6BaseProtocol):
def __init__(self, irc): def __init__(self, irc):

View File

@ -8,13 +8,9 @@ import base64
import struct import struct
from ipaddress import ip_address from ipaddress import ip_address
# Import hacks to access utils and classes... from pylinkirc import utils
curdir = os.path.dirname(__file__) from pylinkirc.classes import *
sys.path += [curdir, os.path.dirname(curdir)] from pylinkirc.log import log
import utils
from log import log
from classes import *
class P10UIDGenerator(utils.IncrementalUIDGenerator): class P10UIDGenerator(utils.IncrementalUIDGenerator):
"""Implements an incremental P10 UID Generator.""" """Implements an incremental P10 UID Generator."""

View File

@ -7,14 +7,10 @@ import sys
import os import os
import re import re
# Import hacks to access utils and classes... from pylinkirc import utils
curdir = os.path.dirname(__file__) from pylinkirc.classes import *
sys.path += [curdir, os.path.dirname(curdir)] from pylinkirc.log import log
import utils from pylinkirc.protocols.ts6_common import *
from log import log
from classes import *
from ts6_common import *
class TS6Protocol(TS6BaseProtocol): class TS6Protocol(TS6BaseProtocol):
def __init__(self, irc): def __init__(self, irc):

View File

@ -6,14 +6,9 @@ import sys
import os import os
import string import string
# Import hacks to access utils and classes... from pylinkirc import utils, structures
curdir = os.path.dirname(__file__) from pylinkirc.classes import *
sys.path += [curdir, os.path.dirname(curdir)] from pylinkirc.log import log
import utils
from log import log
from classes import *
import structures
class TS6SIDGenerator(): class TS6SIDGenerator():
""" """

View File

@ -9,14 +9,10 @@ import codecs
import socket import socket
import re import re
# Import hacks to access utils and classes... from pylinkirc import utils
curdir = os.path.dirname(__file__) from pylinkirc.classes import *
sys.path += [curdir, os.path.dirname(curdir)] from pylinkirc.log import log
from pylinkirc.protocols.ts6_common import *
import utils
from log import log
from classes import *
from ts6_common import *
class UnrealProtocol(TS6BaseProtocol): class UnrealProtocol(TS6BaseProtocol):
def __init__(self, irc): def __init__(self, irc):

13
pylink
View File

@ -1,20 +1,13 @@
#!/usr/bin/env python3 #!/usr/bin/env python3
import os import os
import sys
# Change directory to the folder containing PyLink's source
os.chdir(os.path.dirname(os.path.abspath(__file__)))
# This must be done before conf imports, so we get the real conf instead of testing one. # This must be done before conf imports, so we get the real conf instead of testing one.
import world from pylinkirc import world
world.testing = False world.testing = False
import conf from pylinkirc import conf, classes, utils, coreplugin
from log import log from pylinkirc.log import log
import classes
import utils
import coreplugin
if __name__ == '__main__': if __name__ == '__main__':
log.info('PyLink %s starting...', world.version) log.info('PyLink %s starting...', world.version)

View File

@ -45,7 +45,7 @@ setup(
install_requires=['pyyaml'], install_requires=['pyyaml'],
# Folders (packages of code) # Folders (packages of code)
packages=find_packages(exclude=['log', 'docs', 'tests']), packages=['pylinkirc', 'pylinkirc.protocols', 'pylinkirc.plugins'],
# Single modules. TODO: consider organizing this into a pylink/ folder # Single modules. TODO: consider organizing this into a pylink/ folder
py_modules=["classes", "conf", "coreplugin", "log", "structures", "utils", "world"], py_modules=["classes", "conf", "coreplugin", "log", "structures", "utils", "world"],
@ -55,6 +55,8 @@ setup(
'': ['example-conf.yml'], '': ['example-conf.yml'],
}, },
package_dir = {'pylinkirc': '.'},
# Executable scripts # Executable scripts
scripts=["pylink"], scripts=["pylink"],
) )

View File

@ -11,9 +11,8 @@ import importlib
import os import os
import collections import collections
from log import log from .log import log
import world from . import world, conf
import conf
class NotAuthenticatedError(Exception): class NotAuthenticatedError(Exception):
""" """