3
# Copyright (C) 2012 Canonical Ltd.
5
# This program is free software: you can redistribute it and/or modify it
6
# under the terms of the GNU General Public License version 3, as published
7
# by the Free Software Foundation.
9
# This program is distributed in the hope that it will be useful, but
10
# WITHOUT ANY WARRANTY; without even the implied warranties of
11
# MERCHANTABILITY, SATISFACTORY QUALITY, or FITNESS FOR A PARTICULAR
12
# PURPOSE. See the GNU General Public License for more details.
14
# You should have received a copy of the GNU General Public License along
15
# with this program. If not, see <http://www.gnu.org/licenses/>.
17
# In addition, as a special exception, the copyright holders give
18
# permission to link the code of portions of this program with the
19
# OpenSSL library under certain conditions as described in each
20
# individual source file, and distribute linked combinations
22
# You must obey the GNU General Public License in all respects
23
# for all of the code used other than OpenSSL. If you modify
24
# file(s) with this exception, you may extend this exception to your
25
# version of the file(s), but you are not obligated to do so. If you
26
# do not wish to do so, delete this exception statement from your
27
# version. If you delete this exception statement from all source
28
# files in the program, then also delete it here.
29
"""A script that checks for unintended imports of twisted.internet.reactor."""
31
# NOTE: the goal of this script is to avoid a bug that affects
32
# ubuntuone-control-panel on windows and darwin. Those platforms use
33
# the qt4reactor, and will break if the default reactor is installed
34
# first. This can happen if a module used by control-panel (such as
35
# ubuntuone.platform.credentials), imports reactor. Only sub-modules
36
# that are not used by ubuntuone-control-panel can safely import
37
# reactor at module-level.
39
from __future__ import (unicode_literals, print_function)
47
sys.path.append(os.path.abspath(os.getcwd()))
50
def fake_import(*args, **kwargs):
51
"""A wrapper for __import__ that dies when importing reactor."""
52
imp_name_base = args[0]
54
if len(args) == 4 and args[3] is not None:
55
imp_names = ["{0}.{1}".format(imp_name_base, sm)
58
imp_names = [imp_name_base]
60
for imp_name in imp_names:
61
if 'twisted.internet.reactor' == imp_name:
62
print("ERROR: should not import reactor here:")
63
traceback.print_stack()
66
r = real_import(*args, **kwargs)
70
if __name__ == '__main__':
72
real_import = __builtin__.__import__
73
__builtin__.__import__ = fake_import
75
subs = ["", ".tools", ".logger", ".credentials"]
76
for module in ["ubuntuone.platform" + p for p in subs]:
77
m = __import__(module)