/usr/lib/python3/dist-packages/systemimage/service.py is in system-image-common 2.2-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 121 122 123 124 125 126 127 128 129 130 131 | # Copyright (C) 2013-2014 Canonical Ltd.
# Author: Barry Warsaw <barry@ubuntu.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/>.
"""DBus service main entry point."""
__all__ = [
'main',
]
import os
import sys
import dbus
import logging
import argparse
from contextlib import ExitStack
from dbus.mainloop.glib import DBusGMainLoop
from pkg_resources import resource_string as resource_bytes
from systemimage.config import config
from systemimage.dbus import Loop
from systemimage.helpers import makedirs
from systemimage.logging import initialize
from systemimage.main import DEFAULT_CONFIG_FILE
# --testing is only enabled when the systemimage.testing package is
# available. This will be the case for the upstream source package, and when
# the systemimage-dev binary package is installed in Ubuntu.
try:
from systemimage.testing.dbus import instrument, get_service
except ImportError:
instrument = None
get_service = None
__version__ = resource_bytes(
'systemimage', 'version.txt').decode('utf-8').strip()
def main():
global config
parser = argparse.ArgumentParser(
prog='system-image-dbus',
description='Ubuntu System Image Upgrader DBus service')
parser.add_argument('--version',
action='version',
version='system-image-dbus {}'.format(__version__))
parser.add_argument('-C', '--config',
default=DEFAULT_CONFIG_FILE, action='store',
metavar='FILE',
help="""Use the given configuration file instead of
the default""")
parser.add_argument('-v', '--verbose',
default=0, action='count',
help='Increase verbosity')
# Hidden argument for special setup required by test environment.
if instrument is not None:
parser.add_argument('--testing',
default=False, action='store',
help=argparse.SUPPRESS)
args = parser.parse_args(sys.argv[1:])
try:
config.load(args.config)
except FileNotFoundError as error:
parser.error('\nConfiguration file not found: {}'.format(error))
assert 'parser.error() does not return'
# Load the optional channel.ini file, which must live next to the
# configuration file. It's okay if this file does not exist.
channel_ini = os.path.join(os.path.dirname(args.config), 'channel.ini')
try:
config.load(channel_ini, override=True)
except FileNotFoundError:
pass
# Create the temporary directory if it doesn't exist.
makedirs(config.system.tempdir)
# Initialize the loggers.
initialize(verbosity=args.verbose)
log = logging.getLogger('systemimage')
DBusGMainLoop(set_as_default=True)
system_bus = dbus.SystemBus()
# Ensure we're the only owner of this bus name.
code = system_bus.request_name(
'com.canonical.SystemImage',
dbus.bus.NAME_FLAG_DO_NOT_QUEUE)
if code == dbus.bus.REQUEST_NAME_REPLY_EXISTS:
# Another instance already owns this name. Exit.
log.error('Cannot get exclusive ownership of bus name.')
sys.exit(2)
log.info('SystemImage dbus main loop starting [{}/{}]',
config.channel, config.device)
with ExitStack() as stack:
loop = Loop()
testing_mode = getattr(args, 'testing', None)
if testing_mode:
instrument(config, stack)
config.dbus_service = get_service(
testing_mode, system_bus, '/Service', loop)
else:
from systemimage.dbus import Service
config.dbus_service = Service(system_bus, '/Service', loop)
try:
loop.run()
except KeyboardInterrupt:
log.info('SystemImage dbus main loop interrupted')
except:
log.exception('D-Bus loop exception')
raise
else:
log.info('SystemImage dbus main loop exited')
if __name__ == '__main__':
sys.exit(main())
|