This repository has been archived by the owner on Apr 26, 2020. It is now read-only.
forked from kalkin/qubes-dbus
-
-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
72 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) |