Support optional command-line argument specifying full path to conf file.
This commit is contained in:
parent
a907737aa6
commit
6191182cb3
1 changed files with 15 additions and 1 deletions
16
rtmbot.py
16
rtmbot.py
|
@ -10,6 +10,7 @@ import os
|
||||||
import sys
|
import sys
|
||||||
import time
|
import time
|
||||||
import logging
|
import logging
|
||||||
|
from argparse import ArgumentParser
|
||||||
|
|
||||||
from slackclient import SlackClient
|
from slackclient import SlackClient
|
||||||
|
|
||||||
|
@ -164,14 +165,27 @@ def main_loop():
|
||||||
except:
|
except:
|
||||||
logging.exception('OOPS')
|
logging.exception('OOPS')
|
||||||
|
|
||||||
|
|
||||||
|
def parse_args():
|
||||||
|
parser = ArgumentParser()
|
||||||
|
parser.add_argument(
|
||||||
|
'-c',
|
||||||
|
'--config',
|
||||||
|
help='Full path to config file.',
|
||||||
|
metavar='path'
|
||||||
|
)
|
||||||
|
return parser.parse_args()
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
args = parse_args()
|
||||||
directory = os.path.dirname(sys.argv[0])
|
directory = os.path.dirname(sys.argv[0])
|
||||||
if not directory.startswith('/'):
|
if not directory.startswith('/'):
|
||||||
directory = os.path.abspath("{}/{}".format(os.getcwd(),
|
directory = os.path.abspath("{}/{}".format(os.getcwd(),
|
||||||
directory
|
directory
|
||||||
))
|
))
|
||||||
|
|
||||||
config = yaml.load(file('rtmbot.conf', 'r'))
|
config = yaml.load(file(args.config or 'rtmbot.conf', 'r'))
|
||||||
debug = config["DEBUG"]
|
debug = config["DEBUG"]
|
||||||
bot = RtmBot(config["SLACK_TOKEN"])
|
bot = RtmBot(config["SLACK_TOKEN"])
|
||||||
site_plugins = []
|
site_plugins = []
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue