forked from vavrusa/notifypy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
notify.py
executable file
·43 lines (36 loc) · 1.14 KB
/
notify.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
#!/usr/bin/env python
# -*- coding: utf-8 -*-
import ConfigParser, os
import api, modules
# Defaults
config_path = '~/.notifypy.cfg'
# Read configuration
header = 'NotifyPy (configuration: %s)' % config_path
print header
print ''.center(len(header), '-')
cfg = ConfigParser.ConfigParser()
if len(cfg.read(os.path.expanduser(config_path))) is 0:
# Initialize default config
cfg.read('default.cfg')
with open(os.path.expanduser(config_path), 'wb') as cfgout:
cfg.write(cfgout)
print 'Creating config \'%s\' ...' % config_path
# Check first run
if cfg.has_option('Global', 'first-run'):
print '[!!] Please remove \'first-run\' option before use.'
exit(1)
# Load APIs
api_list = cfg.get('Global', 'api').split(' ')
print 'Loading APIs (%s) ...' % ' '.join(api_list)
notificator = api.Notificator(cfg)
for api_id in api_list:
notificator.load(api_id)
# Load modules
mod_list = cfg.get('Global', 'modules').split(' ')
print 'Loading modules (%s) ...' % ' '.join(mod_list)
manager = modules.Manager(cfg, notificator)
for mod_id in mod_list:
manager.load(mod_id)
# Run modules
print 'Running %i modules.' % len(manager.list)
manager.run()