From: Arvin Schnell Date: Wed, 23 May 2012 14:38:38 +0000 (+0200) Subject: - work on dbus interface X-Git-Tag: v0.1.3~227 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0bc6b8b63153da4408a41ba8329f028568bc29d1;p=thirdparty%2Fsnapper.git - work on dbus interface --- diff --git a/client/cleanup.cc b/client/cleanup.cc index c45dc04e..d23f295a 100644 --- a/client/cleanup.cc +++ b/client/cleanup.cc @@ -22,9 +22,12 @@ #include +#include + #include "commands.h" +using namespace snapper; using namespace std; @@ -88,14 +91,12 @@ do_cleanup_number(DBus::Connection& conn, const string& config_name) time_t min_age = 1800; size_t limit = 50; - /* - TODO - string val; - if (config->getValue("NUMBER_MIN_AGE", val)) - val >> min_age; - if (config->getValue("NUMBER_LIMIT", val)) - val >> limit; - */ + map c = command_get_xxconfig(conn, config_name); + map::const_iterator pos; + if ((pos = c.find("NUMBER_MIN_AGE")) != c.end()) + pos->second >> min_age; + if ((pos = c.find("NUMBER_LIMIT")) != c.end()) + pos->second >> limit; XSnapshots snapshots = command_list_xsnapshots(conn, config_name); @@ -221,20 +222,18 @@ do_cleanup_timeline(DBus::Connection& conn, const string& config_name) size_t limit_monthly = 10; size_t limit_yearly = 10; - /* - TODO - string val; - if (config->getValue("TIMELINE_MIN_AGE", val)) - val >> min_age; - if (config->getValue("TIMELINE_LIMIT_HOURLY", val)) - val >> limit_hourly; - if (config->getValue("TIMELINE_LIMIT_DAILY", val)) - val >> limit_daily; - if (config->getValue("TIMELINE_LIMIT_MONTHLY", val)) - val >> limit_monthly; - if (config->getValue("TIMELINE_LIMIT_YEARLY", val)) - val >> limit_yearly; - */ + map c = command_get_xxconfig(conn, config_name); + map::const_iterator pos; + if ((pos = c.find("TIMELINE_MIN_AGE")) != c.end()) + pos->second >> min_age; + if ((pos = c.find("TIMELINE_LIMIT_HOURLY")) != c.end()) + pos->second >> limit_hourly; + if ((pos = c.find("TIMELINE_LIMIT_DAILY")) != c.end()) + pos->second >> limit_daily; + if ((pos = c.find("TIMELINE_LIMIT_MONTHLY")) != c.end()) + pos->second >> limit_monthly; + if ((pos = c.find("TIMELINE_LIMIT_YEARLY")) != c.end()) + pos->second >> limit_yearly; size_t num_hourly = 0; size_t num_daily = 0; @@ -297,12 +296,10 @@ do_cleanup_empty_pre_post(DBus::Connection& conn, const string& config_name) { time_t min_age = 1800; - /* - TODO - string val; - if (config->getValue("EMPTY_PRE_POST_MIN_AGE", val)) - val >> min_age; - */ + map c = command_get_xxconfig(conn, config_name); + map::const_iterator pos; + if ((pos = c.find("EMPTY_PRE_POST_MIN_AGE")) != c.end()) + pos->second >> min_age; XSnapshots snapshots = command_list_xsnapshots(conn, config_name); diff --git a/client/commands.cc b/client/commands.cc index 3e87226d..e8c3bbec 100644 --- a/client/commands.cc +++ b/client/commands.cc @@ -55,6 +55,25 @@ command_get_xconfig(DBus::Connection& conn, const string& config_name) } +map +command_get_xxconfig(DBus::Connection& conn, const string& config_name) +{ + DBus::MessageMethodCall call(SERVICE, OBJECT, INTERFACE, "GetConfig"); + + DBus::Hoho hoho(call); + hoho << config_name; + + DBus::Message reply = conn.send_and_reply_and_block(call); + + map ret; + + DBus::Hihi hihi(reply); + hihi >> ret; + + return ret; +} + + list command_list_xconfigs(DBus::Connection& conn) { diff --git a/client/commands.h b/client/commands.h index c672ca18..bbb552f5 100644 --- a/client/commands.h +++ b/client/commands.h @@ -40,6 +40,9 @@ using std::map; XConfigInfo command_get_xconfig(DBus::Connection& conn, const string& config_name); +map +command_get_xxconfig(DBus::Connection& conn, const string& config_name); + list command_list_xconfigs(DBus::Connection& conn); diff --git a/examples/python/get-config.py b/examples/python/get-config.py new file mode 100755 index 00000000..814576a8 --- /dev/null +++ b/examples/python/get-config.py @@ -0,0 +1,15 @@ +#!/usr/bin/python + +import dbus + +bus = dbus.SystemBus() + +snapper = dbus.Interface(bus.get_object('org.opensuse.snapper', '/org/opensuse/snapper'), + dbus_interface='org.opensuse.snapper') + + +config = snapper.GetConfig("root") + +for k, v in config.items(): + print "%s=%s" % (k, v) + diff --git a/server/snapperd.cc b/server/snapperd.cc index 628b05d5..0f7c2dc7 100644 --- a/server/snapperd.cc +++ b/server/snapperd.cc @@ -34,6 +34,7 @@ #include #include #include +#include #include "dbus/DBusConnection.h" #include "dbus/DBusMessage.h" @@ -82,6 +83,11 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg) " \n" " \n" + " \n" + " \n" + " \n" + " \n" + " \n" " \n" " \n" @@ -305,6 +311,8 @@ send_signal_snapshots_deleted(DBus::Connection& conn, const string& config_name, void reply_to_command_list_configs(DBus::Connection& conn, DBus::Message& msg) { + y2mil("ListConfigs"); + list config_infos = Snapper::getConfigs(); DBus::MessageMethodReturn reply(msg); @@ -342,6 +350,31 @@ reply_to_command_create_config(DBus::Connection& conn, DBus::Message& msg) } +void +reply_to_command_get_config(DBus::Connection& conn, DBus::Message& msg) +{ + string config_name; + + DBus::Hihi hihi(msg); + hihi >> config_name; + + y2mil("GetConfig config_name:" << config_name); + + check_permission(conn, msg, config_name); + + Snapper* snapper = getSnapper(config_name); + + map tmp = snapper->getSysconfigFile()->getAllValues(); + + DBus::MessageMethodReturn reply(msg); + + DBus::Hoho hoho(reply); + hoho << tmp; + + conn.send(reply); +} + + void reply_to_command_delete_config(DBus::Connection& conn, DBus::Message& msg) { @@ -891,6 +924,8 @@ dispatch(DBus::Connection& conn, DBus::Message& msg) reply_to_command_list_configs(conn, msg); else if (msg.is_method_call(INTERFACE, "CreateConfig")) reply_to_command_create_config(conn, msg); + else if (msg.is_method_call(INTERFACE, "GetConfig")) + reply_to_command_get_config(conn, msg); else if (msg.is_method_call(INTERFACE, "DeleteConfig")) reply_to_command_delete_config(conn, msg); else if (msg.is_method_call(INTERFACE, "LockConfig")) diff --git a/snapper/AsciiFile.cc b/snapper/AsciiFile.cc index 38ffdccf..cc829a10 100644 --- a/snapper/AsciiFile.cc +++ b/snapper/AsciiFile.cc @@ -223,4 +223,21 @@ AsciiFile::save() return true; } + + map + SysconfigFile::getAllValues() const + { + map ret; + + Regex rx('^' + Regex::ws + "([0-9A-Z_]+)" + '=' + "(['\"]?)([^'\"]*)\\2" + Regex::ws + '$'); + + for (vector::const_iterator it = Lines_C.begin(); it != Lines_C.end(); ++it) + { + if (rx.match(*it)) + ret[rx.cap(1)] = rx.cap(3); + } + + return ret; + } + } diff --git a/snapper/AsciiFile.h b/snapper/AsciiFile.h index ccd7736b..b3f5cc75 100644 --- a/snapper/AsciiFile.h +++ b/snapper/AsciiFile.h @@ -100,6 +100,8 @@ namespace snapper void setValue(const string& key, const vector& values); bool getValue(const string& key, vector& values) const; + map getAllValues() const; + private: bool modified; diff --git a/snapper/Snapper.h b/snapper/Snapper.h index fe47f6f4..dcd71816 100644 --- a/snapper/Snapper.h +++ b/snapper/Snapper.h @@ -165,6 +165,8 @@ namespace snapper const Filesystem* getFilesystem() const { return filesystem; } + const SysconfigFile* getSysconfigFile() const { return config; } + private: void filter1(list& tmp, time_t min_age);