Restructure contrib_bots bots to new layout.

In order to make the layout of all bots consistent, this commit
moves each bot into a folder with its name and modifies 'run.py'
so that only bots with such a structure can be executed. 'lib'
gets renamed to 'bots'.
This commit is contained in:
Robert Hönig 2017-01-22 10:38:34 +00:00 committed by showell
parent dd4ea5e56e
commit 4415d6085f
58 changed files with 21 additions and 24 deletions

View File

@ -17,7 +17,7 @@ the user home directory and add an API key.
Move
```
~/zulip/contrib_bots/lib/CommuteBot/google-commute.ini
~/zulip/contrib_bots/bots/commute_bot/CommuteBot/google-commute.ini
```
into

View File

@ -62,7 +62,9 @@ class CommuteHandler(object):
Please note:
Fare information can be derived, though is solely dependent on the
availability of the informatipython run.py lib/followup.py --config-file ~/.zuliprc-localon released by public transport operators.
availability of the information
python run.py bots/followup/followup.py --config-file ~/.zuliprc-local
released by public transport operators.
Duration in traffic can only be derived if a departure time is set.
If a location has spaces in its name, please use a + symbol in the
place of the space/s.
@ -88,7 +90,7 @@ class CommuteHandler(object):
# adds API Authentication Key to url request
def get_api_key(self):
# google-commute.ini must have been moved from
# ~/zulip/contrib_bots/lib/CommuteBot/google-commute.ini into
# ~/zulip/contrib_bots/bots/commute_bot/CommuteBot/google-commute.ini into
# /google-commute.ini for program to work
# see doc.md for more information
with open(CONFIG_PATH) as settings:

View File

Before

Width:  |  Height:  |  Size: 54 KiB

After

Width:  |  Height:  |  Size: 54 KiB

View File

Before

Width:  |  Height:  |  Size: 73 KiB

After

Width:  |  Height:  |  Size: 73 KiB

View File

Before

Width:  |  Height:  |  Size: 19 KiB

After

Width:  |  Height:  |  Size: 19 KiB

View File

Before

Width:  |  Height:  |  Size: 287 KiB

After

Width:  |  Height:  |  Size: 287 KiB

View File

Before

Width:  |  Height:  |  Size: 180 KiB

After

Width:  |  Height:  |  Size: 180 KiB

View File

Before

Width:  |  Height:  |  Size: 160 KiB

After

Width:  |  Height:  |  Size: 160 KiB

View File

Before

Width:  |  Height:  |  Size: 170 KiB

After

Width:  |  Height:  |  Size: 170 KiB

View File

@ -9,11 +9,11 @@ from six.moves import configparser as cp
from six.moves import range
home = expanduser('~')
CONFIG_PATH = home + '/zulip/contrib_bots/lib/FourSquareBot/settings.ini'
CONFIG_PATH = home + '/zulip/contrib_bots/bots/foursquare/FourSquareBot/settings.ini'
def get_api_key():
# settings.ini must have been moved from
# ~/zulip/contrib_bots/lib/FourSquareBot/settings.ini into
# ~/zulip/contrib_bots/bots/foursquare/FourSquareBot/settings.ini into
# ~/settings.ini for program to work
# see doc.md for more information
with open(CONFIG_PATH) as settings:

View File

@ -27,7 +27,7 @@ Here is an example of running the `git_hub_comment` bot from
inside a Zulip repo:
`cd ~/zulip/contrib_bots`
`./run.py lib/git_hub_comment.py --config-file ~/.zuliprc-prod`
`./run.py bots/git_hub_comment/git_hub_comment.py --config-file ~/.zuliprc-prod`
Once the bot code starts running, you will see a
message explaining how to use the bot, as well as

View File

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

View File

Before

Width:  |  Height:  |  Size: 56 KiB

After

Width:  |  Height:  |  Size: 56 KiB

View File

Before

Width:  |  Height:  |  Size: 9.0 KiB

After

Width:  |  Height:  |  Size: 9.0 KiB

View File

Before

Width:  |  Height:  |  Size: 6.9 KiB

After

Width:  |  Height:  |  Size: 6.9 KiB

View File

Before

Width:  |  Height:  |  Size: 83 KiB

After

Width:  |  Height:  |  Size: 83 KiB

View File

Before

Width:  |  Height:  |  Size: 49 KiB

After

