forked from EventGhost/EventGhost
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathEventGhost.pyw
54 lines (51 loc) · 2.01 KB
/
EventGhost.pyw
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
# -*- coding: utf-8 -*-
#
# This file is part of EventGhost.
# Copyright © 2005-2019 EventGhost Project <http://www.eventghost.net/>
#
# EventGhost is free software: you can redistribute it and/or modify it under
# the terms of the GNU General Public License as published by the Free
# Software Foundation, either version 2 of the License, or (at your option)
# any later version.
#
# EventGhost is distributed in the hope that it will be useful, but WITHOUT
# ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
# FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
# more details.
#
# You should have received a copy of the GNU General Public License along
# with EventGhost. If not, see <http://www.gnu.org/licenses/>.
import sys
if hasattr(sys, "frozen"):
from os.path import dirname
FSE = sys.getfilesystemencoding()
filePath = sys.executable.encode(FSE) if isinstance(sys.executable, unicode) else sys.executable
sys.path.append(dirname(filePath))
# sys.path.append(dirname(sys.executable.encode('mbcs')))
if len(sys.argv) > 2 and sys.argv[1] == "-execfile":
import imp
import os
filename = sys.argv[2]
# we need a reference to the old module, otherwise we get garbage collected
oldMainModule = sys.modules['__main__']
# Create a new module to serve as __main__
mainModule = imp.new_module('__main__')
mainModule.__file__ = filename
mainModule.__builtins__ = sys.modules['__builtin__']
sys.modules['__main__'] = mainModule
# Set sys.argv and the path element properly.
sys.argv = sys.argv[2:]
sys.path.append(os.path.dirname(filename))
try:
source = open(filename, 'rU').read()
except IOError:
raise Exception("No file to run: %r" % filename)
exec compile(source, filename, "exec") in mainModule.__dict__
else:
if __name__ == "__main__":
from multiprocessing import freeze_support
freeze_support()
import __main__
__main__.isMain = True
import eg
eg.Main()