Permalink
Browse files

- work on python bindings

  • Loading branch information...
aschnell committed Oct 4, 2011
1 parent daad7aa commit 6e20d8866d5c0028d917b2764423292c49821a11
Showing with 139 additions and 8 deletions.
  1. +35 −1 bindings/python/examples/test.py
  2. +19 −1 bindings/python/libsnapper.i
  3. +85 −6 examples/SnapTest.cc
@@ -12,19 +12,27 @@ def print_snap_info( s ):
print s.getNum(), s.getType(), s.getDescription()
sh = libsnapper.createSnapper("root", False)
-pl = sh.getIgnorePatterns()
+
+# testing getConfigs
cl = libsnapper.Snapper.getConfigs()
print cl.size()
for i in cl: print i.config_name, i.subvolume
+
+# testing getIgnorePatterns
+pl = sh.getIgnorePatterns()
print pl.size()
for i in pl: print i
+
+# testing iterators over container
sl = sh.getSnapshots()
for i in sl: print_snap_info( i )
print sl.size()
i = sl.begin()
while i!=sl.end():
print_snap_info( i )
i.incr()
+
+# testing find functions
i = sl.find(3)
print_snap_info( i )
i = sl.getSnapshotCurrent()
@@ -35,6 +43,8 @@ def print_snap_info( s ):
print_snap_info( j )
i = sl.find(10)
print_snap_info( i )
+
+# testing handling description
j = sl.findPost(i)
print_snap_info( j )
s=j.value().getDescription()
@@ -43,6 +53,8 @@ def print_snap_info( s ):
print_snap_info( j )
s=j.value().getDescription()
j.value().setDescription(s[:-2])
+
+# testing handling userdata
j = sl.findPost(i)
print_snap_info( j )
s=j.value().getUserdata()
@@ -60,11 +72,33 @@ def print_snap_info( s ):
j = sl.findPost(i)
print_snap_info( j )
print j.value().getUserdata().items()
+
+# testing compare functionality
j=sl.find(11);
i=sl.findPre(j);
cmp=libsnapper.Comparison(sh,i,j)
i1=cmp.getSnapshot1()
i2=cmp.getSnapshot2()
print_snap_info( i1 )
print_snap_info( i2 )
+flist=cmp.getFiles()
+print flist.size()
+for f in flist:
+ print f.getAbsolutePath(libsnapper.LOC_SYSTEM), f.getAbsolutePath(libsnapper.LOC_PRE), f.getAbsolutePath(libsnapper.LOC_POST)
+ sl = f.getDiff("-u")
+ for s in sl: print s
+
+# testing set/getUndo
+f=flist.begin()
+if f != flist.end():
+ print f.value().getUndo()
+ f.value().setUndo(True)
+ print f.value().getUndo()
+ f.value().setUndo(False)
+ print f.value().getUndo()
+ f.value().setUndo(True)
+ print f.value().getUndo()
+# testing doUndo
+if f != flist.end():
+ print cmp.doUndo()
@@ -39,6 +39,14 @@ using namespace std;
%ignore snapper::Snapshots::getSnapshotCurrent() const;
%ignore snapper::Comparison::getSnapshot1() const;
%ignore snapper::Comparison::getSnapshot2() const;
+%ignore snapper::Files::begin();
+%ignore snapper::Files::begin() const;
+%ignore snapper::Files::end();
+%ignore snapper::Files::end() const;
+%ignore snapper::Files::find();
+%ignore snapper::Files::find() const;
+%ignore snapper::Files::findAbsolutePath();
+%ignore snapper::Files::findAbsolutePath() const;
%include "../../snapper/Factory.h"
%include "../../snapper/Exception.h"
@@ -52,7 +60,7 @@ using namespace snapper;
%template(vectorstring) std::vector<string>;
%std_nodefconst_type(File);
-%template(VectorFile) std::vector<File>;
+%template(vectorFile) std::vector<File, allocator< File > >;
%template(mapstringstring) std::map<string,string>;
%template(pairstringstring) std::pair<string,string>;
%template(paircstringstring) std::pair<const string,string>;
@@ -229,5 +237,15 @@ swig::SwigPyIterator* __iter__(PyObject **PYTHON_SELF)
return new MyFileIt(self->begin(), self->begin(),
self->end(), *PYTHON_SELF);
}
+swig::SwigPyIterator* begin(PyObject **PYTHON_SELF)
+ {
+ return new MyFileIt(self->begin(), self->begin(),
+ self->end(), *PYTHON_SELF);
+ }
+swig::SwigPyIterator* end(PyObject **PYTHON_SELF)
+ {
+ return new MyFileIt(self->end(), self->begin(),
+ self->end(), *PYTHON_SELF);
+ }
}
View
@@ -4,27 +4,42 @@
#include <snapper/Factory.h>
#include <snapper/Snapper.h>
+#include <snapper/Comparison.h>
+#include <snapper/File.h>
using namespace snapper;
using namespace std;
-void print_snap_info( Snapshots::const_iterator s,
+void print_snap_info( Snapshots::const_iterator s,
Snapshots::const_iterator e )
{
if( s==e )
cout << "end iterator" << endl;
else
- cout << s->getNum() << " " << s->getType() << " "
+ cout << s->getNum() << " " << s->getType() << " "
<< s->getDescription() << endl;
}
+void print_smap_info( map<string, string> const& sm )
+ {
+ cout << "[";
+ for( map<string,string>::const_iterator i=sm.begin(); i!=sm.end(); ++i )
+ {
+ cout << "('" << i->first << "', '" << i->second << "')";
+ if( --sm.end() != i )
+ cout << ", ";
+ }
+ cout << "]" << endl;
+ }
+
+
int
main(int argc, char** argv)
{
- list<ConfigInfo> c = Snapper::getConfigs();
-
Snapper* sh = NULL;
+ // testing getConfigs
+ list<ConfigInfo> c = Snapper::getConfigs();
cout << c.size() << endl;
for (list<ConfigInfo>::const_iterator it = c.begin(); it != c.end(); ++it)
cout << it->config_name << " " << it->subvolume << endl;
@@ -34,10 +49,13 @@ main(int argc, char** argv)
if( sh )
{
+ // testing getIgnorePatterns
vector<string> pl = sh->getIgnorePatterns();
cout << pl.size() << endl;
for (vector<string>::const_iterator s = pl.begin(); s!=pl.end(); ++s)
cout << *s << endl;
+
+ // testing iterators over container
Snapshots& snap = sh->getSnapshots();
for (Snapshots::const_iterator s = snap.begin(); s!=snap.end(); ++s)
print_snap_info( s, snap.end() );
@@ -49,23 +67,84 @@ main(int argc, char** argv)
print_snap_info( s, snap.end() );
++s;
}
+
+ // testing find functions
s = snap.find(3);
print_snap_info( s, snap.end() );
s = snap.getSnapshotCurrent();
print_snap_info( s, snap.end() );
- s = snap.find(8);
+ s = snap.find(11);
print_snap_info( s, snap.end() );
Snapshots::iterator j = snap.findPre(s);
print_snap_info( j, snap.end() );
- s = snap.find(6);
+ s = snap.find(10);
print_snap_info( s, snap.end() );
+
+ // testing handling description
j = snap.findPost(s);
print_snap_info( j, snap.end() );
string desc = j->getDescription();
desc += " 1";
j->setDescription(desc);
j = snap.findPost(s);
print_snap_info( j, snap.end() );
+ desc.erase( desc.size()-2 );
+ j->setDescription(desc);
+
+ // testing handling userdata
+ j = snap.findPost(s);
+ print_snap_info( j, snap.end() );
+ map<string,string> sm=j->getUserdata();
+ print_smap_info( sm );
+ sm["key1"] = "value1";
+ sm["key2"] = "value2";
+ sm["key3"] = "value3";
+ j->setUserdata( sm );
+ map<string,string> sn=j->getUserdata();
+ print_smap_info( sn );
+ sn.clear();
+ j->setUserdata( sn );
+ print_smap_info( j->getUserdata() );
+
+ // testing compare functionality
+ j=snap.find(11);
+ s=snap.findPre(j);
+ Comparison cmp(sh,s,j);
+ {
+ Snapshots::const_iterator j1 = cmp.getSnapshot1();
+ Snapshots::const_iterator j2 = cmp.getSnapshot2();
+ print_snap_info( j1, snap.end() );
+ print_snap_info( j2, snap.end() );
+ const Files& flist = cmp.getFiles();
+ cout << flist.size() << endl;
+ for( Files::const_iterator f=flist.begin(); f!=flist.end(); ++f )
+ {
+ cout << f->getAbsolutePath(LOC_SYSTEM) << " "
+ << f->getAbsolutePath(LOC_PRE) << " "
+ << f->getAbsolutePath(LOC_POST) << endl;
+ vector<string> const& sv = f->getDiff("-u");
+ for( vector<string>::const_iterator s=sv.begin(); s!=sv.end(); ++s )
+ cout << *s << endl;
+ }
+ }
+
+ // testing set/getUndo
+ {
+ Files& flist = cmp.getFiles();
+ Files::iterator fi=flist.begin();
+ if( fi!=flist.end() )
+ cout << boolalpha << fi->getUndo() << endl;
+ fi->setUndo(true);
+ cout << boolalpha << fi->getUndo() << endl;
+ fi->setUndo(false);
+ cout << boolalpha << fi->getUndo() << endl;
+ fi->setUndo(true);
+ cout << boolalpha << fi->getUndo() << endl;
+
+ // testing doUndo
+ if( fi!=flist.end() )
+ cout << boolalpha << fi->doUndo() << endl;
+ }
delete sh;
}

0 comments on commit 6e20d88

Please sign in to comment.