summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorFrederic Back <fredericback@gmail.com>2006-09-25 10:41:59 +0000
committerFrederic Back <fredericback@gmail.com>2006-09-25 10:41:59 +0000
commita6d9c932ce4cb91223e46c532489c0f514b09d4f (patch)
treeb7073b23f5dfdd744e122f7c59f2be212f54a94c
parentea97aefad7f3dd527ef910aedcb73f4b5b7f48dc (diff)
* sync extension back from trunk
git-svn-id: file:///home/lennart/svn/public/fring/branches/c_walker@26 d0d2c35f-0a1e-0410-abeb-dabff30a67ee
-rw-r--r--src/extension/extensiontest.py4
-rw-r--r--src/extension/fringtools.cpp36
2 files changed, 20 insertions, 20 deletions
diff --git a/src/extension/extensiontest.py b/src/extension/extensiontest.py
index e95c7a3..cd4b6aa 100644
--- a/src/extension/extensiontest.py
+++ b/src/extension/extensiontest.py
@@ -13,6 +13,9 @@ else: tree_path = os.path.expanduser("~")
def read( t, tab=0 ):
fn, data, size = t
print " "*tab,fn,size
+
+ if tab>0: return
+
if not data: return
for e in data:
read(e,tab+1)
@@ -20,4 +23,5 @@ def read( t, tab=0 ):
print 'getting "%s":'%tree_path
i = fringtools.build_tree(tree_path, True)
print "done."
+
read(i)
diff --git a/src/extension/fringtools.cpp b/src/extension/fringtools.cpp
index 577a486..9205816 100644
--- a/src/extension/fringtools.cpp
+++ b/src/extension/fringtools.cpp
@@ -16,9 +16,11 @@ def _build_tree(self,path):
try: p = os.path.join(path, fn)
except: continue
s = os.lstat(p)
- if stat.S_ISDIR(s.st_mode): l.append( (fn, self._build_tree(p)) )
- elif stat.S_ISREG(s.st_mode): l.append( (fn, s.st_size) )
- return sum_list(l, os.path.split(path)[-1])
+ if stat.S_ISDIR(s.st_mode):
+ l.append( (fn, self._build_tree(p), s.st_size) )
+ elif stat.S_ISREG(s.st_mode):
+ l.append( (fn, None, s.st_size) )
+ return sum_list(os.path.split(path)[-1], l, 0)
==============================================================================
@@ -28,14 +30,12 @@ Instead of using SumList, the new build_tree will use a tuple
/// recursive function to build a list system with directory information
PyObject* build_tree( std::string path, const bool& skipHidden) {
-
PyObject* l = PyList_New(0);
-
DIR* d = opendir(path.c_str());
- struct dirent *e;
-
- int total = 0;
+ if(d == 0) Py_RETURN_NONE;
+ unsigned long total = 0;
+ struct dirent *e;
while((e = readdir(d)) != NULL) {
std::string fn = e->d_name;
@@ -46,20 +46,22 @@ PyObject* build_tree( std::string path, const bool& skipHidden) {
struct stat s;
lstat(fn.c_str(), &s);
+ if (s.st_size < 0)
+ std::cout << "alert2 " << path << ", " << total << std::endl << std::flush;
+
if(S_ISDIR(s.st_mode)) {
PyObject* sub = build_tree(fn,skipHidden);
+ PyTuple_SetItem(sub,0,PyString_FromString(e->d_name));
PyList_Append(l, sub );
- total += PyInt_AsLong( PyTuple_GET_ITEM(sub,2) );
+ total += PyLong_AsUnsignedLong( PyTuple_GET_ITEM(sub,2) );
} else if (S_ISREG(s.st_mode)) {
- PyList_Append(l, Py_BuildValue("(sOi)",fn.c_str(),Py_None,s.st_size) );
+ PyList_Append(l, Py_BuildValue("(sOk)",e->d_name,Py_None,s.st_size) );
total += s.st_size;
}
-
}
closedir(d);
-
- return Py_BuildValue("(sOi)", path.c_str(), l, total );
+ return Py_BuildValue("(sOk)", path.c_str(), l, total );
}
/// initial function call.
@@ -67,13 +69,7 @@ static PyObject* fringtools_build_tree(PyObject *self, PyObject *args) {
const char *path;
int skip_hidden = 1;
if (!PyArg_ParseTuple(args, "si", &path, &skip_hidden)) return NULL;
-
- PyObject* o;
- //Py_BEGIN_ALLOW_THREADS
- o = build_tree(std::string(path),(skip_hidden==1));
- //Py_END_ALLOW_THREADS
-
- return o;
+ return build_tree(std::string(path),(skip_hidden==1));
}
//==============================================================================