diff options
Diffstat (limited to 'warmachine')
| -rw-r--r-- | warmachine/addons/base.py | 1 | ||||
| -rw-r--r-- | warmachine/addons/standup.py | 15 | ||||
| -rw-r--r-- | warmachine/connections/base.py | 3 | ||||
| -rw-r--r-- | warmachine/connections/irc.py | 1 |
4 files changed, 18 insertions, 2 deletions
diff --git a/warmachine/addons/base.py b/warmachine/addons/base.py index 0a02df7..d67500f 100644 --- a/warmachine/addons/base.py +++ b/warmachine/addons/base.py | |||
| @@ -6,6 +6,7 @@ class WarMachinePlugin(object): | |||
| 6 | def __init__(self, *args, **kwargs): | 6 | def __init__(self, *args, **kwargs): |
| 7 | self._loop = asyncio.get_event_loop() | 7 | self._loop = asyncio.get_event_loop() |
| 8 | self.log = logging.getLogger(self.__class__.__name__) | 8 | self.log = logging.getLogger(self.__class__.__name__) |
| 9 | self.config_dir = kwargs.pop('config_dir', None) | ||
| 9 | 10 | ||
| 10 | def recv_msg(self, *args, **kwargs): | 11 | def recv_msg(self, *args, **kwargs): |
| 11 | """ | 12 | """ |
diff --git a/warmachine/addons/standup.py b/warmachine/addons/standup.py index 6ee6378..aa7fda6 100644 --- a/warmachine/addons/standup.py +++ b/warmachine/addons/standup.py | |||
| @@ -2,6 +2,7 @@ import asyncio | |||
| 2 | from datetime import datetime, timedelta | 2 | from datetime import datetime, timedelta |
| 3 | import functools | 3 | import functools |
| 4 | import json | 4 | import json |
| 5 | import os | ||
| 5 | from pprint import pformat | 6 | from pprint import pformat |
| 6 | 7 | ||
| 7 | from .base import WarMachinePlugin | 8 | from .base import WarMachinePlugin |
| @@ -20,6 +21,7 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 20 | !standup-schedules | 21 | !standup-schedules |
| 21 | !standup-waiting_replies | 22 | !standup-waiting_replies |
| 22 | """ | 23 | """ |
| 24 | SETTINGS_FILENAME = 'standup_schedules.json' | ||
| 23 | def __init__(self, *args, **kwargs): | 25 | def __init__(self, *args, **kwargs): |
| 24 | super().__init__(*args, **kwargs) | 26 | super().__init__(*args, **kwargs) |
| 25 | 27 | ||
| @@ -38,6 +40,15 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 38 | self.users_awaiting_reply = {} | 40 | self.users_awaiting_reply = {} |
| 39 | self.log.info('Loaded standup plugin') | 41 | self.log.info('Loaded standup plugin') |
| 40 | 42 | ||
| 43 | self.settings_file = os.path.join( | ||
| 44 | self.config_dir, self.SETTINGS_FILENAME) | ||
| 45 | |||
| 46 | if not os.path.exists(self.settings_file): | ||
| 47 | self.log.info('Creating standup config file: {}'.format( | ||
| 48 | self.settings_file)) | ||
| 49 | with open(self.settings_file, 'w') as f: | ||
| 50 | f.write('{}') | ||
| 51 | |||
| 41 | def on_connect(self, connection): | 52 | def on_connect(self, connection): |
| 42 | self.load_schedule(connection) | 53 | self.load_schedule(connection) |
| 43 | 54 | ||
| @@ -416,7 +427,7 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 416 | data[channel][key] = self.standup_schedules[channel][key] | 427 | data[channel][key] = self.standup_schedules[channel][key] |
| 417 | 428 | ||
| 418 | data = {connection.id: data} | 429 | data = {connection.id: data} |
| 419 | with open('/home/jason/.warmachine/standup_schedules.json', 'w') as f: | 430 | with open(self.settings_file, 'w') as f: |
| 420 | f.write(json.dumps(data)) | 431 | f.write(json.dumps(data)) |
| 421 | 432 | ||
| 422 | self.log.info('Schedules saved to disk') | 433 | self.log.info('Schedules saved to disk') |
| @@ -425,7 +436,7 @@ class StandUpPlugin(WarMachinePlugin): | |||
| 425 | """ | 436 | """ |
| 426 | Load the channel schedules from a file. | 437 | Load the channel schedules from a file. |
| 427 | """ | 438 | """ |
| 428 | with open('/home/jason/.warmachine/standup_schedules.json', 'r') as f: | 439 | with open(self.settings_file, 'r') as f: |
| 429 | try: | 440 | try: |
| 430 | data = json.loads(f.read()) | 441 | data = json.loads(f.read()) |
| 431 | except Exception as e: | 442 | except Exception as e: |
diff --git a/warmachine/connections/base.py b/warmachine/connections/base.py index e787e35..56ce108 100644 --- a/warmachine/connections/base.py +++ b/warmachine/connections/base.py | |||
| @@ -3,6 +3,9 @@ CONNECTED = 'Connected' | |||
| 3 | 3 | ||
| 4 | 4 | ||
| 5 | class Connection(object): | 5 | class Connection(object): |
| 6 | def __init__(self): | ||
| 7 | self.config_dir = None | ||
| 8 | |||
| 6 | def connect(self, *args, **kwargs): | 9 | def connect(self, *args, **kwargs): |
| 7 | """ | 10 | """ |
| 8 | This is called by the main start method. It should prepare your | 11 | This is called by the main start method. It should prepare your |
diff --git a/warmachine/connections/irc.py b/warmachine/connections/irc.py index 86068d7..542ba62 100644 --- a/warmachine/connections/irc.py +++ b/warmachine/connections/irc.py | |||
| @@ -7,6 +7,7 @@ from ..utils.decorators import memoize | |||
| 7 | 7 | ||
| 8 | class AioIRC(Connection): | 8 | class AioIRC(Connection): |
| 9 | def __init__(self, host, port): | 9 | def __init__(self, host, port): |
| 10 | super().__init__() | ||
| 10 | self._loop = asyncio.get_event_loop() | 11 | self._loop = asyncio.get_event_loop() |
| 11 | self.log = logging.getLogger(self.__class__.__name__) | 12 | self.log = logging.getLogger(self.__class__.__name__) |
| 12 | 13 | ||