/[fuse_dbi]/fuse/trunk/python/xmp.py
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /fuse/trunk/python/xmp.py

Parent Directory Parent Directory | Revision Log Revision Log


Revision 5 - (show annotations)
Wed Aug 4 11:40:49 2004 UTC (19 years, 8 months ago) by dpavlin
File MIME type: text/x-python
File size: 4857 byte(s)
copy CVS to trunk

1 #!/usr/bin/env python
2 #@+leo-ver=4
3 #@+node:@file xmp.py
4 #@@first
5 #
6 # Copyright (C) 2001 Jeff Epler <jepler@unpythonic.dhs.org>
7 #
8 # This program can be distributed under the terms of the GNU GPL.
9 # See the file COPYING.
10 #
11
12 #@+others
13 #@+node:imports
14
15 from fuse import Fuse
16 import os
17 from errno import *
18 from stat import *
19
20 import thread
21 #@-node:imports
22 #@+node:class Xmp
23 class Xmp(Fuse):
24
25 #@ @+others
26 #@+node:__init__
27 def __init__(self, *args, **kw):
28
29 Fuse.__init__(self, *args, **kw)
30
31 if 0:
32 print "xmp.py:Xmp:mountpoint: %s" % repr(self.mountpoint)
33 print "xmp.py:Xmp:unnamed mount options: %s" % self.optlist
34 print "xmp.py:Xmp:named mount options: %s" % self.optdict
35
36 # do stuff to set up your filesystem here, if you want
37 #thread.start_new_thread(self.mythread, ())
38 pass
39 #@-node:__init__
40 #@+node:mythread
41 def mythread(self):
42
43 """
44 The beauty of the FUSE python implementation is that with the python interp
45 running in foreground, you can have threads
46 """
47 print "mythread: started"
48 #while 1:
49 # time.sleep(120)
50 # print "mythread: ticking"
51
52 #@-node:mythread
53 #@+node:attribs
54 flags = 1
55
56 #@-node:attribs
57 #@+node:getattr
58 def getattr(self, path):
59 return os.lstat(path)
60 #@-node:getattr
61 #@+node:readlink
62 def readlink(self, path):
63 return os.readlink(path)
64 #@-node:readlink
65 #@+node:getdir
66 def getdir(self, path):
67 return map(lambda x: (x,0), os.listdir(path))
68 #@-node:getdir
69 #@+node:unlink
70 def unlink(self, path):
71 return os.unlink(path)
72 #@-node:unlink
73 #@+node:rmdir
74 def rmdir(self, path):
75 return os.rmdir(path)
76 #@-node:rmdir
77 #@+node:symlink
78 def symlink(self, path, path1):
79 return os.symlink(path, path1)
80 #@-node:symlink
81 #@+node:rename
82 def rename(self, path, path1):
83 return os.rename(path, path1)
84 #@-node:rename
85 #@+node:link
86 def link(self, path, path1):
87 return os.link(path, path1)
88 #@-node:link
89 #@+node:chmod
90 def chmod(self, path, mode):
91 return os.chmod(path, mode)
92 #@-node:chmod
93 #@+node:chown
94 def chown(self, path, user, group):
95 return os.chown(path, user, group)
96 #@-node:chown
97 #@+node:truncate
98 def truncate(self, path, size):
99 f = open(path, "w+")
100 return f.truncate(size)
101 #@-node:truncate
102 #@+node:mknod
103 def mknod(self, path, mode, dev):
104 """ Python has no os.mknod, so we can only do some things """
105 if S_ISREG(mode):
106 open(path, "w")
107 else:
108 return -EINVAL
109 #@-node:mknod
110 #@+node:mkdir
111 def mkdir(self, path, mode):
112 return os.mkdir(path, mode)
113 #@-node:mkdir
114 #@+node:utime
115 def utime(self, path, times):
116 return os.utime(path, times)
117 #@-node:utime
118 #@+node:open
119 def open(self, path, flags):
120 #print "xmp.py:Xmp:open: %s" % path
121 os.close(os.open(path, flags))
122 return 0
123
124 #@-node:open
125 #@+node:read
126 def read(self, path, len, offset):
127 #print "xmp.py:Xmp:read: %s" % path
128 f = open(path, "r")
129 f.seek(offset)
130 return f.read(len)
131
132 #@-node:read
133 #@+node:write
134 def write(self, path, buf, off):
135 #print "xmp.py:Xmp:write: %s" % path
136 f = open(path, "r+")
137 f.seek(off)
138 f.write(buf)
139 return len(buf)
140
141 #@-node:write
142 #@+node:release
143 def release(self, path, flags):
144 print "xmp.py:Xmp:release: %s %s" % (path, flags)
145 return 0
146 #@-node:release
147 #@+node:statfs
148 def statfs(self):
149 """
150 Should return a tuple with the following 6 elements:
151 - blocksize - size of file blocks, in bytes
152 - totalblocks - total number of blocks in the filesystem
153 - freeblocks - number of free blocks
154 - totalfiles - total number of file inodes
155 - freefiles - nunber of free file inodes
156
157 Feel free to set any of the above values to 0, which tells
158 the kernel that the info is not available.
159 """
160 print "xmp.py:Xmp:statfs: returning fictitious values"
161 blocks_size = 1024
162 blocks = 100000
163 blocks_free = 25000
164 files = 100000
165 files_free = 60000
166 namelen = 80
167 return (blocks_size, blocks, blocks_free, files, files_free, namelen)
168 #@-node:statfs
169 #@+node:fsync
170 def fsync(self, path, isfsyncfile):
171 print "xmp.py:Xmp:fsync: path=%s, isfsyncfile=%s" % (path, isfsyncfile)
172 return 0
173
174 #@-node:fsync
175 #@-others
176 #@-node:class Xmp
177 #@+node:mainline
178
179 if __name__ == '__main__':
180
181 server = Xmp()
182 server.flags = 0
183 server.multithreaded = 1;
184 server.main()
185 #@-node:mainline
186 #@-others
187 #@-node:@file xmp.py
188 #@-leo

Properties

Name Value
svn:executable

  ViewVC Help
Powered by ViewVC 1.1.26