joystick
[e-sieve] / OPEN-GAME
1 #!/usr/bin/env python
2
3 from os import environ, execvp, chdir, getcwd
4 from os.path import exists, join, dirname
5 from sys import version_info, argv
6
7 def can_import(module_name):
8     try:
9         __import__(module_name)
10     except ImportError:
11         return False
12     else:
13         return True
14
15 def is_python_3():
16     return version_info[0] >= 3
17
18 def is_current_version(file_name):
19     version = map(int, file_name.replace("python", "").split("."))
20     return version == list(version_info)[:2]
21
22 def launch_alternative(alternatives):
23     for alternative in alternatives:
24         if not is_current_version(alternative):
25             for root in environ["PATH"].split(":"):
26                 if exists(join(root, alternative)):
27                     execvp(alternative, [alternative] + argv)
28
29 def move_to_executable():
30     chdir(dirname(argv[0]))
31
32 if is_python_3():
33     launch_alternative(["python2", "python2.7", "python2.6"])
34
35 if not can_import("pygame"):
36     launch_alternative(["python2.7", "python2.6"])
37
38 if "--go-to-dir" in argv:
39     move_to_executable()
40
41 from electric_sieve.ElectricSieve import ElectricSieve
42
43 ElectricSieve().run()