~ubuntu-branches/ubuntu/saucy/ubuntuone-client/saucy-proposed

« back to all changes in this revision

Viewing changes to contrib/check-reactor-import

  • Committer: Package Import Robot
  • Author(s): Rodney Dawes
  • Date: 2013-07-11 15:11:07 UTC
  • mfrom: (1.1.83)
  • Revision ID: package-import@ubuntu.com-20130711151107-6tbv4n9er446e2yy
Tags: 13.07-0ubuntu1
* New upstream release.
  - Remove libsyncdaemon and convert to pure python project.
* debian/control:
  - Update dependencies for changes.
  - Drop libsyncdaemon packages. (LP: #1196684)
* debian/rules:
  - Convert to pure dh and update for build system changes.
* debian/tests:
  - Add autopkgtest configuration.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#! /usr/bin/python
 
2
#
 
3
# Copyright (C) 2012 Canonical Ltd.
 
4
#
 
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.
 
8
#
 
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.
 
13
#
 
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/>.
 
16
#
 
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
 
21
# including the two.
 
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."""
 
30
 
 
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.
 
38
 
 
39
from __future__ import (unicode_literals, print_function)
 
40
 
 
41
import __builtin__
 
42
 
 
43
import os
 
44
import sys
 
45
import traceback
 
46
 
 
47
sys.path.append(os.path.abspath(os.getcwd()))
 
48
 
 
49
 
 
50
def fake_import(*args, **kwargs):
 
51
    """A wrapper for __import__ that dies when importing reactor."""
 
52
    imp_name_base = args[0]
 
53
 
 
54
    if len(args) == 4 and args[3] is not None:
 
55
        imp_names = ["{0}.{1}".format(imp_name_base, sm)
 
56
                     for sm in args[3]]
 
57
    else:
 
58
        imp_names = [imp_name_base]
 
59
 
 
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()
 
64
            sys.exit(1)
 
65
 
 
66
    r = real_import(*args, **kwargs)
 
67
    return r
 
68
 
 
69
 
 
70
if __name__ == '__main__':
 
71
 
 
72
    real_import = __builtin__.__import__
 
73
    __builtin__.__import__ = fake_import
 
74
 
 
75
    subs = ["", ".tools", ".logger", ".credentials"]
 
76
    for module in ["ubuntuone.platform" + p for p in subs]:
 
77
        m = __import__(module)