1
0
forked from drath/libratbag

Drop the SVG handling from libratbag

The SVGs must not be part of any stable API, there is too much behavior
implied that we cannot/do not specify. So it's perfectly likely that a future
change in the SVGs or rendering libraries breaks things in some detail. But
then we cannot update the SVGs without risking breaking other clients that
rely on the current behavior.

Besides: we only have one theme, called "gnome" because a push
towards having SVGs for other themes never happened.

And that theme isn't gnome-specific, it merely looks GNOMEy. The theme is very
much piper-specific in that it requires certain elements that piper cares
about. Currently anyway, if we make this part of our API, piper cannot change
that behavior ever without breaking others.

So let's drop SVG handling completely and rely on the clients to sort it out
for themselves.

For now the SVGs are left in the tree to make it easier to copy to Piper. Once
that's done, we will remove those too.

Signed-off-by: Peter Hutterer <peter.hutterer@who-t.net>
This commit is contained in:
Peter Hutterer
2019-02-21 10:29:48 +10:00
committed by Benjamin Tissoires
parent 10a1cc9bbc
commit 734977f176
54 changed files with 2 additions and 341 deletions

View File

@@ -35,7 +35,6 @@ libratbag_references:
command: |
PREFIX=/usr/local/
diff -u <(cd data/devices; ls *.device) <(cd $PREFIX/share/libratbag/devices; ls *.device)
diff -u <(cd data/gnome; ls *.svg) <(cd $PREFIX/share/libratbag/gnome; ls *.svg)
check_uninstall: &check_uninstall
run:
name: Checking if any files are left after uninstall

View File

@@ -29,9 +29,6 @@ import argparse
import os
import configparser
# Set on commandline with --svg-dir
svg_dirs = []
def assertIn(element, l):
if element not in l:
raise AssertionError('{} must be in {}'.format(element, l))
@@ -42,18 +39,6 @@ def assertNotIn(element, l):
raise AssertionError('{} must not be in {}'.format(element, l))
def check_svg_str(string):
assert(string.endswith('.svg'))
svg_file_found = False
for svg_dir in svg_dirs:
files = os.listdir(svg_dir)
if string in files:
svg_file_found = True
break
assert(svg_file_found)
def check_match_str(string):
bustypes = ['usb', 'bluetooth']
@@ -84,7 +69,7 @@ def check_ledtypes_str(string):
def check_section_device(section):
required_keys = ['Name', 'Driver', 'DeviceMatch']
permitted_keys = required_keys + ['Svg', 'LedTypes']
permitted_keys = required_keys + ['LedTypes']
for key in section.keys():
assertIn(key, permitted_keys)
@@ -92,11 +77,6 @@ def check_section_device(section):
for r in required_keys:
assertIn(r, section)
try:
check_svg_str(section['Svg'])
except KeyError:
pass
try:
check_ledtypes_str(section['LedTypes'])
except KeyError:
@@ -234,10 +214,6 @@ def parse_data_file(path):
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Device data-file checker")
parser.add_argument('file', nargs='+')
parser.add_argument('--svg-dir', metavar='dir', action='append',
type=str,
help='Directory to check for SVG files (may be given multiple times)')
args = parser.parse_args()
svg_dirs = args.svg_dir
for path in args.file:
parse_data_file(path)

View File

@@ -12,9 +12,6 @@ Name=Logitech Example Device
# zeroes.
DeviceMatch=usb:12ab:00f2
# The file name of the SVG file representing this device
Svg=logitech-example.svg
# The libratbag driver backend
Driver=hidpp10

View File

@@ -2,4 +2,3 @@
Name=Etekcity Scroll Alpha
DeviceMatch=usb:1ea7:4011
Driver=etekcity
Svg=etekcity.svg

View File

@@ -2,4 +2,3 @@
Name=Logitech MX Anywhere 2
DeviceMatch=usb:046d:404a;bluetooth:046d:b013
Driver=hidpp20
Svg=logitech-mx-anywhere2.svg

View File

