forked from exaile/exaile
-
Notifications
You must be signed in to change notification settings - Fork 0
/
exaile_win.py
113 lines (88 loc) · 3.53 KB
/
exaile_win.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
#!/usr/bin/env python2
"""Launcher for Exaile on Windows"""
from __future__ import division, print_function, unicode_literals
# Make file handles not inheritable, that way we can restart on the fly
# -> From http://www.virtualroadside.com/blog/index.php/2013/02/06/problems-with-file-descriptors-being-inherited-by-default-in-python/
import __builtin__
import msvcrt, sys
from ctypes import windll
__builtin__open = __builtins__.open
def __open_inheritance_hack(*args, **kwargs):
result = __builtin__open(*args, **kwargs)
handle = msvcrt.get_osfhandle(result.fileno())
windll.kernel32.SetHandleInformation(handle, 1, 0)
return result
__builtin__.open = __open_inheritance_hack
def error(message1, message2=None, die=True):
import logging
"""Show error message and exit.
If two message arguments are supplied, the first one will be used as title.
If `die` is true, exit after showing the message.
"""
logging.error(message1 + (('\r\n\r\n' + message2) if message2 else ''))
if sys.stdout.isatty():
if die:
print("\r\n[Press Enter to exit.]", file=sys.stderr)
raw_input()
else:
import ctypes
if not message2:
message1, message2 = message2, message1
ctypes.windll.user32.MessageBoxW(None, message2, message1, 0x10)
if die:
sys.exit(1)
def main():
import logging
logging.basicConfig(level=logging.INFO, datefmt="%H:%M:%S",
format="%(levelname)-8s: %(message)s")
aio_message = "\r\n\r\nPlease run the 'All-In-One PyGI/PyGObject for Windows Installer' and ensure that the following are selected:" + \
"\r\n\r\n" + \
"* GTK+ 3.x\r\n" + \
"* GStreamer 1.4.5 and the gst-plugins package(s)\r\n" + \
"\r\n" + \
"The 'All-In-One PyGI/PyGObject for Windows Installer' can be downloaded at\r\nhttp://sourceforge.net/projects/pygobjectwin32/\r\n\r\n" + \
"See README.Windows for more information."
try:
import gi
except:
error("PyGObject not found",
"PyGObject could not be imported. " + aio_message)
else:
logging.info("PyGObject works")
try:
from gi.repository import Gtk
except:
error("GTK not found",
"GTK could not be imported. " + aio_message)
else:
logging.info("GTK works")
try:
from gi.repository import Gst
except:
error("GStreamer not found",
"GStreamer could not be imported. " + aio_message)
else:
logging.info("GStreamer works")
try:
import mutagen
except Exception:
error("Mutagen not found",
"The Python module Mutagen could not be imported. It can be downloaded from http://code.google.com/p/mutagen\r\n\r\n" +
"See README.Windows for more information.")
else:
logging.info("Mutagen works")
# disable the logging before starting exaile.. otherwise it gets
# configured twice and we get double the log messages!
logging = None
del sys.modules['logging']
try:
sys.argv[1:1] = ['--startgui', '--no-dbus', '--no-hal']
import exaile
exaile.main()
except Exception:
import traceback
traceback.print_exc()
raw_input()
if __name__ == '__main__':
main()
# vi: et sts=4 sw=4 ts=4