Syntax cleanup 1: strip leo markup.
This commit is contained in:
parent
f148047acd
commit
217e3919e4
6 changed files with 32 additions and 1293 deletions
|
|
@ -9,6 +9,10 @@
|
|||
to differenciating between the exact form of the above routines.
|
||||
- Properly catch and propagate errors.
|
||||
- Add crude support for fetching options from command line to xmp.py.
|
||||
* Syntax cleanup:
|
||||
- Strip leo markup. I'm not using leo and I find that markup somewhat
|
||||
obtrusive. OTOH it seems to be auto-generated so my editions will
|
||||
break it anyway.
|
||||
|
||||
2006-05-23 Csaba Henk <csaba.henk@creo.hu>
|
||||
* Fix statfs index mismatch in xmp.py.
|
||||
|
|
|
|||
6
README
6
README
|
|
@ -1,7 +1,3 @@
|
|||
#@+leo-ver=4
|
||||
#@+node:@file README
|
||||
#@@language
|
||||
|
||||
Refer to the INSTALL file for build/install instructions
|
||||
|
||||
General Information
|
||||
|
|
@ -88,5 +84,3 @@ License, Version 2. Future versions, if any, will be available at [3].
|
|||
[1] http://www.python.org
|
||||
[2] http://sourceforge.net/projects/avf/
|
||||
[3] http://unpythonic.dhs.org/~jepler/fuse/
|
||||
#@-node:@file README
|
||||
#@-leo
|
||||
|
|
|
|||
|
|
@ -1,6 +1,3 @@
|
|||
//@+leo-ver=4
|
||||
//@+node:@file _fusemodule.c
|
||||
//@@language c
|
||||
/*
|
||||
Copyright (C) 2001 Jeff Epler <jepler@unpythonic.dhs.org>
|
||||
|
||||
|
|
@ -22,16 +19,13 @@
|
|||
#endif
|
||||
|
||||
#define FUSE_USE_VERSION 26
|
||||
//@+others
|
||||
//@+node:includes
|
||||
|
||||
#include <sys/types.h>
|
||||
#include <sys/param.h>
|
||||
#include <sys/mount.h>
|
||||
#include <time.h>
|
||||
#include <Python.h>
|
||||
#include "fuse.h"
|
||||
//@-node:includes
|
||||
//@+node:globals
|
||||
|
||||
static PyObject *getattr_cb=NULL, *readlink_cb=NULL, *getdir_cb=NULL,
|
||||
*mknod_cb=NULL, *mkdir_cb=NULL, *unlink_cb=NULL, *rmdir_cb=NULL,
|
||||
|
|
@ -45,23 +39,17 @@ static int debuglevel=0;
|
|||
|
||||
static PyObject *Py_FuseError;
|
||||
|
||||
//@-node:globals
|
||||
//@+node:PROLOGUE
|
||||
#define PROLOGUE \
|
||||
int ret = -EINVAL; \
|
||||
if (!v) { PyErr_Print(); goto OUT; } \
|
||||
if(v == Py_None) { ret = 0; goto OUT_DECREF; } \
|
||||
if(PyInt_Check(v)) { ret = PyInt_AsLong(v); goto OUT_DECREF; }
|
||||
|
||||
//@-node:PROLOGUE
|
||||
//@+node:EPILOGUE
|
||||
#define EPILOGUE \
|
||||
OUT_DECREF: \
|
||||
Py_DECREF(v); \
|
||||
OUT: \
|
||||
return ret;
|
||||
//@-node:EPILOGUE
|
||||
//@+node:getattr_func
|
||||
|
||||
/*
|
||||
* Local Variables:
|
||||
|
|
@ -106,9 +94,6 @@ ret = 0;
|
|||
EPILOGUE
|
||||
}
|
||||
|
||||
//@-node:getattr_func
|
||||
//@+node:readlink_func
|
||||
|
||||
static int readlink_func(const char *path, char *link, size_t size)
|
||||
{
|
||||
PyObject *v = PyObject_CallFunction(readlink_cb, "s", path);
|
||||
|
|
@ -123,8 +108,6 @@ static int readlink_func(const char *path, char *link, size_t size)
|
|||
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:readlink_func
|
||||
//@+node:getdir_add_entry
|
||||
|
||||
static int getdir_add_entry(PyObject *w, fuse_dirh_t dh, fuse_dirfil_t df)
|
||||
{
|
||||
|
|
@ -165,8 +148,6 @@ out_decref:
|
|||
out:
|
||||
return ret;
|
||||
}
|
||||
//@-node:getdir_add_entry
|
||||
//@+node:getdir_func
|
||||
|
||||
static int getdir_func(const char *path, fuse_dirh_t dh, fuse_dirfil_t df)
|
||||
{
|
||||
|
|
@ -189,8 +170,6 @@ static int getdir_func(const char *path, fuse_dirh_t dh, fuse_dirfil_t df)
|
|||
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:getdir_func
|
||||
//@+node:mknod_func
|
||||
|
||||
static int mknod_func(const char *path, mode_t m, dev_t d)
|
||||
{
|
||||
|
|
@ -198,8 +177,6 @@ static int mknod_func(const char *path, mode_t m, dev_t d)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:mknod_func
|
||||
//@+node:mkdir_func
|
||||
|
||||
static int mkdir_func(const char *path, mode_t m)
|
||||
{
|
||||
|
|
@ -207,8 +184,6 @@ static int mkdir_func(const char *path, mode_t m)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:mkdir_func
|
||||
//@+node:unlink_func
|
||||
|
||||
static int unlink_func(const char *path)
|
||||
{
|
||||
|
|
@ -216,8 +191,6 @@ static int unlink_func(const char *path)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:unlink_func
|
||||
//@+node:rmdir_func
|
||||
|
||||
static int rmdir_func(const char *path)
|
||||
{
|
||||
|
|
@ -225,8 +198,6 @@ static int rmdir_func(const char *path)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:rmdir_func
|
||||
//@+node:symlink_func
|
||||
|
||||
static int symlink_func(const char *path, const char *path1)
|
||||
{
|
||||
|
|
@ -234,8 +205,6 @@ static int symlink_func(const char *path, const char *path1)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:symlink_func
|
||||
//@+node:rename_func
|
||||
|
||||
static int rename_func(const char *path, const char *path1)
|
||||
{
|
||||
|
|
@ -243,8 +212,6 @@ static int rename_func(const char *path, const char *path1)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:rename_func
|
||||
//@+node:link_func
|
||||
|
||||
static int link_func(const char *path, const char *path1)
|
||||
{
|
||||
|
|
@ -252,8 +219,6 @@ static int link_func(const char *path, const char *path1)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:link_func
|
||||
//@+node:chmod_func
|
||||
|
||||
static int chmod_func(const char *path, mode_t m)
|
||||
{
|
||||
|
|
@ -261,8 +226,6 @@ static int chmod_func(const char *path, mode_t m)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:chmod_func
|
||||
//@+node:chown_func
|
||||
|
||||
static int chown_func(const char *path, uid_t u, gid_t g)
|
||||
{
|
||||
|
|
@ -270,8 +233,6 @@ static int chown_func(const char *path, uid_t u, gid_t g)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:chown_func
|
||||
//@+node:truncate_func
|
||||
|
||||
static int truncate_func(const char *path, off_t o)
|
||||
{
|
||||
|
|
@ -279,8 +240,6 @@ static int truncate_func(const char *path, off_t o)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:truncate_func
|
||||
//@+node:utime_func
|
||||
|
||||
static int utime_func(const char *path, struct utimbuf *u) {
|
||||
int actime = u ? u->actime : time(NULL);
|
||||
|
|
@ -290,8 +249,6 @@ static int utime_func(const char *path, struct utimbuf *u) {
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:utime_func
|
||||
//@+node:read_func
|
||||
|
||||
#if FUSE_VERSION >= 22
|
||||
static int read_func(const char *path, char *buf, size_t s, off_t off,
|
||||
|
|
@ -309,8 +266,6 @@ static int read_func(const char *path, char *buf, size_t s, off_t off)
|
|||
}
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:read_func
|
||||
//@+node:write_func
|
||||
|
||||
#if FUSE_VERSION >= 22
|
||||
static int write_func(const char *path, const char *buf, size_t t, off_t off,
|
||||
|
|
@ -323,8 +278,6 @@ static int write_func(const char *path, const char *buf, size_t t, off_t off)
|
|||
PROLOGUE
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:write_func
|
||||
//@+node:open_func
|
||||
|
||||
#if FUSE_VERSION >= 22
|
||||
static int open_func(const char *path, struct fuse_file_info *fi)
|
||||
|
|
@ -339,8 +292,7 @@ static int open_func(const char *path, int mode)
|
|||
printf("open_func: path=%s\n", path);
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:open_func
|
||||
//@+node:release_func
|
||||
|
||||
#if FUSE_VERSION >= 22
|
||||
static int release_func(const char *path, struct fuse_file_info *fi)
|
||||
{
|
||||
|
|
@ -354,8 +306,7 @@ static int release_func(const char *path, int flags)
|
|||
//printf("release_func: path=%s flags=%d\n", path, flags);
|
||||
EPILOGUE
|
||||
}
|
||||
//@-node:release_func
|
||||
//@+node:statfs_func
|
||||
|
||||
#if FUSE_VERSION >= 25
|
||||
static int statfs_func( const char *dummy, struct statvfs *fst)
|
||||
#else
|
||||
|
|
@ -412,8 +363,6 @@ EPILOGUE
|
|||
|
||||
}
|
||||
|
||||
//@-node:statfs_func
|
||||
//@+node:fsync_func
|
||||
#if FUSE_VERSION >= 22
|
||||
static int fsync_func(const char *path, int datasync, struct fuse_file_info *fi)
|
||||
{
|
||||
|
|
@ -427,9 +376,6 @@ static int fsync_func(const char *path, int isfsyncfile)
|
|||
EPILOGUE
|
||||
}
|
||||
|
||||
//@-node:fsync_func
|
||||
//@+node:process_cmd
|
||||
|
||||
static void process_cmd(struct fuse *f, struct fuse_cmd *cmd, void *data)
|
||||
{
|
||||
PyInterpreterState *interp = (PyInterpreterState *) data;
|
||||
|
|
@ -448,8 +394,6 @@ static void process_cmd(struct fuse *f, struct fuse_cmd *cmd, void *data)
|
|||
PyThreadState_Delete(state);
|
||||
PyEval_ReleaseLock();
|
||||
}
|
||||
//@-node:process_cmd
|
||||
//@+node:pyfuse_loop_mt
|
||||
|
||||
static int pyfuse_loop_mt(struct fuse *f)
|
||||
{
|
||||
|
|
@ -470,8 +414,6 @@ static int pyfuse_loop_mt(struct fuse *f)
|
|||
|
||||
return(err);
|
||||
}
|
||||
//@-node:pyfuse_loop_mt
|
||||
//@+node:Fuse_main
|
||||
|
||||
static struct fuse *fuse=NULL;
|
||||
|
||||
|
|
@ -604,13 +546,7 @@ Fuse_main(PyObject *self, PyObject *args, PyObject *kw)
|
|||
Py_INCREF(Py_None);
|
||||
return Py_None;
|
||||
}
|
||||
//@-node:Fuse_main
|
||||
//@+node:DL_EXPORT
|
||||
//@+at
|
||||
//@nonl
|
||||
// List of functions defined in the module
|
||||
//@-at
|
||||
//@@c
|
||||
|
||||
static char FuseInvalidate__doc__[] =
|
||||
"Tell Fuse kernel module to explicitly invalidate a cached inode's contents\n";
|
||||
|
||||
|
|
@ -690,8 +626,3 @@ init_fuse(void)
|
|||
PyDict_SetItemString(d, "error", Py_FuseError);
|
||||
// PyDict_SetItemString(d, "DEBUG", PyInt_FromLong(FUSE_DEBUG));
|
||||
}
|
||||
//@-node:DL_EXPORT
|
||||
//@-others
|
||||
|
||||
//@-node:@file _fusemodule.c
|
||||
//@-leo
|
||||
|
|
|
|||
30
fuse.py
30
fuse.py
|
|
@ -1,5 +1,3 @@
|
|||
#@+leo-ver=4
|
||||
#@+node:@file fuse.py
|
||||
#
|
||||
# Copyright (C) 2001 Jeff Epler <jepler@unpythonic.dhs.org>
|
||||
#
|
||||
|
|
@ -8,9 +6,6 @@
|
|||
#
|
||||
|
||||
|
||||
#@@language python
|
||||
#@+others
|
||||
#@+node:imports
|
||||
# suppress version mismatch warnings
|
||||
try:
|
||||
import warnings
|
||||
|
|
@ -26,15 +21,11 @@ from string import join
|
|||
import sys
|
||||
from errno import *
|
||||
|
||||
#@-node:imports
|
||||
#@+node:class ErrnoWrapper
|
||||
class ErrnoWrapper:
|
||||
#@ @+others
|
||||
#@+node:__init__
|
||||
|
||||
def __init__(self, func):
|
||||
self.func = func
|
||||
#@-node:__init__
|
||||
#@+node:__call__
|
||||
|
||||
def __call__(self, *args, **kw):
|
||||
try:
|
||||
return apply(self.func, args, kw)
|
||||
|
|
@ -42,14 +33,9 @@ class ErrnoWrapper:
|
|||
# Sometimes this is an int, sometimes an instance...
|
||||
if hasattr(detail, "errno"): detail = detail.errno
|
||||
return -detail
|
||||
#@-node:__call__
|
||||
#@-others
|
||||
#@-node:class ErrnoWrapper
|
||||
#@+node:class Fuse
|
||||
|
||||
class Fuse:
|
||||
|
||||
#@ @+others
|
||||
#@+node:attribs
|
||||
_attrs = ['getattr', 'readlink', 'getdir', 'mknod', 'mkdir',
|
||||
'unlink', 'rmdir', 'symlink', 'rename', 'link', 'chmod',
|
||||
'chown', 'truncate', 'utime', 'open', 'read', 'write', 'release',
|
||||
|
|
@ -58,8 +44,6 @@ class Fuse:
|
|||
flags = 0
|
||||
multithreaded = 0
|
||||
|
||||
#@-node:attribs
|
||||
#@+node:__init__
|
||||
def __init__(self, *args, **kw):
|
||||
|
||||
# default attributes
|
||||
|
|
@ -111,8 +95,6 @@ class Fuse:
|
|||
def Invalidate(self, path):
|
||||
return FuseInvalidate(self, path)
|
||||
|
||||
#@-node:__init__
|
||||
#@+node:main
|
||||
def main(self):
|
||||
|
||||
d = {'mountpoint': self.mountpoint}
|
||||
|
|
@ -159,9 +141,3 @@ class Fuse:
|
|||
apply(main, (), d)
|
||||
except FuseError:
|
||||
if not nomount: raise
|
||||
#@-node:main
|
||||
#@-others
|
||||
#@-node:class Fuse
|
||||
#@-others
|
||||
#@-node:@file fuse.py
|
||||
#@-leo
|
||||
|
|
|
|||
88
xmp.py
88
xmp.py
|
|
@ -1,17 +1,11 @@
|
|||
#!/usr/bin/env python
|
||||
#@+leo-ver=4
|
||||
#@+node:@file xmp.py
|
||||
#@@first
|
||||
#
|
||||
|
||||
# Copyright (C) 2001 Jeff Epler <jepler@unpythonic.dhs.org>
|
||||
#
|
||||
# This program can be distributed under the terms of the GNU LGPL.
|
||||
# See the file COPYING.
|
||||
#
|
||||
|
||||
#@+others
|
||||
#@+node:imports
|
||||
|
||||
import os
|
||||
from errno import *
|
||||
from stat import *
|
||||
|
|
@ -29,12 +23,8 @@ except ImportError:
|
|||
|
||||
|
||||
import thread
|
||||
#@-node:imports
|
||||
#@+node:class Xmp
|
||||
class Xmp(Fuse):
|
||||
|
||||
#@ @+others
|
||||
#@+node:__init__
|
||||
def __init__(self, *args, **kw):
|
||||
|
||||
Fuse.__init__(self, *args, **kw)
|
||||
|
|
@ -47,8 +37,7 @@ class Xmp(Fuse):
|
|||
# do stuff to set up your filesystem here, if you want
|
||||
#thread.start_new_thread(self.mythread, ())
|
||||
pass
|
||||
#@-node:__init__
|
||||
#@+node:mythread
|
||||
|
||||
def mythread(self):
|
||||
|
||||
"""
|
||||
|
|
@ -60,102 +49,77 @@ class Xmp(Fuse):
|
|||
# time.sleep(120)
|
||||
# print "mythread: ticking"
|
||||
|
||||
#@-node:mythread
|
||||
#@+node:attribs
|
||||
flags = 1
|
||||
|
||||
#@-node:attribs
|
||||
#@+node:getattr
|
||||
def getattr(self, path):
|
||||
return os.lstat(path)
|
||||
#@-node:getattr
|
||||
#@+node:readlink
|
||||
|
||||
def readlink(self, path):
|
||||
return os.readlink(path)
|
||||
#@-node:readlink
|
||||
#@+node:getdir
|
||||
|
||||
def getdir(self, path):
|
||||
return map(lambda x: (x,0), os.listdir(path))
|
||||
#@-node:getdir
|
||||
#@+node:unlink
|
||||
|
||||
def unlink(self, path):
|
||||
return os.unlink(path)
|
||||
#@-node:unlink
|
||||
#@+node:rmdir
|
||||
|
||||
def rmdir(self, path):
|
||||
return os.rmdir(path)
|
||||
#@-node:rmdir
|
||||
#@+node:symlink
|
||||
|
||||
def symlink(self, path, path1):
|
||||
return os.symlink(path, path1)
|
||||
#@-node:symlink
|
||||
#@+node:rename
|
||||
|
||||
def rename(self, path, path1):
|
||||
return os.rename(path, path1)
|
||||
#@-node:rename
|
||||
#@+node:link
|
||||
|
||||
def link(self, path, path1):
|
||||
return os.link(path, path1)
|
||||
#@-node:link
|
||||
#@+node:chmod
|
||||
|
||||
def chmod(self, path, mode):
|
||||
return os.chmod(path, mode)
|
||||
#@-node:chmod
|
||||
#@+node:chown
|
||||
|
||||
def chown(self, path, user, group):
|
||||
return os.chown(path, user, group)
|
||||
#@-node:chown
|
||||
#@+node:truncate
|
||||
|
||||
def truncate(self, path, size):
|
||||
f = open(path, "w+")
|
||||
return f.truncate(size)
|
||||
#@-node:truncate
|
||||
#@+node:mknod
|
||||
|
||||
def mknod(self, path, mode, dev):
|
||||
""" Python has no os.mknod, so we can only do some things """
|
||||
if S_ISREG(mode):
|
||||
open(path, "w")
|
||||
else:
|
||||
return -EINVAL
|
||||
#@-node:mknod
|
||||
#@+node:mkdir
|
||||
|
||||
def mkdir(self, path, mode):
|
||||
return os.mkdir(path, mode)
|
||||
#@-node:mkdir
|
||||
#@+node:utime
|
||||
|
||||
def utime(self, path, times):
|
||||
return os.utime(path, times)
|
||||
#@-node:utime
|
||||
#@+node:open
|
||||
|
||||
def open(self, path, flags):
|
||||
#print "xmp.py:Xmp:open: %s" % path
|
||||
os.close(os.open(path, flags))
|
||||
return 0
|
||||
|
||||
#@-node:open
|
||||
#@+node:read
|
||||
|
||||
def read(self, path, length, offset):
|
||||
#print "xmp.py:Xmp:read: %s" % path
|
||||
f = open(path, "r")
|
||||
f.seek(offset)
|
||||
return f.read(length)
|
||||
|
||||
#@-node:read
|
||||
#@+node:write
|
||||
|
||||
def write(self, path, buf, off):
|
||||
#print "xmp.py:Xmp:write: %s" % path
|
||||
f = open(path, "r+")
|
||||
f.seek(off)
|
||||
f.write(buf)
|
||||
return len(buf)
|
||||
|
||||
#@-node:write
|
||||
#@+node:release
|
||||
|
||||
def release(self, path, flags):
|
||||
print "xmp.py:Xmp:release: %s %s" % (path, flags)
|
||||
return 0
|
||||
#@-node:release
|
||||
#@+node:statfs
|
||||
|
||||
def statfs(self):
|
||||
"""
|
||||
Should return a tuple with the following 6 elements:
|
||||
|
|
@ -176,17 +140,11 @@ class Xmp(Fuse):
|
|||
files_free = 60000
|
||||
namelen = 80
|
||||
return (blocks_size, blocks, blocks - blocks_free, blocks_free, files, files_free, namelen)
|
||||
#@-node:statfs
|
||||
#@+node:fsync
|
||||
|
||||
def fsync(self, path, isfsyncfile):
|
||||
print "xmp.py:Xmp:fsync: path=%s, isfsyncfile=%s" % (path, isfsyncfile)
|
||||
return 0
|
||||
|
||||
#@-node:fsync
|
||||
#@-others
|
||||
#@-node:class Xmp
|
||||
#@+node:mainline
|
||||
|
||||
if __name__ == '__main__':
|
||||
|
||||
server = Xmp()
|
||||
|
|
@ -199,7 +157,3 @@ if __name__ == '__main__':
|
|||
server.fuse_opt_list = server.optlist
|
||||
server.fuse_opts = server.optdict
|
||||
server.main()
|
||||
#@-node:mainline
|
||||
#@-others
|
||||
#@-node:@file xmp.py
|
||||
#@-leo
|
||||
|
|
|
|||
Loading…
Reference in a new issue