-
Notifications
You must be signed in to change notification settings - Fork 5
/
WikidPadStarter.py
244 lines (172 loc) · 5.95 KB
/
WikidPadStarter.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#!/bin/python
# try:
# import psyco
# psyco.full()
# except ImportError:
# pass
# traceback.print_exc()
import sys, os, traceback, os.path, glob, shutil, imp, warnings, ConfigParser
os.stat_float_times(True)
if not hasattr(sys, 'frozen'):
sys.path.insert(0, "lib")
# sys.path.append("lib")
# sys.path.append(r"C:\Daten\Projekte\Wikidpad\Current\lib")
os.environ["PATH"] = os.path.dirname(os.path.abspath(sys.argv[0])) + \
os.pathsep + os.environ["PATH"]
from Consts import CONFIG_FILENAME, CONFIG_GLOBALS_DIRNAME
# imports VERSION_TUPLE for plugins which may expect it here
from Consts import VERSION_STRING, VERSION_TUPLE
import __builtin__
# Dummies for localization
def N_(s):
return s
__builtin__.N_ = N_
del N_
__builtin__._ = N_
del __builtin__
# create a Trace object
# import trace
# __builtins__["tracer"] = trace.Trace(
# ignoredirs=[sys.prefix, sys.exec_prefix],
# trace=1,
# count=0)
import ExceptionLogger
ExceptionLogger.startLogger(VERSION_STRING)
# ## import hotshot
# ## _prof = hotshot.Profile("hotshot.prf")
def _putPathPrepends():
"""
Process file "binInst.ini" in installation directory, if present.
The file is created by the Windows binary installer (Inno Setup)
and contains adjustments to the installation, namely additional
ZIP-files to add to sys.path.
"""
parser = ConfigParser.RawConfigParser()
try:
f = open(os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),
"binInst.ini"), "rU")
parser.readfp(f)
f.close()
try:
for opt, val in parser.items("sysPathPrepend"):
sys.path.insert(0, os.path.join(os.path.dirname(
os.path.abspath(sys.argv[0])), val))
except ConfigParser.NoSectionError:
pass
try:
for opt, val in parser.items("sysPathAppend"):
sys.path.append(os.path.join(os.path.dirname(
os.path.abspath(sys.argv[0])), val))
except ConfigParser.NoSectionError:
pass
except IOError:
pass # Probably file not present
_putPathPrepends()
sys.path.append(os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),
"gadfly.zip"))
# sys.path.append(r"C:\Daten\Projekte\Wikidpad\Current\gadfly.zip")
# print "sys.path + ", os.path.join(os.path.abspath(sys.argv[0]), "gadfly.zip")
import wx
# cmore addition
if (not hasattr(wx, "NO_3D")):
wx.NO_3D=0
# from pwiki import srePersistent
# srePersistent.loadCodeCache()
from pwiki.MainApp import App, findDirs
if len(sys.argv) == 2 and sys.argv[1] == "--deleteconfig":
# Special option, called by deinstaller on request to delete personal
# configuration files
# We need a dummy app to call findDirs()
dummyApp = wx.App(0)
dummyApp.SetAppName("WikidPad")
wikiAppDir, globalConfigDir = findDirs()
if globalConfigDir is None:
sys.exit(1)
try:
try:
globalConfigSubDir = os.path.join(globalConfigDir,
CONFIG_GLOBALS_DIRNAME)
shutil.rmtree(globalConfigSubDir, True)
except:
pass
try:
globalConfigSubDir = os.path.join(globalConfigDir,
"." + CONFIG_GLOBALS_DIRNAME)
shutil.rmtree(globalConfigSubDir, True)
except:
pass
# subfiles = glob.glob(os.path.join(globalConfigSubDir, "*"))
# for f in subfiles:
# try:
# os.remove(f)
# except:
# pass
# try:
# os.rmdir(globalConfigSubDir)
# except:
# pass
try:
os.remove(os.path.join(globalConfigDir, CONFIG_FILENAME))
except:
pass
try:
os.remove(os.path.join(globalConfigDir, "." + CONFIG_FILENAME))
except:
pass
if wikiAppDir != globalConfigDir:
try:
os.rmdir(globalConfigDir)
except:
pass
sys.exit(0)
except SystemExit:
raise
except:
sys.exit(1)
elif len(sys.argv) >= 3 and sys.argv[1] == "--updtrans":
try:
# Update translation from .pot file
args = sys.argv[2:]
# We need a dummy app to call findDirs()
dummyApp = wx.App(0)
dummyApp.SetAppName("WikidPad")
wikiAppDir, globalConfigDir = findDirs()
if len(args) == 1:
args.append(os.path.join(wikiAppDir, "WikidPad.pot"))
from pwiki import I18nPoUpdater
I18nPoUpdater.main(args)
sys.exit(0)
except SystemExit:
raise
except:
traceback.print_exc()
sys.exit(1)
# # Start initial localization support before reading config
# gettext.install("WikidPad", os.path.join(wikiAppDir, "Lang"), True)
class ErrorFrame(wx.Frame):
def __init__(self, parent, id, title):
wx.Frame.__init__(self, parent, -1, title, size = (300, 200),
style=wx.DEFAULT_FRAME_STYLE|wx.NO_FULL_REPAINT_ON_RESIZE)
dlg_m = wx.MessageDialog(self, _(u"Error starting WikidPad"),
_(u'Error!'), wx.OK)
dlg_m.ShowModal()
dlg_m.Destroy()
self.Close()
class Error(wx.App):
def OnInit(self):
errorFrame = ErrorFrame(None, -1, _(u"Error"))
self.SetTopWindow(errorFrame)
return False
app = None
exception = None
def main():
try:
app = App(0)
app.MainLoop()
# srePersistent.saveCodeCache()
except Exception, e:
traceback.print_exc()
exception = e
error = Error(0)
error.MainLoop()
sys.exit()