-
Notifications
You must be signed in to change notification settings - Fork 5
/
__init__.py
114 lines (93 loc) · 2.77 KB
/
__init__.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
# This file is part of Xpra.
# Copyright (C) 2010 Nathaniel Smith <njs@pobox.com>
# Copyright (C) 2011-2014 Antoine Martin <antoine@devloop.org.uk>
# Xpra is released under the terms of the GNU GPL v2, or, at your option, any
# later version. See the file COPYING for details.
import os as os
import sys as sys
_init_done = False
def init(prgname=None, appname=None):
""" do whatever is needed to prepare an application for running,
some platforms may initialize logging to file, etc
"""
global _init_done
if not _init_done:
_init_done = True
if prgname:
set_prgname(prgname)
if appname:
set_application_name(appname)
do_init()
#platforms can override this
def do_init():
pass
_clean_done = False
def clean():
global _clean_done
if not _clean_done:
_clean_done = True
do_clean()
#platforms can override this
def do_clean():
pass
#platforms can override this
_prg_name = None
def set_prgname(name):
global _prg_name
if _prg_name is None:
_prg_name = name
do_set_prgname(name)
def do_set_prgname(name):
try:
import glib
glib.set_prgname(name)
except:
pass
def get_prgname():
global _prg_name
return _prg_name
#platforms can override this
_application_name = None
def set_application_name(name):
global _application_name
if _application_name is None:
_application_name = name
do_set_application_name(name)
def do_set_application_name(name):
try:
import glib
glib.set_application_name(name)
except:
pass
def get_application_name():
global _application_name
return _application_name
def platform_import(where, pm, required, *imports):
if os.name == "nt":
p = "win32"
elif sys.platform.startswith("darwin"):
p = "darwin"
elif os.name == "posix":
p = "xposix"
else:
raise OSError("Unknown OS %s" % (os.name))
module = "xpra.platform.%s" % p
if pm:
module += ".%s" % pm
#cannot log this early! (win32 needs log to file redirection..)
#log = Logger("platform", "import")
#log("importing %s from %s (required=%s)" % (imports, module, required))
platform_module = __import__(module, {}, {}, imports)
assert platform_module
for x in imports:
found = hasattr(platform_module, x)
if not found:
if required:
raise Exception("could not find %s in %s" % (x, module))
else:
continue
v = getattr(platform_module, x)
where[x] = v
platform_import(globals(), None, True, "do_init", "do_clean")
platform_import(globals(), None, False, "do_set_prgname")
platform_import(globals(), None, False, "do_set_application_name")