]> git.ipfire.org Git - thirdparty/snapper.git/commitdiff
- work on dbus interface
authorArvin Schnell <aschnell@suse.de>
Wed, 23 May 2012 14:38:38 +0000 (16:38 +0200)
committerArvin Schnell <aschnell@suse.de>
Wed, 23 May 2012 14:38:38 +0000 (16:38 +0200)
client/cleanup.cc
client/commands.cc
client/commands.h
examples/python/get-config.py [new file with mode: 0755]
server/snapperd.cc
snapper/AsciiFile.cc
snapper/AsciiFile.h
snapper/Snapper.h

index c45dc04e70287fa4d6be9bf35b9428b5c18895ac..d23f295a39c46036f3d728789cd8d62a350b422d 100644 (file)
 
 #include <algorithm>
 
+#include <snapper/SnapperTmpl.h>
+
 #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<string, string> c = command_get_xxconfig(conn, config_name);
+    map<string, string>::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<string, string> c = command_get_xxconfig(conn, config_name);
+    map<string, string>::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<string, string> c = command_get_xxconfig(conn, config_name);
+    map<string, string>::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);
 
index 3e87226d7440cf5359fb31319b670f96b4b56f63..e8c3bbec45bccac0c373d88519aa3d9af2d6a089 100644 (file)
@@ -55,6 +55,25 @@ command_get_xconfig(DBus::Connection& conn, const string& config_name)
 }
 
 
+map<string, string>
+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<string, string> ret;
+
+    DBus::Hihi hihi(reply);
+    hihi >> ret;
+
+    return ret;
+}
+
+
 list<XConfigInfo>
 command_list_xconfigs(DBus::Connection& conn)
 {
index c672ca180059c51cfb2133f4c67337d0aa6727f1..bbb552f517dc35390e110cfc65adc1d3389e6304 100644 (file)
@@ -40,6 +40,9 @@ using std::map;
 XConfigInfo
 command_get_xconfig(DBus::Connection& conn, const string& config_name);
 
+map<string, string>
+command_get_xxconfig(DBus::Connection& conn, const string& config_name);
+
 list<XConfigInfo>
 command_list_xconfigs(DBus::Connection& conn);
 
diff --git a/examples/python/get-config.py b/examples/python/get-config.py
new file mode 100755 (executable)
index 0000000..814576a
--- /dev/null
@@ -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)
+
index 628b05d54ccc28b48a8d044f38d1d00b79a74811..0f7c2dc767ac1d0e74836bfa1f9c4a8f58bc030b 100644 (file)
@@ -34,6 +34,7 @@
 #include <snapper/Comparison.h>
 #include <snapper/Log.h>
 #include <snapper/SnapperTmpl.h>
+#include <snapper/AsciiFile.h>
 
 #include "dbus/DBusConnection.h"
 #include "dbus/DBusMessage.h"
@@ -82,6 +83,11 @@ reply_to_introspect(DBus::Connection& conn, DBus::Message& msg)
        "      <arg name='template-name' type='s' direction='in'/>\n"
        "    </method>\n"
 
+       "    <method name='GetConfig'>\n"
+       "      <arg name='config-name' type='s' direction='in'/>\n"
+       "      <arg name='data' type='a{ss}' direction='out'/>\n"
+       "    </method>\n"
+
        "    <method name='DeleteConfig'>\n"
        "      <arg name='config-name' type='s' direction='in'/>\n"
        "    </method>\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<ConfigInfo> 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<string, string> 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"))
index 38ffdccfac1dc9e04a65852383091fa9d091f968..cc829a10d332b899ef7ca09031204eb55b44fb3e 100644 (file)
@@ -223,4 +223,21 @@ AsciiFile::save()
        return true;
     }
 
+
+    map<string, string>
+    SysconfigFile::getAllValues() const
+    {
+       map<string, string> ret;
+
+       Regex rx('^' + Regex::ws + "([0-9A-Z_]+)" + '=' + "(['\"]?)([^'\"]*)\\2" + Regex::ws + '$');
+
+       for (vector<string>::const_iterator it = Lines_C.begin(); it != Lines_C.end(); ++it)
+       {
+           if (rx.match(*it))
+               ret[rx.cap(1)] = rx.cap(3);
+       }
+
+       return ret;
+    }
+
 }
index ccd7736bf5db7435c90a8a4b57a3cd14db56baa4..b3f5cc753639bdb96b39e148914dd39f430bd6e4 100644 (file)
@@ -100,6 +100,8 @@ namespace snapper
        void setValue(const string& key, const vector<string>& values);
        bool getValue(const string& key, vector<string>& values) const;
 
+       map<string, string> getAllValues() const;
+
     private:
 
        bool modified;
index fe47f6f442cb7e78999e1a405eec28a1ca186fa9..dcd7181644fa80d4609afd489789664915eface7 100644 (file)
@@ -165,6 +165,8 @@ namespace snapper
 
        const Filesystem* getFilesystem() const { return filesystem; }
 
+       const SysconfigFile* getSysconfigFile() const { return config; }
+
     private:
 
        void filter1(list<Snapshots::iterator>& tmp, time_t min_age);