Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

extended xbmcvfs module with stat #1062

Closed
wants to merge 1 commit into from

4 participants

@tamland
Collaborator

Added stat method to xbmcvfs. Just returns a big tuple. I guess a proper named tuple would be better, but I can't figure out how to do that without a boilerplate class. Users can call posix.stat_result tho..

@tamland
Collaborator

You mean I should cast them all to long long? Any suggestion on how to do it otherwise, because the type seems to be implementation dependent, so I'm not sure what to do about that. Manually write all the cases? (cant even figure out what they are btw)

@nuka1195

A copytree(old, new) would also be useful or maybe just enhance the copy() to support that.

@jmarshallnz
Owner

Please get rid of the merge commits by rebasing on master.

@jimfcarroll
Collaborator

The code looks OK to me.

@tamland tamland closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Aug 10, 2012
  1. @tamland
This page is out of date. Refresh to see the latest.
Showing with 40 additions and 0 deletions.
  1. +40 −0 xbmc/interfaces/python/xbmcmodule/xbmcvfsmodule.cpp
View
40 xbmc/interfaces/python/xbmcmodule/xbmcvfsmodule.cpp
@@ -390,6 +390,45 @@ extern "C" {
}
return Py_BuildValue((char*)"O,O", folderList, fileList);
}
+
+ PyDoc_STRVAR(stat__doc__,
+ "stat(path) -- get file or file system status.\n"
+ "\n"
+ "path : file or folder\n"
+ "\n"
+ "example:\n"
+ " - mode,ino,dev,nlink,uid,gid,size,atime,mtime,ctime = xbmcvfs.stat(path)\n");
+ // get file status, mimics Pythons os.stat()
+ PyObject* vfs_stat(File *self, PyObject *args, PyObject *kwds)
+ {
+ PyObject *f_line;
+ if (!PyArg_ParseTuple(
+ args,
+ (char*)"O",
+ &f_line))
+ {
+ return NULL;
+ }
+ CStdString strSource;
+ if (!PyXBMCGetUnicodeString(strSource, f_line, 1))
+ return NULL;
+
+ int result;
+ struct __stat64 st;
+
+ CPyThreadState pyState;
+ result = self->pFile->Stat(strSource, &st);
+ pyState.Restore();
+
+ if (result != 0)
+ {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+
+ return Py_BuildValue((char*)"(LLLLLLLLLL)", st.st_mode, st.st_ino, st.st_dev, st.st_nlink,
+ st.st_uid, st.st_gid, st.st_size, st.st_atime, st.st_mtime, st.st_ctime);
+ }
// define c functions to be used in python here
PyMethodDef xbmcvfsMethods[] = {
@@ -401,6 +440,7 @@ extern "C" {
{(char*)"rmdir", (PyCFunction)vfs_rmdir, METH_VARARGS, rmdir__doc__},
{(char*)"exists", (PyCFunction)vfs_exists, METH_VARARGS, exists__doc__},
{(char*)"listdir", (PyCFunction)vfs_listdir, METH_VARARGS, listdir__doc__},
+ {(char*)"stat", (PyCFunction)vfs_stat, METH_VARARGS, stat__doc__},
{NULL, NULL, 0, NULL}
};
PyDoc_STRVAR(read__doc__,
Something went wrong with that request. Please try again.