Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 11 additions & 7 deletions halibot/halibot.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,6 @@ class Halibot():

VERSION = "0.2.0"

config = {}

running = False
log = None

Expand All @@ -44,6 +42,11 @@ def __init__(self, **kwargs):
self.use_config = kwargs.get("use_config", True)
self.use_auth = kwargs.get("use_auth", True)
self.workdir = kwargs.get("workdir", ".")
self.config = kwargs.get("config", {})

@richteer richteer Oct 1, 2018

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Issue here: When we load a config from a file via ._load_config, we update halibot.packages.__path__. If a config is supplied, that step is skipped. Will fix in next edit as well, just need to check if we are supplied a config and update the path accordingly.

update: should be fixed now

if self.config:
halibot.packages.__path__ = self.config.get("package-path", [])

@sjrct sjrct Feb 6, 2019

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With #126 lines 46-47 should not be needed as that assignment is done automatically


self.configfile = kwargs.get("configfile", "config.json")

self.auth = HalAuth()
self.objects = ObjectDict()
Expand All @@ -53,7 +56,8 @@ def start(self, block=True):
self.running = True

if self.use_config:
self._load_config()
if not self.config:
self._load_config(configfile=self.configfile)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Forgot to mention this in the description, but I have it here skip loading the config if it was already defined. We may want to change this behavior, but I figure if someone is calling .start(), they can also call ._load_config as well.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Follow up TODO item: we should really consider config.json validation.

self._instantiate_objects("agent")
self._instantiate_objects("module")
if self.use_auth:
Expand Down Expand Up @@ -89,13 +93,13 @@ def add_instance(self, name, inst):
inst.init()
self.log.info("Instantiated object '" + name + "'")

def _load_config(self):
with open(os.path.join(self.workdir, "config.json"), "r") as f:
def _load_config(self, configfile="config.json"):
with open(os.path.join(self.workdir, configfile), "r") as f:
self.config = json.loads(f.read())
halibot.packages.__path__ = self.config.get("package-path", [])

def _write_config(self):
with open(os.path.join(self.workdir, "config.json"), "w") as f:
def _write_config(self, configfile="config.json"):
with open(os.path.join(self.workdir, configfile), "w") as f:
f.write(json.dumps(self.config, sort_keys=True, indent=4))


Expand Down