conf: use shutil.move instead of os.rename for saving
[urk.git] / urk.py
blob9985dc0a6598ac0d2891e58644f4fde6c1013613
1 #!/usr/bin/python -O
3 import imp
4 import os
5 import sys
6 import traceback
8 sys.modules['urk'] = sys.modules[__name__]
10 #add ~/.urk and path (normally where urk.py is located) to sys.path
11 urkpath = os.path.dirname(__file__)
12 def path(filename=""):
13 if filename:
14 return os.path.join(urkpath, filename)
15 else:
16 return urkpath
18 if 'URK_PROFILE' in os.environ:
19 userpath = os.environ['URK_PROFILE']
20 if not os.access(userpath,os.F_OK):
21 os.mkdir(userpath, 0700)
22 if not os.access(os.path.join(userpath,'scripts'),os.F_OK):
23 os.mkdir(os.path.join(userpath,'scripts'), 0700)
24 elif os.access(path('profile'),os.F_OK) or os.path.expanduser("~") == "~":
25 userpath = path('profile')
26 if not os.access(userpath,os.F_OK):
27 os.mkdir(userpath)
28 if not os.access(os.path.join(userpath,'scripts'),os.F_OK):
29 os.mkdir(os.path.join(userpath,'scripts'))
30 else:
31 userpath = os.path.join(os.path.expanduser("~"), ".urk")
32 if not os.access(userpath,os.F_OK):
33 os.mkdir(userpath, 0700)
34 if not os.access(os.path.join(userpath,'scripts'),os.F_OK):
35 os.mkdir(os.path.join(userpath,'scripts'), 0700)
37 platforms = ['gtk', 'stdio']
39 def test_platform(platform, verbose=False):
40 try:
41 f = open(os.path.join(path('platform'), platform, 'check.py'), 'U')
42 except:
43 if verbose:
44 traceback.print_exc()
45 return False
46 try:
47 exec f.read()
48 return True
49 except:
50 if verbose:
51 traceback.print_exc()
52 return False
53 finally:
54 f.close()
56 if 'URK_PLATFORM' in os.environ:
57 platform = os.environ['URK_PLATFORM']
58 if not test_platform(platform, verbose=True):
59 print("Cannot use forced platform '%s'" % platform)
60 sys.exit(1)
61 platform_path = os.path.join(path('platform'), platform)
62 print("Using forced platform '%s'" % platform)
63 else:
64 for platform in platforms:
65 f = open(os.path.join(path('platform'), platform, 'check.py'), 'U')
66 try:
67 exec f.read()
68 except:
69 print("Couldn't load platform '%s'" % platform)
70 else:
71 print("Using platform '%s'" % platform)
72 platform_path = os.path.join(path('platform'), platform)
73 break
74 f.close()
75 del f
76 else:
77 print("Cannot use any available platform")
78 sys.exit(1)
80 sys.path = [
81 platform_path,
82 os.path.join(platform_path, "scripts"),
83 userpath,
84 os.path.join(userpath, "scripts"),
85 os.curdir,
86 os.path.join(os.curdir, "scripts"),
87 path(),
88 path("scripts")
89 ] + sys.path
91 import events
92 import ui
94 name = "urk"
95 long_name = "urk IRC"
96 version = 0, -1, "cvs"
97 long_version = "%s v%s" % (long_name, ".".join(str(x) for x in version))
98 website = "http://urk.sf.net/"
99 authors = ["Vincent Povirk", "Marc Liddell"]
100 copyright = "2005 %s" % ', '.join(authors)
102 def main():
103 for script_path in set(sys.path[1:8:2]):
104 try:
105 suffix = os.extsep+"py"
106 for script in os.listdir(script_path):
107 if script.endswith(suffix):
108 try:
109 events.load(script)
110 except:
111 traceback.print_exc()
112 print "Failed loading script %s." % script
113 except OSError:
114 pass
116 ui.start(' '.join(sys.argv[1:]))
118 if __name__ == "__main__":
119 main()