Skip to content
This repository has been archived by the owner on Apr 26, 2020. It is now read-only.

Commit

Permalink
Add DeviceManager & Device
Browse files Browse the repository at this point in the history
  • Loading branch information
kalkin committed Nov 8, 2016
1 parent d07e35a commit 88ca6cb
Showing 1 changed file with 72 additions and 0 deletions.
72 changes: 72 additions & 0 deletions qubesdbus/device_manager.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
# -*- encoding: utf8 -*-
# pylint: disable=invalid-name
#
# The Qubes OS Project, https://www.qubes-os.org/
#
# Copyright (C) 2016 Bahtiar `kalkin-` Gadimov <[email protected]>
# 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; either version 2 of the License, or
# (at your option) any later version.
#
# 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, write to the Free Software Foundation, Inc.,
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
''' org.qubes.DeviceManager1 Service '''
import logging
import pprint
import sys

import qubes
import systemd.journal
from gi.repository import GLib

import qubesdbus.serialize
import qubesdbus.service

log = logging.getLogger('qubesdbus.DomainManager1')
log.addHandler(
systemd.journal.JournalHandler(
level=logging.DEBUG, SYSLOG_IDENTIFIER='qubesdbus.domain_manager'))
log.propagate = True

pp = pprint.PrettyPrinter()


class DeviceManager(qubesdbus.service.ObjectManager):
def __init__(self, data):
super(DeviceManager, self).__init__()
self.managed_objects = [Device(self.bus, self.bus_name, self.bus_path,
dev) for dev in data]


class Device(qubesdbus.service.PropertiesObject):
def __init__(self, bus, bus_name, bus_path, data):
self.properties = data
pp.pprint(data)
self.name = data['ident']
bus_path = '/'.join(
[bus_path, 'devices', str(data['ident'])])
super(Device, self).__init__(self.name, 'org.qubes.Device1', data,
bus=bus, bus_name=bus_name,
bus_path=bus_path)


def main(args=None): # pylint: disable=unused-argument
''' Main function starting the DomainManager1 service. '''
loop = GLib.MainLoop()
app = qubes.Qubes()
app.domains[0].devices[
'pci'].available() # HACK this populates dom0 devices
devices = qubesdbus.serialize.devices_data(app)
_ = DeviceManager(devices)
return loop.run()


if __name__ == '__main__':
sys.exit(main())

0 comments on commit 88ca6cb

Please sign in to comment.