-
Notifications
You must be signed in to change notification settings - Fork 3
/
wpmaker.py
executable file
·81 lines (64 loc) · 2.05 KB
/
wpmaker.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
77
78
79
80
81
#!/usr/bin/env python
import sys
from application import Application
try:
import wx
except:
pass
# Start logger
import logging
logging.basicConfig(format='%(levelname)s (%(threadName)s): %(message)s | %(pathname)s:%(lineno)d @ %(asctime)s',
filename='last_run.log',
filemode='w',
level=logging.DEBUG)
# Load all plugins
from plugins import plugin_manager
# Read options and arguments
from config import get_config, save_config
config = get_config(plugin_manager['Option'])
plugin_manager.activate_plugins(config, 'UI')
# Find and set ui
ui = None
if len(plugin_manager['UI']):
ui = plugin_manager['UI'][0]
# Check if ui is set
if ui is None and config['ui'] is not None:
raise RuntimeError("Couldn't find ui plugin '%s'" % config['ui'])
from config import ConfigurationError, get_doc
try:
plugin_manager.plugin_hook('check_config', save_config)
plugin_manager.activate_plugins(config)
except ConfigurationError, e:
print e.cmdline_message()
print get_doc(plugin_manager['Option'])
sys.exit(1)
app = Application(config, ui)
def main():
try:
if ui is not None:
ui.start_app()
else:
app.main()
except KeyboardInterrupt:
pass
def lowpriority():
""" Set the priority of the process to below-normal."""
if sys.platform == 'win32':
# Based on:
# "Recipe 496767: Set Process Priority In Windows" on ActiveState
# http://code.activestate.com/recipes/496767/
import win32api,win32process,win32con
pid = win32api.GetCurrentProcessId()
handle = win32api.OpenProcess(win32con.PROCESS_ALL_ACCESS, True, pid)
win32process.SetPriorityClass(handle, win32process.BELOW_NORMAL_PRIORITY_CLASS)
else:
import os
os.nice(1)
# ui and app should both be set, logging started and config read.
# Let's start this thing
if __name__ == '__main__':
try:
lowpriority()
except:
logging.exception('Low priority not set, exception occurred!')
main()