@@ -2,4 +2,3 @@
Name=Logitech MX Anywhere 2S
DeviceMatch=usb:046d:406a
Driver=hidpp20
Svg=logitech-mx-anywhere2.svg

View File

@@ -3,4 +3,3 @@
Name=Logitech MX Master 2S
DeviceMatch=bluetooth:046d:b019;usb:046d:4069
Driver=hidpp20
Svg=logitech-mx-master-2s.svg

View File

@@ -3,4 +3,3 @@
Name=Logitech MX Master
DeviceMatch=usb:046d:4041;bluetooth:046d:b012;usb:046d:4060
Driver=hidpp20
Svg=logitech-mx-master.svg

View File

@@ -1,7 +1,6 @@
[Device]
Name=Logitech G Pro Wireless
DeviceMatch=usb:046d:c539;usb:046d:c088
Svg=logitech-g-pro-wireless.svg
LedTypes=logo;battery;dpi;
Driver=hidpp20

View File

@@ -1,6 +1,5 @@
[Device]
Name=Logitech Gaming Mouse G Pro
DeviceMatch=usb:046d:c085
Svg=logitech-g-pro.svg
Driver=hidpp20
LedTypes=logo;side

View File

@@ -2,6 +2,5 @@
[Device]
Name=Logitech Gaming Mouse G102/G103
DeviceMatch=usb:046d:c084
Svg=logitech-g102-g203.svg
Driver=hidpp20
LedTypes=logo;side;

View File

@@ -3,4 +3,3 @@
Name=Logitech G300
DeviceMatch=usb:046d:c246
Driver=logitech_g300
Svg=logitech-g300.svg

View File

@@ -2,6 +2,5 @@
[Device]
Name=Logitech Gaming Mouse G302
DeviceMatch=usb:046d:c07f
Svg=logitech-g303.svg
Driver=hidpp20
LedTypes=logo;side;

View File

@@ -2,6 +2,5 @@
[Device]
Name=Logitech Gaming Mouse G303
DeviceMatch=usb:046d:c080
Svg=logitech-g303.svg
Driver=hidpp20
LedTypes=logo;side;

View File

@@ -3,4 +3,3 @@
Name=Logitech G402 Gaming Mouse
DeviceMatch=usb:046d:c07e
Driver=hidpp20
Svg=logitech-g402.svg

View File

@@ -3,4 +3,3 @@
Name=Logitech G403
DeviceMatch=usb:046d:c082;usb:046d:c083
Driver=hidpp20
Svg=logitech-g403.svg

View File

@@ -2,7 +2,6 @@
Name=Logitech G500
DeviceMatch=usb:046d:c068
Driver=hidpp10
Svg=logitech-g500.svg
[Driver/hidpp10]
DpiRange=0:5700@23.53

View File

@@ -2,7 +2,6 @@
Name=Logitech G500s
DeviceMatch=usb:046d:c24e
Driver=hidpp10
Svg=logitech-g500s.svg
[Driver/hidpp10]
DpiRange=0:8200@50

View File

@@ -3,4 +3,3 @@
Name=Logitech G502 HERO
DeviceMatch=usb:046d:c08b
Driver=hidpp20
Svg=logitech-g502.svg

View File

@@ -3,4 +3,3 @@
Name=Logitech G502 Proteus Core
DeviceMatch=usb:046d:c07d
Driver=hidpp20
Svg=logitech-g502.svg

View File

@@ -3,4 +3,3 @@
Name=Logitech G502 Proteus Spectrum
DeviceMatch=usb:046d:c332
Driver=hidpp20
Svg=logitech-g502.svg

View File

@@ -3,4 +3,3 @@
Name=Logitech G600
DeviceMatch=usb:046d:c24a
Driver=logitech_g600
Svg=logitech-g600.svg

View File

@@ -3,4 +3,3 @@
Name=Logitech G603
DeviceMatch=bluetooth:046d:b01c
Driver=hidpp20
Svg=logitech-g603.svg

View File

@@ -4,7 +4,6 @@
Name=Logitech G700
DeviceMatch=usb:046d:c06b
Driver=hidpp10
Svg=logitech-g700.svg
[Driver/hidpp10]
DpiRange=0:5700@23.53

