From 4a275db4d38c8ab9ee4128103fd4829cbad53934 Mon Sep 17 00:00:00 2001 From: makefu Date: Fri, 4 Sep 2015 22:08:40 +0200 Subject: config: more logic in config file :( --- reaktor/__init__.py | 1 + reaktor/commands/version | 27 ++++++++++++++++++ reaktor/config.py | 74 ++++++++++++++++++++++++------------------------ setup.py | 3 +- 4 files changed, 67 insertions(+), 38 deletions(-) create mode 100755 reaktor/commands/version diff --git a/reaktor/__init__.py b/reaktor/__init__.py index e69de29..4fe60b4 100644 --- a/reaktor/__init__.py +++ b/reaktor/__init__.py @@ -0,0 +1 @@ +__version__="0.4.0" diff --git a/reaktor/commands/version b/reaktor/commands/version new file mode 100755 index 0000000..ff3c48f --- /dev/null +++ b/reaktor/commands/version @@ -0,0 +1,27 @@ +#!/usr/bin/env python + +url="https://pypi.python.org/pypi/Reaktor/json" +import requests +import reaktor +cur_version = reaktor.__version__ + +ret = requests.get(url).json() +latest_version = ret["info"]["version"] + +def vt(v): + return tuple(map(int, (v.split(".")))) + +try: + rel = ret["releases"][cur_version][0]["upload_time"] +except: + rel = "unknown release date" +print("{} - {}".format(cur_version,rel)) +if vt(latest_version) > vt(cur_version): + print(" newer release available: {}".format(latest_version)) +elif vt(latest_version) < vt(cur_version): + print(" ahead of official release: {}".format(latest_version)) +else: + # on the most current release + pass + + diff --git a/reaktor/config.py b/reaktor/config.py index 56ef71e..7f4837c 100644 --- a/reaktor/config.py +++ b/reaktor/config.py @@ -2,45 +2,45 @@ import os from os.path import abspath, expanduser,dirname,join import reaktor # to get the path to the reaktor basedir import re +env = os.environ -debug = True +# TODO: put this somewhere else +def str2bool(v): + return v.lower() in ("yes", "true", "t", "1") +#### ENVIRON CONFIG +# this provides a simple means of reconfiguring this config without the need to +# copy-paste the whole thing +debug = str2bool(env.get('REAKTOR_DEBUG',"False")) # IRC_NICKNAME is set if the nick changes and the config is getting reloaded +name = env.get('REAKTOR_NICKNAME','crabmanner') +irc_server = env.get('REAKTOR_HOST','irc.freenode.org') +irc_port = int(env.get('REAKTOR_PORT',6667)) # TODO: do not implement functionality in the config :\ -name = os.environ.get('IRC_NICKNAME','crabmanner') +workdir = env.get('REAKTOR_STATEDIR',expanduser('~') + '/state') +irc_channels = env.get('REAKTOR_CHANNELS','#krebs').split(',') +#### static config +# if you want to change this part you have to copy the config +irc_alarm_timeout = 300 +irc_hammer_interval = 10 +irc_kill_timeout = 360 +irc_nickname = name +irc_restart_timeout = 5 -#workdir = './state' -workdir = expanduser('~') + '/state' +#### IMPLEMENTATION +# this config contains the implementation of how commands should match # TODO: YAY more functionality in config.py .. +# create the workdir somewhere # else in the code ... # if this fails the bot will fail (which is ok) if not os.path.isdir(workdir): os.makedirs(workdir) - - -irc_alarm_timeout = 300 -irc_hammer_interval = 10 -irc_kill_timeout = 360 -irc_nickname = name -irc_server = 'irc.freenode.org' -irc_port = 6667 -irc_restart_timeout = 5 -irc_channels = [ - '#krebs' -] admin_file=workdir+'/admin.lst' auth_file=workdir+'/auth.lst' -nag_env={ - 'hosts_repo': 'https://github.com/krebscode/hosts', - 'services_repo': 'gitolite@localhost:services', - 'inspect_services': 'false' -} - config_filename = abspath(__file__) - mod_dir=dirname(abspath(reaktor.__file__)) # the commands dirname ( dist_dir = abspath(join(mod_dir)) @@ -49,16 +49,18 @@ dist_dir = abspath(join(mod_dir)) # TODO: name may change after reconnect, then this pattern fails to match # this may need a complete refactor of how to create patterns and matches + +## IMPLEMENTATION + me = '\\b' + re.escape(name) + '\\b' me_or_us = '(?:' + me + '|\\*)' +indirect_pattern='^'+me_or_us+':\\s*{}\\s*(?:\\s+(?P.*))?$' def distc(cmd): - """ builds a path to a cmd in the distribution command folder""" + """ builds a path to a cmd in the command folder of the Reaktor distribution""" return join(dist_dir,"commands",cmd) -# using partial formatting {{}} -indirect_pattern='^{}:\\s*{{}}\\s*(?:\\s+(?P.*))?$'.format(me_or_us) def default_command(cap, cmd=None, env=None): """ (botname|*): cmd args @@ -90,32 +92,33 @@ def simple_command(cap, cmd=None, env=None): 'env': env } +# unauthenticated commands public_commands = [ default_command('caps', env={ 'config_filename': config_filename }), default_command('hello'), default_command('badcommand'), - default_command('rev'), + #default_command('rev'), # TODO: when uploaded to pypi the rev gets lost + default_command('version'), default_command('uptime'), default_command('nocommand'), default_command('tell', cmd='tell-on_privmsg', env={ 'state_file': workdir + '/tell.txt' }), - # TODO this is disabled until someone fixes it - #default_command('nag', env=nag_env), simple_command('identify', env={ 'config_filename': config_filename }), # command not found - { 'pattern': '^' + me_or_us + ':.*', - 'argv': [ distc('respond'),'You are made of stupid!'] }, + #{ 'pattern': '^' + me_or_us + ':.*', + # 'argv': [ distc('respond'),'You are made of stupid!'] }, # "highlight" { 'pattern': '.*' + me + '.*', 'argv': [ distc('say'), 'I\'m famous' ] }, # identify via direct connect ] +# authenticated commands commands = [ default_command('reload'), ] @@ -128,11 +131,8 @@ on_join = [ } ] +# Timer on_ping = [ - { - 'capname': 'nag', - 'argv': [ distc('nag') ], - 'env': nag_env, - 'targets': irc_channels - } ] + +## END IMPLEMENTATION diff --git a/setup.py b/setup.py index 7b78171..e96568f 100644 --- a/setup.py +++ b/setup.py @@ -1,9 +1,10 @@ import sys from setuptools import setup +import reaktor setup( name='Reaktor', - version='0.3.2', + version=reaktor.__version__, description='an IRC bot based on asyn* libs', long_description=open("README.md").read(), -- cgit v1.2.3