This file is indexed.

/usr/lib/python2.7/dist-packages/ubuntuuitoolkit/fixture_setup.py is in ubuntu-ui-toolkit-autopilot 0.1.46+14.04.20140408.1-0ubuntu1.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  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
115
116
117
118
119
120
# -*- Mode: Python; coding: utf-8; indent-tabs-mode: nil; tab-width: 4 -*-
#
# Copyright (C) 2014 Canonical Ltd.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU Lesser General Public License as published by
# the Free Software Foundation; version 3.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU Lesser General Public License for more details.
#
# You should have received a copy of the GNU Lesser General Public License
# along with this program. If not, see <http://www.gnu.org/licenses/>.

import copy
import os
import tempfile

import fixtures

from ubuntuuitoolkit import base, environment


DEFAULT_QML_FILE_CONTENTS = ("""
import QtQuick 2.0
import Ubuntu.Components 0.1

MainView {
    width: units.gu(48)
    height: units.gu(60)

    Label {
        objectName: 'testLabel'
        text: 'Test application.'
    }
}
""")
DEFAULT_DESKTOP_FILE_DICT = {
    'Type': 'Application',
    'Name': 'test',
    'Exec': '{qmlscene} {qml_file_path}',
    'Icon': 'Not important'
}


class FakeApplication(fixtures.Fixture):

    def __init__(
            self, qml_file_contents=DEFAULT_QML_FILE_CONTENTS,
            desktop_file_dict=None):
        super(FakeApplication, self).__init__()
        self._qml_file_contents = qml_file_contents
        if desktop_file_dict is None:
            self._desktop_file_dict = copy.deepcopy(DEFAULT_DESKTOP_FILE_DICT)
        else:
            self._desktop_file_dict = copy.deepcopy(desktop_file_dict)

    def setUp(self):
        super(FakeApplication, self).setUp()
        self.qml_file_path, self.desktop_file_path = (
            self._create_test_application())

    def _create_test_application(self):
        qml_file_path = self._write_test_qml_file()
        self.addCleanup(os.remove, qml_file_path)
        desktop_file_path = self._write_test_desktop_file(qml_file_path)
        self.addCleanup(os.remove, desktop_file_path)
        return qml_file_path, desktop_file_path

    def _write_test_qml_file(self):
        qml_file = tempfile.NamedTemporaryFile(
            mode='w+t', suffix='.qml', delete=False)
        qml_file.write(self._qml_file_contents)
        qml_file.close()
        return qml_file.name

    def _write_test_desktop_file(self, qml_file_path):
        desktop_file_dir = self._get_local_desktop_file_directory()
        if not os.path.exists(desktop_file_dir):
            os.makedirs(desktop_file_dir)
        desktop_file = tempfile.NamedTemporaryFile(
            mode='w+t', suffix='.desktop', dir=desktop_file_dir, delete=False)
        self._desktop_file_dict['Exec'] = (
            self._desktop_file_dict['Exec'].format(
                qmlscene=base.get_qmlscene_launch_command(),
                qml_file_path=qml_file_path))
        desktop_file.write('[Desktop Entry]\n')
        for key, value in self._desktop_file_dict.items():
            desktop_file.write('{key}={value}\n'.format(key=key, value=value))
        desktop_file.close()
        return desktop_file.name

    def _get_local_desktop_file_directory(self):
        return os.path.join(
            os.environ.get('HOME'), '.local', 'share', 'applications')


class InitctlEnvironmentVariable(fixtures.Fixture):
    """Set the value of initctl environment variables."""

    def __init__(self, **kwargs):
        super(InitctlEnvironmentVariable, self).__init__()
        self.variables = kwargs

    def setUp(self):
        super(InitctlEnvironmentVariable, self).setUp()
        for variable, value in self.variables.items():
            self._add_variable_cleanup(variable)
            environment.set_initctl_env_var(variable, value)

    def _add_variable_cleanup(self, variable):
        if environment.is_initctl_env_var_set(variable):
            original_value = environment.get_initctl_env_var(variable)
            self.addCleanup(
                environment.set_initctl_env_var, variable,
                original_value)
        else:
            self.addCleanup(environment.unset_initctl_env_var, variable)