This file is indexed.

/usr/share/pyshared/dmedia/gtkui/client.py is in dmedia-gtk 0.6.0~repack-1build1.

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
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
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
# Authors:
#   Jason Gerard DeRose <jderose@novacut.com>
#
# dmedia: distributed media library
# Copyright (C) 2010 Jason Gerard DeRose <jderose@novacut.com>
#
# This file is part of `dmedia`.
#
# `dmedia` is free software: you can redistribute it and/or modify it under the
# terms of the GNU Affero General Public License as published by the Free
# Software Foundation, either version 3 of the License, or (at your option) any
# later version.
#
# `dmedia` 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 Affero General Public License for more
# details.
#
# You should have received a copy of the GNU Affero General Public License along
# with `dmedia`.  If not, see <http://www.gnu.org/licenses/>.

"""
Convenience wrapper for Python applications talking to dmedia dbus service.
"""

import dbus
import dbus.mainloop.glib
from gi.repository import GObject
from gi.repository.GObject import TYPE_PYOBJECT
from dmedia.constants import IMPORT_BUS, IMPORT_IFACE, EXTENSIONS


# We need mainloop integration to test signals:
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)


class Client(GObject.GObject):
    """
    Simple and Pythonic way to control dmedia dbus service.

    For Python applications, this client provides several advantages over
    strait dbus because it:

      1. Lazily starts the dmedia service the first time you call a dbus method
         or connect a signal handler

      2. More Pythonic API, including default argument values where they make
         sense

      3. Can use convenient GObject signals

    Controlling import operations
    =============================

    The dmedia service can have multiple import operations running at once.
    Import jobs are identified by the path of the directory being imported.

    For example, use `Client.list_imports()` to get the list of currently running
    imports:

    >>> from dmedia.gtkui.client import Client
    >>> client = Client()  #doctest: +SKIP
    >>> client.list_imports()  #doctest: +SKIP
    []

    Start an import operation using `Client.start_import()`, after which you
    will see it in the list of running imports:

    >>> client.start_import('/media/EOS_DIGITAL')  #doctest: +SKIP
    'started'
    >>> client.list_imports()  #doctest: +SKIP
    ['/media/EOS_DIGITAL']

    If you try to import a path for which an import operation is already in
    progress, `Client.start_import()` will return the status string
    ``'already_running'``:

    >>> client.start_import('/media/EOS_DIGITAL')  #doctest: +SKIP
    'already_running'

    Stop an import operation using `Client.stop_import()`, after which there
    will be no running imports:

    >>> client.stop_import('/media/EOS_DIGITAL')  #doctest: +SKIP
    'stopped'
    >>> client.list_imports()  #doctest: +SKIP
    []

    If you try to stop an import operation that doesn't exist,
    `Client.stop_import()` will return the status string ``'not_running'``:

    >>> client.stop_import('/media/EOS_DIGITAL')  #doctest: +SKIP
    'not_running'

    Finally, you can shutdown the dmedia service with `Client.kill()`:

    >>> client.kill()  #doctest: +SKIP

    """

    __gsignals__ = {
        'batch_started': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
            [TYPE_PYOBJECT]
        ),
        'batch_finished': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
            [TYPE_PYOBJECT, TYPE_PYOBJECT]
        ),
        'import_started': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
            [TYPE_PYOBJECT, TYPE_PYOBJECT]
        ),
        'import_count': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
            [TYPE_PYOBJECT, TYPE_PYOBJECT, TYPE_PYOBJECT]
        ),
        'import_progress': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
            [TYPE_PYOBJECT, TYPE_PYOBJECT, TYPE_PYOBJECT, TYPE_PYOBJECT,
            TYPE_PYOBJECT]
        ),
        'import_finished': (GObject.SIGNAL_RUN_LAST, GObject.TYPE_NONE,
            [TYPE_PYOBJECT, TYPE_PYOBJECT, TYPE_PYOBJECT]
        ),
    }

    def __init__(self, bus=None):
        super(Client, self).__init__()
        self._bus = (IMPORT_BUS if bus is None else bus)
        self._conn = dbus.SessionBus()
        self._proxy = None

    @property
    def proxy(self):
        """
        Lazily create proxy object so dmedia service starts only when needed.
        """
        if self._proxy is None:
            self._proxy = self._conn.get_object(self._bus, '/')
            self._connect_signals()
        return self._proxy

    def _call(self, name, *args):
        method = self.proxy.get_dbus_method(name, dbus_interface=IMPORT_IFACE)
        return method(*args)

    def _connect_signals(self):
        self.proxy.connect_to_signal(
            'BatchStarted', self._on_BatchStarted, IMPORT_IFACE
        )
        self.proxy.connect_to_signal(
            'BatchFinished', self._on_BatchFinished, IMPORT_IFACE
        )
        self.proxy.connect_to_signal(
            'ImportStarted', self._on_ImportStarted, IMPORT_IFACE
        )
        self.proxy.connect_to_signal(
            'ImportCount', self._on_ImportCount, IMPORT_IFACE
        )
        self.proxy.connect_to_signal(
            'ImportProgress', self._on_ImportProgress, IMPORT_IFACE
        )
        self.proxy.connect_to_signal(
            'ImportFinished', self._on_ImportFinished, IMPORT_IFACE
        )

    def _on_BatchStarted(self, batch_id):
        self.emit('batch_started', batch_id)

    def _on_BatchFinished(self, batch_id, stats):
        self.emit('batch_finished', batch_id, stats)

    def _on_ImportStarted(self, base, import_id):
        self.emit('import_started', base, import_id)

    def _on_ImportCount(self, base, import_id, total):
        self.emit('import_count', base, import_id, total)

    def _on_ImportProgress(self, base, import_id, completed, total, info):
        self.emit('import_progress', base, import_id, completed, total, info)

    def _on_ImportFinished(self, base, import_id, stats):
        self.emit('import_finished', base, import_id, stats)

    def connect(self, *args, **kw):
        super(Client, self).connect(*args, **kw)
        if self._proxy is None:
            self.proxy

    def kill(self):
        """
        Shutdown the dmedia daemon.
        """
        self._call('Kill')
        self._proxy = None

    def version(self):
        """
        Return version number of running dmedia daemon.
        """
        return self._call('Version')

    def get_extensions(self, types):
        """
        Get a list of extensions based on broad categories in *types*.

        Currently recognized categories include ``'video'``, ``'audio'``,
        ``'images'``, and ``'all'``.  You can safely include categories that
        don't yet exist.

        :param types: A list of general categories, e.g. ``['video', 'audio']``
        """
        return self._call('GetExtensions', types)

    def start_import(self, base, extract=True):
        """
        Start import of card mounted at *base*.

        If *extract* is ``True`` (the default), metadata will be extracted and
        thumbnails generated.

        :param base: File-system path from which to import, e.g.
            ``'/media/EOS_DIGITAL'``
        :param extract: If ``True``, perform metadata extraction, thumbnail
            generation; default is ``True``.
        """
        return self._call('StartImport', base, extract)

    def stop_import(self, base):
        """
        Start import of card mounted at *base*.

        :param base: File-system path from which to import, e.g.
            ``'/media/EOS_DIGITAL'``
        """
        return self._call('StopImport', base)

    def list_imports(self):
        """
        Return list of currently running imports.
        """
        return self._call('ListImports')