View File

@@ -4,7 +4,6 @@
Name=Logitech G700s
DeviceMatch=usb:046d:c531
Driver=hidpp10
Svg=logitech-g700.svg
[Driver/hidpp10]
DpiRange=0:8200@50

View File

@@ -4,7 +4,6 @@
Name=Logitech G700s
DeviceMatch=usb:046d:c07c
Driver=hidpp10
Svg=logitech-g700.svg
[Driver/hidpp10]
DpiRange=0:8200@50

View File

@@ -2,5 +2,4 @@
Name=Logitech G703
DeviceMatch=usb:046d:c087
Driver=hidpp20
Svg=logitech-g703.svg

View File

@@ -5,7 +5,6 @@ Name=Logitech G9
DeviceMatch=usb:046d:c048
LedTypes=dpi
Driver=hidpp10
Svg=logitech-g9.svg
[Driver/hidpp10]
DpiList=200;400;600;800;1000;1200;1400;1600;1800;2000;2200;2400;2600;2800;3000;3200

View File

@@ -3,7 +3,6 @@
Name=Logitech G900, G903, G603, G403
DeviceMatch=usb:046d:c539
Driver=hidpp20
Svg=logitech-g900.svg
[Driver/hidpp20]
DeviceIndex=1

View File

@@ -3,4 +3,3 @@
Name=Logitech G900
DeviceMatch=usb:046d:c081
Driver=hidpp20
Svg=logitech-g900.svg

View File

@@ -3,4 +3,3 @@
Name=Logitech G903
DeviceMatch=usb:046d:c086
Driver=hidpp20
Svg=logitech-g900.svg

View File

@@ -3,7 +3,6 @@
Name=Logitech G PowerPlay mouse pad.
DeviceMatch=usb:046d:c53a
Driver=hidpp20
Svg=logitech-g900.svg
[Driver/hidpp20]
DeviceIndex=1

View File

@@ -2,4 +2,3 @@
Name=Roccat Kone XTD
DeviceMatch=usb:1e7d:2e22
Driver=roccat
Svg=roccat-kone-xtd.svg

View File

@@ -2,7 +2,6 @@
Name=SteelSeries Kinzu V2
DeviceMatch=usb:1038:1378
Driver=steelseries
Svg=steelseries-kinzu-v2.svg
[Driver/steelseries]
DeviceVersion=1

View File

@@ -2,7 +2,6 @@
Name=SteelSeries Rival 310
DeviceMatch=usb:1038:1720
Driver=steelseries
Svg=steelseries-rival310.svg
[Driver/steelseries]
DeviceVersion=2

View File

@@ -2,7 +2,6 @@
Name=SteelSeries Rival 600
DeviceMatch=usb:1038:1724
Driver=steelseries
Svg=steelseries-rival600.svg
[Driver/steelseries]
DeviceVersion=3

View File

@@ -2,7 +2,6 @@
Name=SteelSeries Rival
DeviceMatch=usb:1038:1384
Driver=steelseries
Svg=steelseries-rival.svg
[Driver/steelseries]
DeviceVersion=1

View File

@@ -2,7 +2,6 @@
Name=SteelSeries Sensei 310
DeviceMatch=usb:1038:1722
Driver=steelseries
Svg=steelseries-sensei310.svg
[Driver/steelseries]
DeviceVersion=2

View File

@@ -2,7 +2,6 @@
Name=SteelSeries Sensei Raw
DeviceMatch=usb:1038:1369
Driver=steelseries
Svg=steelseries-senseiraw.svg
LedTypes=logo;dpi
[Driver/steelseries]

View File

