#include <algorithm>
+#include <snapper/SnapperTmpl.h>
+
#include "commands.h"
+using namespace snapper;
using namespace std;
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);
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;
{
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);
}
+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)
{
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);
--- /dev/null
+#!/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)
+
#include <snapper/Comparison.h>
#include <snapper/Log.h>
#include <snapper/SnapperTmpl.h>
+#include <snapper/AsciiFile.h>
#include "dbus/DBusConnection.h"
#include "dbus/DBusMessage.h"
" <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"
void
reply_to_command_list_configs(DBus::Connection& conn, DBus::Message& msg)
{
+ y2mil("ListConfigs");
+
list<ConfigInfo> config_infos = Snapper::getConfigs();
DBus::MessageMethodReturn reply(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)
{
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"))
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;
+ }
+
}
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;
const Filesystem* getFilesystem() const { return filesystem; }
+ const SysconfigFile* getSysconfigFile() const { return config; }
+
private:
void filter1(list<Snapshots::iterator>& tmp, time_t min_age);