-
Notifications
You must be signed in to change notification settings - Fork 0
/
Main.py
73 lines (61 loc) · 2.47 KB
/
Main.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
# Copyright (C) 2009-2011 AG Projects. See LICENSE for details.
#
import os
import sys
from util import memory_stick_mode
from Foundation import NSBundle
import Foundation
assert Foundation.NSThread.isMultiThreaded()
# Make mimetypes use our copy of the file in order to work with sandboxing
import mimetypes
resource_path = unicode(Foundation.NSBundle.mainBundle().resourcePath())
mimetypes.init(os.path.join(resource_path, "mime.types"))
class NSLogger(object):
closed = False
encoding = 'UTF-8'
mode = 'w'
name = '<NSLogger>'
newlines = None
softspace = 0
def close(self): pass
def flush(self): pass
def fileno(self): return -1
def isatty(self): return False
def next(self): raise IOError("cannot read from NSLogger")
def read(self): raise IOError("cannot read from NSLogger")
def readline(self): raise IOError("cannot read from NSLogger")
def readlines(self): raise IOError("cannot read from NSLogger")
def readinto(self, buf): raise IOError("cannot read from NSLogger")
def seek(self, offset, whence=0): raise IOError("cannot seek in NSLogger")
def tell(self): raise IOError("NSLogger does not have position")
def truncate(self, size=0): raise IOError("cannot truncate NSLogger")
def write(self, text):
pool= Foundation.NSAutoreleasePool.alloc().init()
if isinstance(text, basestring):
text = text.rstrip()
elif not isinstance(text, buffer):
raise TypeError("write() argument must be a string or read-only buffer")
Foundation.NSLog("%@", text)
def writelines(self, lines):
pool= Foundation.NSAutoreleasePool.alloc().init()
for line in lines:
if isinstance(line, basestring):
line = line.rstrip()
elif not isinstance(line, buffer):
raise TypeError("writelines() argument must be a sequence of strings")
Foundation.NSLog("%@", line)
sys.stdout = NSLogger()
sys.stderr = NSLogger()
if memory_stick_mode():
from resources import ApplicationData
from Foundation import NSBundle
ApplicationData._cached_directory = os.path.join(os.path.dirname(NSBundle.mainBundle().bundlePath()), 'Data')
# import modules containing classes required to start application and load MainMenu.nib
import BlinkAppDelegate
import ContactWindowController
import growl
import signal
signal.signal(signal.SIGPIPE, signal.SIG_IGN)
# pass control to AppKit
from PyObjCTools import AppHelper
AppHelper.runEventLoop()