@@ -90,18 +90,6 @@ interact with ratbagd.
An array of read-only object paths referencing the available
devices. The devices implement the :ref:`device` interface.
.. attribute:: Themes
:type: as
:flags: read-only, constant
The list of available theme names. This list is guaranteed to have
at least one theme available ('default'). Other themes are
implementation-defined. A theme listed here is only a guarantee
that the theme is known to libratbag and that SVGs *may* exist, it
is not a guarantee that the SVG for any specific device exists. In
other words, a device may not have an SVG for a specific theme.
.. _device:
org.freedesktop.ratbag1.Device
@@ -196,21 +184,6 @@ known to ratbagd.
occurs, the :func:`Resync` signal is emitted and all properties are
updated to the current state.
.. function:: GetSvgFd(s) → (h)
:param s: the theme name
:returns: An open file descriptor to the SVG for the given theme
Returns an open file descriptor to the SVG for the given theme or an
errno on error. The theme must be one of
:func:`org.freedesktop.ratbag1.Manager.Themes <Themes>`.
The theme **'default'** is guaranteed to be available.
ratbagd may return ``ENOENT`` if a file doesn't exist.
This is the case if the device has SVGs available but not
for the given theme.
.. function:: Resync()
:type: Signal

View File

@@ -319,47 +319,7 @@ install_data(data_files,
install_dir : join_paths(get_option('datadir'), 'libratbag', 'devices'))
data_parse_test = find_program(join_paths(meson.source_root(), 'data/devices/data-parse-test.py'))
test('data-parse-test', data_parse_test,
args : [ '--svg-dir', join_paths(meson.source_root(), 'data/default'),
'--svg-dir', join_paths(meson.source_root(), 'data/gnome') ] + data_files)
#### svg files ####
# list ordered by git ls-files data/gnome/*.svg
gnome_svg_files = files(
'data/gnome/fallback.svg',
'data/gnome/logitech-g102-g203.svg',
'data/gnome/logitech-g300.svg',
'data/gnome/logitech-g303.svg',
'data/gnome/logitech-g402.svg',
'data/gnome/logitech-g403.svg',
'data/gnome/logitech-g500.svg',
'data/gnome/logitech-g500s.svg',
'data/gnome/logitech-g502.svg',
'data/gnome/logitech-g600.svg',
'data/gnome/logitech-g603.svg',
'data/gnome/logitech-g700.svg',
'data/gnome/logitech-g703.svg',
'data/gnome/logitech-g9.svg',
'data/gnome/logitech-g900.svg',
'data/gnome/logitech-g-pro.svg',
'data/gnome/logitech-g-pro-wireless.svg',
'data/gnome/logitech-mx-anywhere2.svg',
'data/gnome/logitech-mx-anywhere2s.svg',
'data/gnome/logitech-mx-master-2s.svg',
'data/gnome/logitech-mx-master.svg',
'data/gnome/roccat-kone-xtd.svg',
'data/gnome/steelseries-kinzu-v2.svg',
'data/gnome/steelseries-rival.svg',
'data/gnome/steelseries-rival310.svg',
'data/gnome/steelseries-rival600.svg',
'data/gnome/steelseries-sensei310.svg',
'data/gnome/steelseries-senseiraw.svg',
)
install_data(gnome_svg_files,
install_dir : join_paths(get_option('datadir'), 'libratbag', 'gnome'))
test_svg_files = find_program('data/gnome/check-svg.py')
test('check-svg', test_svg_files, args : gnome_svg_files)
test('data-parse-test', data_parse_test, args: data_files)
#### tests ####
enable_tests = get_option('tests')

View File

