switch to 4 space tabs in main phenny module

master
mutantmonkey 2012-02-17 22:10:29 -05:00
parent 09e26155ce
commit 4593a1ae9d
1 changed files with 128 additions and 128 deletions

256
phenny
View File

@ -17,163 +17,163 @@ from textwrap import dedent as trim
dotdir = os.path.expanduser('~/.phenny') dotdir = os.path.expanduser('~/.phenny')
def check_python_version(): def check_python_version():
if sys.version_info < (3, 0): if sys.version_info < (3, 0):
error = 'Error: Requires Python 3.0 or later, from www.python.org' error = 'Error: Requires Python 3.0 or later, from www.python.org'
print(error, file=sys.stderr) print(error, file=sys.stderr)
sys.exit(1) sys.exit(1)
def create_default_config(fn): def create_default_config(fn):
f = open(fn, 'w') f = open(fn, 'w')
print(trim("""\ print(trim("""\
nick = 'phenny' nick = 'phenny'
host = 'irc.example.net' host = 'irc.example.net'
port = 6667 port = 6667
ssl = False ssl = False
ipv6 = False ipv6 = False
channels = ['#example', '#test'] channels = ['#example', '#test']
owner = 'yournickname' owner = 'yournickname'
# password is the NickServ password, serverpass is the server password # password is the NickServ password, serverpass is the server password
# password = 'example' # password = 'example'
# serverpass = 'serverpass' # serverpass = 'serverpass'
# These are people who will be able to use admin.py's functions... # These are people who will be able to use admin.py's functions...
admins = [owner, 'someoneyoutrust'] admins = [owner, 'someoneyoutrust']
# But admin.py is disabled by default, as follows: # But admin.py is disabled by default, as follows:
exclude = ['admin'] exclude = ['admin']
ignore = [''] ignore = ['']
# If you want to enumerate a list of modules rather than disabling # If you want to enumerate a list of modules rather than disabling
# some, use "enable = ['example']", which takes precedent over exclude # some, use "enable = ['example']", which takes precedent over exclude
# #
# enable = [] # enable = []
# Directories to load user modules from # Directories to load user modules from
# e.g. /path/to/my/modules # e.g. /path/to/my/modules
extra = [] extra = []
# Services to load: maps channel names to white or black lists # Services to load: maps channel names to white or black lists
external = { external = {
'#liberal': ['!'], # allow all '#liberal': ['!'], # allow all
'#conservative': [], # allow none '#conservative': [], # allow none
'*': ['!'] # default whitelist, allow all '*': ['!'] # default whitelist, allow all
} }
# EOF # EOF
"""), file=f) """), file=f)
f.close() f.close()
def create_dotdir(dotdir): def create_dotdir(dotdir):
print('Creating a config directory at ~/.phenny...') print('Creating a config directory at ~/.phenny...')
try: os.mkdir(dotdir) try: os.mkdir(dotdir)
except Exception as e: except Exception as e:
print('There was a problem creating %s:' % dotdir, file=sys.stderr) print('There was a problem creating %s:' % dotdir, file=sys.stderr)
print(e.__class__, str(e), file=sys.stderr) print(e.__class__, str(e), file=sys.stderr)
print('Please fix this and then run phenny again.', file=sys.stderr) print('Please fix this and then run phenny again.', file=sys.stderr)
sys.exit(1) sys.exit(1)
print('Creating a default config file at ~/.phenny/default.py...') print('Creating a default config file at ~/.phenny/default.py...')
default = os.path.join(dotdir, 'default.py') default = os.path.join(dotdir, 'default.py')
create_default_config(default) create_default_config(default)
print('Done; now you can edit default.py, and run phenny! Enjoy.') print('Done; now you can edit default.py, and run phenny! Enjoy.')
sys.exit(0) sys.exit(0)
def check_dotdir(): def check_dotdir():
if not os.path.isdir(dotdir): if not os.path.isdir(dotdir):
create_dotdir(dotdir) create_dotdir(dotdir)
def config_names(config): def config_names(config):
config = config or 'default' config = config or 'default'
def files(d): def files(d):
names = os.listdir(d) names = os.listdir(d)
return list(os.path.join(d, fn) for fn in names if fn.endswith('.py')) return list(os.path.join(d, fn) for fn in names if fn.endswith('.py'))
here = os.path.join('.', config) here = os.path.join('.', config)
if os.path.isfile(here): if os.path.isfile(here):
return [here] return [here]
if os.path.isfile(here + '.py'): if os.path.isfile(here + '.py'):
return [here + '.py'] return [here + '.py']
if os.path.isdir(here): if os.path.isdir(here):
return files(here) return files(here)
there = os.path.join(dotdir, config) there = os.path.join(dotdir, config)
if os.path.isfile(there): if os.path.isfile(there):
return [there] return [there]
if os.path.isfile(there + '.py'): if os.path.isfile(there + '.py'):
return [there + '.py'] return [there + '.py']
if os.path.isdir(there): if os.path.isdir(there):
return files(there) return files(there)
print("Error: Couldn't find a config file!", file=sys.stderr) print("Error: Couldn't find a config file!", file=sys.stderr)
print('What happened to ~/.phenny/default.py?', file=sys.stderr) print('What happened to ~/.phenny/default.py?', file=sys.stderr)
sys.exit(1) sys.exit(1)
def main(argv=None): def main(argv=None):
# Step One: Parse The Command Line # Step One: Parse The Command Line
parser = optparse.OptionParser('%prog [options]')
parser.add_option('-c', '--config', metavar='fn',
help='use this configuration file or directory')
opts, args = parser.parse_args(argv)
if args: print('Warning: ignoring spurious arguments', file=sys.stderr)
# Step Two: Check Dependencies
check_python_version() # require python2.4 or later
if not opts.config:
check_dotdir() # require ~/.phenny, or make it and exit
# Step Three: Load The Configurations
config_modules = []
for config_name in config_names(opts.config):
name = os.path.basename(config_name).split('.')[0] + '_config'
module = imp.load_source(name, config_name)
module.filename = config_name
if not hasattr(module, 'prefix'):
module.prefix = r'\.'
if not hasattr(module, 'name'):
module.name = 'Phenny Palmersbot, http://inamidst.com/phenny/'
if not hasattr(module, 'port'):
module.port = 6667
if not hasattr(module, 'ssl'):
module.ssl = False
if not hasattr(module, 'ipv6'):
module.ipv6 = False
parser = optparse.OptionParser('%prog [options]') if not hasattr(module, 'password'):
parser.add_option('-c', '--config', metavar='fn', module.password = None
help='use this configuration file or directory')
opts, args = parser.parse_args(argv)
if args: print('Warning: ignoring spurious arguments', file=sys.stderr)
# Step Two: Check Dependencies if module.host == 'irc.example.net':
error = ('Error: you must edit the config file first!\n' +
"You're currently using %s" % module.filename)
print(error, file=sys.stderr)
sys.exit(1)
check_python_version() # require python2.4 or later config_modules.append(module)
if not opts.config:
check_dotdir() # require ~/.phenny, or make it and exit
# Step Three: Load The Configurations # Step Four: Load Phenny
config_modules = [] try: from __init__ import run
for config_name in config_names(opts.config): except ImportError:
name = os.path.basename(config_name).split('.')[0] + '_config' try: from phenny import run
module = imp.load_source(name, config_name) except ImportError:
module.filename = config_name print("Error: Couldn't find phenny to import", file=sys.stderr)
sys.exit(1)
if not hasattr(module, 'prefix'): # Step Five: Initialise And Run The Phennies
module.prefix = r'\.'
if not hasattr(module, 'name'): # @@ ignore SIGHUP
module.name = 'Phenny Palmersbot, http://inamidst.com/phenny/' for config_module in config_modules:
run(config_module) # @@ thread this
if not hasattr(module, 'port'):
module.port = 6667
if not hasattr(module, 'ssl'):
module.ssl = False
if not hasattr(module, 'ipv6'):
module.ipv6 = False
if not hasattr(module, 'password'):
module.password = None
if module.host == 'irc.example.net':
error = ('Error: you must edit the config file first!\n' +
"You're currently using %s" % module.filename)
print(error, file=sys.stderr)
sys.exit(1)
config_modules.append(module)
# Step Four: Load Phenny
try: from __init__ import run
except ImportError:
try: from phenny import run
except ImportError:
print("Error: Couldn't find phenny to import", file=sys.stderr)
sys.exit(1)
# Step Five: Initialise And Run The Phennies
# @@ ignore SIGHUP
for config_module in config_modules:
run(config_module) # @@ thread this
if __name__ == '__main__': if __name__ == '__main__':
main() main()