-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmyflexget.py
76 lines (55 loc) · 1.91 KB
/
myflexget.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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
from flask import Flask
import os
import sys
app = Flask(__name__)
app.secret_key = 'randomshitfacereggie' # os.urandom(24)
app_folder = os.path.dirname(os.path.abspath(__file__))
#Remove whitespace
app.jinja_env.trim_blocks = True
app.jinja_env.lstrip_blocks = True
_menu = []
#########################################
### Debug log
#########################################
class MyOutput():
def __init__(self, logfile):
self.log = open(logfile, 'a')
def write(self, text):
self.log.write(text)
self.log.flush()
def close(self):
self.log.close()
sys.stdout = MyOutput(os.path.join(app_folder, 'tmp', 'myflexget.log'))
#########################################
@app.context_processor
def variables():
return {'menu': _menu}
def load_plugins():
import plugins
dir = plugins.__path__[0]
#Find plugins:
plugin_names = []
for file in sorted(os.listdir(dir)):
path = os.path.join(dir, file, '__init__.py')
if os.path.isfile(path):
plugin_names.append(file)
#Import plugins:
for name in plugin_names:
print('Loading plugin from: %s' % name)
exec("import plugins.%s" % name)
#Register plugins in flask:
for name in plugin_names:
if hasattr(sys.modules['plugins.%s' % name], 'register_plugin'):
_register_plugin(*sys.modules['plugins.%s' % name].register_plugin())
else:
print('Plugin %s is an unregistered plugin' % name)
def _register_plugin(plugin, menu=None, order=128):
print(' Registering plugin: %s' % plugin.name)
app.register_blueprint(plugin)
if menu:
_register_menu(plugin.url_prefix, menu, order)
def _register_menu(href, caption, order=128):
global _menu
print(' Registering menu: %s -> %s' % (caption, href))
_menu.append({'href': href, 'caption': caption, 'order': order})
_menu = sorted(_menu, key=lambda m: m['order'])