@@ -136,48 +136,6 @@ static int ratbagd_device_get_device_name(sd_bus *bus,
return 0;
}
static int ratbagd_device_get_theme_svg_fd(sd_bus_message *m,
void *userdata,
sd_bus_error *error)
{
struct ratbagd_device *device = userdata;
char svg_path[PATH_MAX] = {0};
const char *theme;
const char *svg;
const char *datadir;
_cleanup_close_ int fd = -1;
datadir = getenv("LIBRATBAG_DATA_DIR");
if (!datadir)
datadir = LIBRATBAG_DATA_DIR;
CHECK_CALL(sd_bus_message_read(m, "s", &theme));
if (streq(theme, "default"))
theme = "gnome";
svg = ratbag_device_get_svg_name(device->lib_device);
if (!svg) {
log_error("%s: failed to fetch SVG, using fallback\n",
ratbagd_device_get_sysname(device));
svg = FALLBACK_SVG_NAME;
}
snprintf(svg_path, sizeof(svg_path), "%s/%s/%s", datadir, theme, svg);
fd = open(svg_path, O_RDONLY);
if (fd == -1) {
log_error("%s: failed to open SVG '%s' (%m)\n",
ratbagd_device_get_sysname(device),
svg_path);
return -ENOENT;
}
CHECK_CALL(sd_bus_reply_method_return(m, "h", fd));
return 0;
}
static int ratbagd_device_get_profiles(sd_bus *bus,
const char *path,
const char *interface,
@@ -264,7 +222,6 @@ const sd_bus_vtable ratbagd_device_vtable[] = {
SD_BUS_PROPERTY("Model", "s", ratbag_device_get_model, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Name", "s", ratbagd_device_get_device_name, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_PROPERTY("Profiles", "ao", ratbagd_device_get_profiles, 0, SD_BUS_VTABLE_PROPERTY_CONST),
SD_BUS_METHOD("GetSvgFd", "s", "h", ratbagd_device_get_theme_svg_fd, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_METHOD("Commit", "", "u", ratbagd_device_commit, SD_BUS_VTABLE_UNPRIVILEGED),
SD_BUS_SIGNAL("Resync", "", 0),
SD_BUS_VTABLE_END,

View File

@@ -39,7 +39,6 @@ static const struct ratbag_test_device ratbagd_test_device_descr = {
.num_resolutions = 3,
.num_buttons = 4,
.num_leds = 3,
.svg = "fallback.svg",
.profiles = {
{
.name = NULL,

View File

@@ -49,12 +49,6 @@ enum log_level {
LL_RAW,
} log_level = LL_INFO;
static const char *SVG_THEMES[] = {
"default",
"gnome",
NULL
};
void log_info(const char *fmt, ...)
{
va_list args;
@@ -170,34 +164,9 @@ static int ratbagd_get_devices(sd_bus *bus,
return 0;
}
static int ratbagd_get_themes(sd_bus *bus,
const char *path,
const char *interface,
const char *property,
sd_bus_message *reply,
void *userdata,
sd_bus_error *error)
{
struct ratbagd *ctx = userdata;
const char **theme;
CHECK_CALL(sd_bus_message_open_container(reply, 'a', "s"));
theme = ctx->themes;
while(*theme) {
CHECK_CALL(sd_bus_message_append(reply, "s", *theme));
theme++;
}
CHECK_CALL(sd_bus_message_close_container(reply));
return 0;
}
static const sd_bus_vtable ratbagd_vtable[] = {
SD_BUS_VTABLE_START(0),
SD_BUS_PROPERTY("Devices", "ao", ratbagd_get_devices, 0, SD_BUS_VTABLE_PROPERTY_EMITS_CHANGE),
SD_BUS_PROPERTY("Themes", "as", ratbagd_get_themes, 0, 0),
#ifdef RATBAG_DEVELOPER_EDITION
SD_BUS_METHOD("ResetTestDevice", "", "u", ratbagd_reset_test_device, SD_BUS_VTABLE_UNPRIVILEGED),
#endif /* RATBAG_DEVELOPER_EDITION */
@@ -441,7 +410,6 @@ static int ratbagd_new(struct ratbagd **out)
int r;
ctx = zalloc(sizeof(*ctx));
ctx->themes = SVG_THEMES;
r = sd_event_default(&ctx->event);
if (r < 0)

View File

@@ -156,13 +156,6 @@ test_write_led(struct ratbag_led *led,
return 0;
}
static const char* test_get_svg_name(const struct ratbag_device *device)
{
struct ratbag_test_device *d = ratbag_get_drv_data(device);
return d->svg;
}
static int
test_fake_probe(struct ratbag_device *device)
{
@@ -294,7 +287,6 @@ struct ratbag_driver test_driver = {
.probe = test_fake_probe,
.test_probe = test_probe,
.remove = test_remove,
.get_svg_name = test_get_svg_name,
.write_profile = test_write_profile,
.set_active_profile = test_set_active_profile,
.write_button = test_write_button,

View File

@@ -81,7 +81,6 @@ struct ratbag_device_data {
int refcount;
char *name;
char *driver;
char *svg;
enum driver drivertype;
@@ -261,12 +260,6 @@ ratbag_device_data_get_name(const struct ratbag_device_data *data)
return data->name;
}
const char *
ratbag_device_data_get_svg(const struct ratbag_device_data *data)
{
return data->svg;
}
enum ratbag_led_type
ratbag_device_data_get_led_type(const struct ratbag_device_data *data,
unsigned int index)
@@ -295,7 +288,6 @@ ratbag_device_data_destroy(struct ratbag_device_data *data)
}
free(data->name);
free(data->driver);
free(data->svg);
free(data);
}
@@ -436,8 +428,6 @@ file_data_matches(struct ratbag *ratbag,
}
}
data->svg = g_key_file_get_string(keyfile, GROUP_DEVICE, "Svg", NULL);
ledtypes_strv = g_key_file_get_string_list(keyfile, GROUP_DEVICE, "LedTypes", NULL, NULL);
if (parse_ledtypes(ledtypes_strv, data->led_types, ARRAY_LENGTH(data->led_types)) < 0) {
log_error(ratbag, "Invalid LedTypes string in '%s'\n", basename(path));

View File

@@ -40,8 +40,6 @@ const char *
ratbag_device_data_get_driver(const struct ratbag_device_data *data);
const char *
ratbag_device_data_get_name(const struct ratbag_device_data *data);
const char *
ratbag_device_data_get_svg(const struct ratbag_device_data *data);
enum ratbag_led_type
ratbag_device_data_get_led_type(const struct ratbag_device_data *data,
unsigned int index);

View File

@@ -192,15 +192,6 @@ struct ratbag_driver {
*/
int (*commit)(struct ratbag_device *device);
/**
* Callback called when the device doesn't have a .device file with
* an SVG name set.
*
* The returned value must not be free by the caller, the driver
* has to free it during .remove().
*/
const char *(*get_svg_name)(const struct ratbag_device *device);
/*
* FIXME: This function is deprecated and should be removed. Once
* we've updated all the device drivers to stop using it we'll remove

View File

@@ -90,7 +90,6 @@ struct ratbag_test_device {
unsigned int num_resolutions;
unsigned int num_buttons;
unsigned int num_leds;
const char *svg;
struct ratbag_test_profile profiles[RATBAG_TEST_MAX_PROFILES];
void (*destroyed)(struct ratbag_device *device, void *data);
void *destroyed_data;

View File

@@ -504,19 +504,6 @@ ratbag_device_get_name(const struct ratbag_device* device)
return device->name;
}
LIBRATBAG_EXPORT const char *
ratbag_device_get_svg_name(const struct ratbag_device* device)
{
const char *name = NULL;
if (device->data)
name = ratbag_device_data_get_svg(device->data);
if (!name && device->driver->get_svg_name)
name = device->driver->get_svg_name(device);
return name;
}
LIBRATBAG_EXPORT const char *
ratbag_device_get_bustype(const struct ratbag_device *device)
{

View File

@@ -430,16 +430,6 @@ ratbag_device_get_user_data(const struct ratbag_device *device);
const char *
ratbag_device_get_name(const struct ratbag_device* device);
/**
* @ingroup device
*
* @param device A previously initialized ratbag device
* @return The file name of the svg drawing associated with the given ratbag.
* If there is no file associated to the device, NULL is returned.
*/
const char *
ratbag_device_get_svg_name(const struct ratbag_device* device);
/**
* @ingroup device
*

View File

@@ -201,12 +201,6 @@ class Ratbagd(object):
return self._devices[id] if id in self._devices.keys() else None
@property
def themes(self):
"""A list of theme names. The theme 'default' is guaranteed to be
available."""
return ["default", "gnome"]
def set_verbose(self, verbose):
if verbose > 2:
libratbag.ratbag_log_set_priority(self._ratbag, libratbag.RATBAG_LOG_PRIORITY_RAW)
@@ -282,20 +276,6 @@ class RatbagdDevice(metaclass=MetaRatbag):
print("No active profile. Please report this bug to the libratbag developers", file=sys.stderr)
return self._profiles[0]
def get_svg_fd(self, theme):
"""Returns a File-like object to the SVG for the given theme, or
raises FileNotFoundError if the file is not available.
The theme must be one of org.freedesktop.ratbag1.Manager.Themes. The
theme 'default' is guaranteed to be available (but the file itself
may not be).
@param theme The theme from which to retrieve the SVG, as str
"""
svg = libratbag.ratbag_device_get_svg_name(self._device)
path = os.path.join(LIBRATBAG_DATA_DIR, 'gnome', svg)
return open(path)
def commit(self):
"""Commits all changes made to the device.

View File

@@ -217,18 +217,7 @@ def print_profile(d, p, level):
def print_device(d, level):
p = d.profiles[0] # there should be always one
svg_name = 'unknown'
try:
with d.get_svg_fd('gnome') as fd:
svg = fd.read()
match = re.search('sodipodi:docname=".*"\n', svg)
if match:
svg_name = match.group(0).split('"')[1]
except FileNotFoundError:
pass
print(" " * level + "{} - {}".format(d.id, d.name))
print(" " * level + " SVG: {}".format(svg_name))
print(" " * level + " Number of Buttons: {}".format(len(p.buttons)))
print(" " * level + " Number of Leds: {}".format(len(p.leds)))
print(" " * level + "Number of Profiles: {}".format(len(d.profiles)))

View File

@@ -216,35 +216,6 @@ class _RatbagdDBus(GObject.GObject):
print(e.message, file=sys.stderr)
raise
def _dbus_call_return_one_fd(self, method, type, *value):
# Calls a method synchronously on the bus, using the given method name,
# type signature and values.
#
# It the result is valid, it is returned. Invalid results raise the
# appropriate RatbagError* or RatbagdDBus* exception, or GLib.Error if
# it is an unexpected exception that probably shouldn't be passed up to
# the UI.
val = GLib.Variant("({})".format(type), value)
try:
res = self._proxy.call_with_unix_fd_list_sync(method, val,
Gio.DBusCallFlags.NO_AUTO_START,
2000, None, None)
if res in EXCEPTION_TABLE:
raise EXCEPTION_TABLE[res]
# Result is a tuple of (GLib.Variant('(h)', (0,)), fd_list),
# we return the first file descriptor in that list
return res[1].get(0)
except GLib.Error as e:
if e.code == Gio.DBusError.FILE_NOT_FOUND:
raise FileNotFoundError('Failed to open SVG file')
elif e.code == Gio.IOErrorEnum.TIMED_OUT:
raise RatbagdDBusTimeout(e.message)
else:
# Unrecognized error code; print the message to stderr and raise
# the GLib.Error.
print(e.message, file=sys.stderr)
raise
def __eq__(self, other):
return other and self._object_path == other._object_path
@@ -301,12 +272,6 @@ class Ratbagd(_RatbagdDBus):
return d
return None
@GObject.Property
def themes(self):
"""A list of theme names. The theme 'default' is guaranteed to be
available."""
return self._get_dbus_property("Themes") or []
def __enter__(self):
return self
@@ -374,19 +339,6 @@ class RatbagdDevice(_RatbagdDBus):
print("No active profile. Please report this bug to the libratbag developers", file=sys.stderr)
return self._profiles[0]
def get_svg_fd(self, theme):
"""Returns a File-like object to the SVG for the given theme, or
raises FileNotFoundError if the file is not available.
The theme must be one of org.freedesktop.ratbag1.Manager.Themes. The
theme 'default' is guaranteed to be available (but the file itself
may not be).
@param theme The theme from which to retrieve the SVG, as str
"""
fd = self._dbus_call_return_one_fd("GetSvgFd", "s", theme)
return os.fdopen(fd)
def commit(self):
"""Commits all changes made to the device.