Permalink
Browse files

- work on dbus interface

  • Loading branch information...
1 parent edd7552 commit 0bc6b8b63153da4408a41ba8329f028568bc29d1 @aschnell aschnell committed May 23, 2012
Showing with 118 additions and 28 deletions.
  1. +25 −28 client/cleanup.cc
  2. +19 −0 client/commands.cc
  3. +3 −0 client/commands.h
  4. +15 −0 examples/python/get-config.py
  5. +35 −0 server/snapperd.cc
  6. +17 −0 snapper/AsciiFile.cc
  7. +2 −0 snapper/AsciiFile.h
  8. +2 −0 snapper/Snapper.h
View
53 client/cleanup.cc
@@ -22,9 +22,12 @@
#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);
View
19 client/commands.cc
@@ -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)
{
View
3 client/commands.h
@@ -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);
View
15 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)
+
View
35 server/snapperd.cc
@@ -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);
@@ -343,6 +351,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)
{
string config_name;
@@ -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"))
View
17 snapper/AsciiFile.cc
@@ -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;
+ }
+
}
View
2 snapper/AsciiFile.h
@@ -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;
View
2 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<Snapshots::iterator>& tmp, time_t min_age);

0 comments on commit 0bc6b8b

Please sign in to comment.