-
Notifications
You must be signed in to change notification settings - Fork 0
/
urk.py
120 lines (107 loc) · 3.36 KB
/
urk.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
#!/usr/bin/python -O
import imp
import os
import sys
import traceback
sys.modules['urk'] = sys.modules[__name__]
#add ~/.urk and path (normally where urk.py is located) to sys.path
urkpath = os.path.dirname(__file__)
def path(filename=""):
if filename:
return os.path.join(urkpath, filename)
else:
return urkpath
if 'URK_PROFILE' in os.environ:
userpath = os.environ['URK_PROFILE']
if not os.path.exists(userpath):
os.mkdir(userpath, 0700)
if not os.path.exists(os.path.join(userpath,'scripts')):
os.mkdir(os.path.join(userpath,'scripts'), 0700)
elif os.path.exists(path('profile')) or os.path.expanduser("~") == "~":
userpath = path('profile')
if not os.path.exists(userpath):
os.mkdir(userpath)
if not os.path.exists(os.path.join(userpath,'scripts')):
os.mkdir(os.path.join(userpath,'scripts'))
else:
userpath = os.path.join(os.path.expanduser("~"), ".urk")
if not os.path.exists(userpath):
os.mkdir(userpath, 0700)
if not os.path.exists(os.path.join(userpath,'scripts')):
os.mkdir(os.path.join(userpath,'scripts'), 0700)
platforms = ['gtk', 'stdio']
def test_platform(platform, verbose=False):
try:
f = open(os.path.join(path('platform'), platform, 'check.py'), 'U')
except:
if verbose:
traceback.print_exc()
return False
try:
try:
exec f.read()
return True
except:
if verbose:
traceback.print_exc()
return False
finally:
f.close()
if 'URK_PLATFORM' in os.environ:
platform = os.environ['URK_PLATFORM']
if not test_platform(platform, verbose=True):
print("Cannot use forced platform '%s'" % platform)
sys.exit(1)
platform_path = os.path.join(path('platform'), platform)
print("Using forced platform '%s'" % platform)
else:
for platform in platforms:
f = open(os.path.join(path('platform'), platform, 'check.py'), 'U')
try:
exec f.read()
except:
print("Couldn't load platform '%s'" % platform)
else:
print("Using platform '%s'" % platform)
platform_path = os.path.join(path('platform'), platform)
break
f.close()
del f
else:
print("Cannot use any available platform")
sys.exit(1)
sys.path = [
platform_path,
os.path.join(platform_path, "scripts"),
userpath,
os.path.join(userpath, "scripts"),
os.curdir,
os.path.join(os.curdir, "scripts"),
path(),
path("scripts")
] + sys.path
import events
import ui
name = "urk"
long_name = "urk IRC"
version = 0, -1, "cvs"
long_version = "%s v%s" % (long_name, ".".join(str(x) for x in version))
website = "http://urk.sf.net/"
authors = ["Vincent Povirk", "Marc Liddell"]
copyright = "2005 %s" % ', '.join(authors)
def main():
for script_path in set(sys.path[1:8:2]):
try:
suffix = os.extsep+"py"
for script in os.listdir(script_path):
if script.endswith(suffix):
try:
events.load(script)
except:
traceback.print_exc()
print "Failed loading script %s." % script
except OSError:
pass
ui.start(' '.join(sys.argv[1:]))
if __name__ == "__main__":
main()