-
Notifications
You must be signed in to change notification settings - Fork 6
halibot: add optional config, configfile argument to core #113
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -33,8 +33,6 @@ class Halibot(): | |
|
|
||
| VERSION = "0.2.0" | ||
|
|
||
| config = {} | ||
|
|
||
| running = False | ||
| log = None | ||
|
|
||
|
|
@@ -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", {}) | ||
| if self.config: | ||
| halibot.packages.__path__ = self.config.get("package-path", []) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() | ||
|
|
@@ -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) | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Follow up |
||
| self._instantiate_objects("agent") | ||
| self._instantiate_objects("module") | ||
| if self.use_auth: | ||
|
|
@@ -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)) | ||
|
|
||
|
|
||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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 updatehalibot.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