Width:  |  Height:  |  Size: 49 KiB

View File

Before

Width:  |  Height:  |  Size: 64 KiB

After

Width:  |  Height:  |  Size: 64 KiB

View File

@ -33,7 +33,7 @@ Here is an example of running the "follow-up" bot from
inside a Zulip repo (and in your remote instance):
cd ~/zulip/contrib_bots
./run.py lib/followup.py --config-file ~/.zuliprc-prod
./run.py bots/followup/followup.py --config-file ~/.zuliprc-prod
Once the bot code starts running, you will see a
message explaining how to use the bot, as well as

View File

@ -1,4 +1,4 @@
# See zulip/contrib_bots/lib/readme.md for instructions on running this code.
# See zulip/contrib_bots/bots/readme.md for instructions on running this code.
from __future__ import print_function
import sys
import logging

View File

Before

Width:  |  Height:  |  Size: 30 KiB

After

Width:  |  Height:  |  Size: 30 KiB

View File

Before

Width:  |  Height:  |  Size: 43 KiB

After

Width:  |  Height:  |  Size: 43 KiB

View File

Before

Width:  |  Height:  |  Size: 45 KiB

After

Width:  |  Height:  |  Size: 45 KiB

View File

Before

Width:  |  Height:  |  Size: 44 KiB

After

Width:  |  Height:  |  Size: 44 KiB

View File

Before

Width:  |  Height:  |  Size: 31 KiB

After

Width:  |  Height:  |  Size: 31 KiB

View File

Before

Width:  |  Height:  |  Size: 14 KiB

After

Width:  |  Height:  |  Size: 14 KiB

View File

@ -55,7 +55,7 @@ Here is an example of running the "yoda_bot" bot from
inside a Zulip repo:
cd ~/zulip/contrib_bots
./run.py lib/yoda_bot.py --config-file ~/.zuliprc-prod
./run.py bots/yoda_bot/yoda_bot.py --config-file ~/.zuliprc-prod
Once the bot code starts running, you will see a
message explaining how to use the bot, as well as

View File

Before

Width:  |  Height:  |  Size: 229 KiB

After

Width:  |  Height:  |  Size: 229 KiB

View File

@ -12,36 +12,31 @@ sys.path.insert(0, our_dir)
from bot_lib import run_message_handler_for_bot
def get_lib_module(lib_fn):
lib_fn = os.path.abspath(lib_fn)
if not os.path.dirname(lib_fn).startswith(os.path.join(our_dir, 'lib')):
print('Sorry, we will only import code from contrib_bots/lib.')
def get_lib_module(bots_fn):
bots_fn = os.path.abspath(bots_fn)
if not os.path.dirname(bots_fn).startswith(os.path.join(our_dir, 'bots')):
print('Sorry, we will only import code from contrib_bots/bots.')
sys.exit(1)
if not lib_fn.endswith('.py'):
if not bots_fn.endswith('.py'):
print('Please use a .py extension for library files.')
sys.exit(1)
sys.path.append('lib')
base_lib_fn = os.path.basename(os.path.splitext(lib_fn)[0])
module_name = 'lib.' + base_lib_fn
base_bots_fn = os.path.basename(os.path.splitext(bots_fn)[0])
sys.path.append('bots/{}'.format(base_bots_fn))
module_name = base_bots_fn
module = importlib.import_module(module_name)
return module
def run():
usage = '''
./run.py <lib file>
Example: ./run.py lib/followup.py
(This program loads bot-related code from the
library code and then runs a message loop,
feeding messages to the library code to handle.)
Please make sure you have a current ~/.zuliprc
file with the credentials you want to use for
this bot.
See lib/readme.md for more context.
'''
@ -58,7 +53,7 @@ def run():
print('You must specify a library!')
sys.exit(1)
lib_module = get_lib_module(lib_fn=args[0])
lib_module = get_lib_module(bots_fn=args[0])
if not options.quiet:
logging.basicConfig(stream=sys.stdout, level=logging.INFO)

View File

@ -457,7 +457,7 @@ def build_custom_checkers(by_lang):
failed = True
markdown_docs_length_exclude = {
"contrib_bots/lib/ConverterBot/docs.md",
"contrib_bots/bots/converter/ConverterBot/docs.md",
"docs/bots-guide.md",
"docs/dev-env-first-time-contributors.md",
"docs/integration-guide.md",