This file is indexed.

/usr/share/avant-window-navigator/applets/thinkhdaps/thinkhdaps.py is in awn-applet-thinkhdaps 0.4.1~bzr1507-0ubuntu7.

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

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
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
#!/usr/bin/python
# Copyright (C) 2008 - 2010  onox <denkpadje@gmail.com>
#
# This program is free software: you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation, version 3 of the License.
#
# 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 General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program.  If not, see <http://www.gnu.org/licenses/>.

import os
import platform

import pygtk
pygtk.require("2.0")
import gtk

from awn.extras import _, awnlib, __version__
from awn import OverlayThemedIcon

import glib

try:
    from pyinotify import WatchManager, ThreadedNotifier, IN_MODIFY
    pyinotify = True
except ImportError:
    pyinotify = None

applet_name = _("ThinkHDAPS")
applet_description = _("Applet that shows the shock protection status of your disks")

# Interval in seconds between two successive status checks
check_status_interval = 0.1

hdaps_short_description = _("%s protected from shocks")
no_hdaps_short_description = _("%s not protected from shocks")

# Logo of the applet, shown in the GTK+ About dialog
applet_logo = os.path.join(os.path.dirname(__file__), "images/thinkhdaps-logo.svg")


def compare_linux_version(wanted_version):
    version = map(int, platform.release().split("-")[0].split("."))
    return awnlib.is_required_version(version, wanted_version)


version_at_least_2_6_27 = compare_linux_version([2, 6, 27])

sysfs_dir = "/sys/block"

if version_at_least_2_6_27:
    protect_file = "device/unload_heads"
else:
    method_file = "queue/protect_method"
    protect_file = "queue/protect"

notifier = None


class ThinkHDAPSApplet:

    """Applet that shows the status of HDAPS.

    """

    __hdaps_device = None

    __was_paused = False
    __error_occurred = False

    def check_status_cb(self):
        """Check the status the hard disk monitored by HDAPS and change
        the applet's icon if necessary,

        """
        try:
            paused = bool(int(open(self.__status_file).readline()))

            # Change icon if status has changed
            if paused != self.__was_paused or self.__error_occurred:
                self.icon_paused.props.active = paused
                self.icon_running.props.active = not paused

            if self.__error_occurred:
                self.__error_occurred = False
                self.applet.tooltip.set(hdaps_short_description % self.__hdaps_device)

            self.__was_paused = paused
        except IOError:
            if not self.__error_occurred:
                self.__error_occurred = True

                self.set_error_icon()
                self.applet.tooltip.set(no_hdaps_short_description % self.__hdaps_device)

    def __init__(self, applet):
        self.applet = applet

        applet.tooltip.disable_toggle_on_click()
        applet.icon.theme("drive-harddisk")

        if version_at_least_2_6_27:
            def can_unload(disk):
                file = os.path.join(sysfs_dir, disk, protect_file)
                if not os.path.isfile(file):
                    return False
                try:
                    open(file).read()
                    return True
                except IOError:
                    return False
        else:
            def can_unload(disk):
                file = os.path.join(sysfs_dir, disk, method_file)
                return os.path.isfile(file) and "[unload]" in open(file).read()
        disks = [disk for disk in os.listdir(sysfs_dir) if can_unload(disk)]

        if len(disks) > 0:
            self.__hdaps_device = disks[0]

        self.icon_running = OverlayThemedIcon("thinkhdaps-running")
        self.icon_running.props.scale = 0.6

        self.icon_paused = OverlayThemedIcon("thinkhdaps-paused")
        self.icon_paused.props.scale = 0.5

        self.icon_error = OverlayThemedIcon("dialog-error")
        self.icon_error.props.scale = 0.6

        for overlay in (self.icon_running, self.icon_paused, self.icon_error):
            overlay.props.gravity = gtk.gdk.GRAVITY_NORTH_WEST
            overlay.props.active = False
            applet.add_overlay(overlay)

        if self.__hdaps_device is not None:
            self.icon_running.props.active = True

            self.__status_file = os.path.join(sysfs_dir, self.__hdaps_device, protect_file)

            applet.tooltip.set(hdaps_short_description % self.__hdaps_device)

            if not self.setup_inotify():
                applet.timing.register(self.check_status_cb, check_status_interval)
        else:
            self.set_error_icon()
            applet.tooltip.set(_("No hard disk found"))

    def setup_inotify(self):
        if pyinotify is None:
            return False

        watch_manager = WatchManager()
        result = watch_manager.add_watch(self.__status_file, IN_MODIFY)[self.__status_file] > 0

        if result:
            global notifier
            def notify_cb(event):
                glib.idle_add(self.check_status_cb)
            notifier = ThreadedNotifier(watch_manager, notify_cb)
            notifier.start()
        return result

    def set_error_icon(self):
        self.icon_paused.props.active = False
        self.icon_running.props.active = False
        self.icon_error.props.active = True


if __name__ == "__main__":
    awnlib.init_start(ThinkHDAPSApplet, {"name": applet_name,
        "short": "thinkhdaps",
        "version": __version__,
        "description": applet_description,
        "logo": applet_logo,
        "author": "onox",
        "copyright-year": "2008 - 2009",
        "authors": ["onox <denkpadje@gmail.com>"],
        "artists": ["Jakub Steiner", "Lapo Calamandrei", "Rodney Dawes", "Garrett LeSage", "onox"]})

    if notifier is not None:
        notifier.stop()