Skip to content

Commit 8c95e3b

Browse files
committed
Merge remote-tracking branch 'upstream/master'
Now using python3 and make IOCTL works again
2 parents fd8715b + 42cf9fb commit 8c95e3b

15 files changed

Lines changed: 205 additions & 125 deletions

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
build
2+
dist
3+
fuse_python.egg-info

.travis.yml

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
language: python
2+
3+
python:
4+
- 2.7
5+
- 3.5
6+
- 3.6
7+
8+
addons:
9+
apt:
10+
packages:
11+
- libfuse-dev
12+
13+
install:
14+
- python setup.py build
15+
16+
script:
17+
- sudo modprobe fuse
18+
- mkdir /tmp/foo
19+
- python example/hello.py /tmp/foo

FAQ

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
FUSE-Python_ bindings FAQ
33
=========================
44

5-
.. _FUSE-Python: http://fuse.sourceforge.net/wiki/index.php/FusePython
5+
.. _FUSE-Python: https://github.com/libfuse/python-fuse
66

77
:Author: Csaba Henk
88

README.1st

Lines changed: 0 additions & 22 deletions
This file was deleted.

README.md

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
# python-fuse #
2+
3+
[![Build Status](https://travis-ci.org/libfuse/python-fuse.svg?branch=master)](https://travis-ci.org/libfuse/python-fuse)
4+
5+
This is a Python interface to libfuse
6+
(https://github.com/libfuse/libfuse).
7+
8+
* The API is described in ``README.new_fusepy_api``. It's an
9+
informative description, not a reference. Apart from that, see the
10+
examples and the actual code.
11+
12+
* Project home page is https://github.com/libfuse/python-fuse

README.new_fusepy_api

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
FUSE-Python_ bindings new API
33
=============================
44

5-
.. _FUSE-Python: http://fuse.sourceforge.net/wiki/index.php/FusePython
5+
.. _FUSE-Python: https://github.com/libfuse/python-fuse
66

77
:Author: Csaba Henk
88

example/_find_fuse_parts.py

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,21 +2,23 @@
22
from os.path import realpath, dirname, join
33
from traceback import format_exception
44

5+
PYTHON_MAJOR_MINOR = "%s.%s" % (sys.version_info[0], sys.version_info[1])
6+
57
ddd = realpath(join(dirname(sys.argv[0]), '..'))
68

79
for d in [ddd, '.']:
8-
for p in glob.glob(join(d, 'build', 'lib.*')):
10+
for p in glob.glob(join(d, 'build', 'lib.*%s' % PYTHON_MAJOR_MINOR)):
911
sys.path.insert(0, p)
1012

1113
try:
1214
import fuse
1315
except ImportError:
14-
raise RuntimeError, """
16+
raise RuntimeError("""
1517
1618
! Got exception:
1719
""" + "".join([ "> " + x for x in format_exception(*sys.exc_info()) ]) + """
1820
! Have you ran `python setup.py build'?
1921
!
2022
! We've done our best to find the necessary components of the FUSE bindings
2123
! even if it's not installed, we've got no clue what went wrong for you...
22-
"""
24+
""")

example/fioc.py

Lines changed: 15 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,7 @@
1616

1717

1818
if not hasattr(fuse, '__version__'):
19-
raise RuntimeError, \
20-
"your fuse-py doesn't know of fuse.__version__, probably it's too old."
19+
raise RuntimeError("your fuse-py doesn't know of fuse.__version__, probably it's too old.")
2120

2221
fuse.fuse_python_api = (0, 2)
2322

@@ -43,32 +42,32 @@ class IOCTL:
4342
_IOC_WRITE = 1
4443
_IOC_READ = 2
4544

46-
@classmethod
45+
@classmethod
4746
def _IOC(cls, d,t,nr,size):
48-
return (((d) << cls._IOC_DIRSHIFT) |
47+
return (((d) << cls._IOC_DIRSHIFT) |
4948
((t) << cls._IOC_TYPESHIFT) | \
5049
((nr) << cls._IOC_NRSHIFT) | \
5150
((size) << cls._IOC_SIZESHIFT))
5251

53-
@classmethod
52+
@classmethod
5453
def _IO(cls, t,nr):
5554
return cls._IOC(cls._IOC_NONE, t, nr, 0)
5655

57-
@classmethod
56+
@classmethod
5857
def _IOR(cls, t,nr,size):
5958
return cls._IOC(cls._IOC_READ, t, nr, size)
6059

61-
@classmethod
60+
@classmethod
6261
def _IOW(cls, t,nr,size):
6362
return cls._IOC(cls._IOC_WRITE, t, nr, size)
6463

65-
@classmethod
64+
@classmethod
6665
def _IOWR(cls,t,nr,size):
6766
return cls._IOC(cls._IOC_WRITE|cls._IOC_READ, t, nr, size)
6867

6968

7069
# IOCTL (as defined in fioc.h)
71-
# Note: on my system, size_t is an unsigned long
70+
# Note: on my system, size_t is an unsigned long
7271
FIOC_GET_SIZE = IOCTL._IOR(ord('E'),0, struct.calcsize("L"));
7372
FIOC_SET_SIZE = IOCTL._IOW(ord('E'),1, struct.calcsize("L"));
7473

@@ -107,7 +106,7 @@ def resize(self, new_size):
107106
if new_size < old_size:
108107
self.buf = self.buf[0:new_size]
109108
else:
110-
self.buf = self.buf + str(bytearray(new_size - old_size))
109+
self.buf = self.buf + "\x00" * (new_size - old_size)
111110

112111
return 0
113112

@@ -125,10 +124,10 @@ def getattr(self, path):
125124
st = MyStat()
126125
ft = self.file_type(path)
127126
if ft == FIOC_ROOT:
128-
st.st_mode = stat.S_IFDIR | 0755
127+
st.st_mode = stat.S_IFDIR | 0o755
129128
st.st_nlink = 2
130129
elif ft == FIOC_FILE:
131-
st.st_mode = stat.S_IFREG | 0444
130+
st.st_mode = stat.S_IFREG | 0o444
132131
st.st_nlink = 1
133132
st.st_size = len(self.buf)
134133
else:
@@ -158,13 +157,12 @@ def read(self, path, size, offset):
158157
return self.do_read(path, size, offset)
159158

160159
def do_write(self, path, buf, size, offset):
161-
162160
self.buf = self.buf[0:offset-1] + buf + self.buf[offset+size+1:len(self.buf)]
163161

164162
def write(self, path, buf, size, offset):
165163
if self.file_type(path) != FIOC_FILE:
166164
return -errno.EINVAL;
167-
165+
168166
self.do_write(path, buf, size, offset)
169167

170168
def trunate(self, path, size):
@@ -179,10 +177,10 @@ def readdir(self, path, offset):
179177

180178
def ioctl(self, path, cmd, arg, flags):
181179
if cmd == FIOC_GET_SIZE:
182-
data = struct.pack("L",len(self.buf))
183-
return data
180+
data = struct.pack("L",len(self.buf))
181+
return data
184182
elif cmd == FIOC_SET_SIZE:
185-
(l,) = struct.unpack("L",arg);
183+
(l,) = struct.unpack("L",arg);
186184
self.resize(l)
187185
return 0
188186

example/hello.py

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,7 @@
1717

1818

1919
if not hasattr(fuse, '__version__'):
20-
raise RuntimeError, \
21-
"your fuse-py doesn't know of fuse.__version__, probably it's too old."
20+
raise RuntimeError("your fuse-py doesn't know of fuse.__version__, probably it's too old.")
2221

2322
fuse.fuse_python_api = (0, 2)
2423

@@ -43,10 +42,10 @@ class HelloFS(Fuse):
4342
def getattr(self, path):
4443
st = MyStat()
4544
if path == '/':
46-
st.st_mode = stat.S_IFDIR | 0755
45+
st.st_mode = stat.S_IFDIR | 0o755
4746
st.st_nlink = 2
4847
elif path == hello_path:
49-
st.st_mode = stat.S_IFREG | 0444
48+
st.st_mode = stat.S_IFREG | 0o444
5049
st.st_nlink = 1
5150
st.st_size = len(hello_str)
5251
else:

example/xmp.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,7 @@
2121

2222

2323
if not hasattr(fuse, '__version__'):
24-
raise RuntimeError, \
25-
"your fuse-py doesn't know of fuse.__version__, probably it's too old."
24+
raise RuntimeError("your fuse-py doesn't know of fuse.__version__, probably it's too old.")
2625

2726
fuse.fuse_python_api = (0, 2)
2827

@@ -269,7 +268,7 @@ def main():
269268
if server.fuse_args.mount_expected():
270269
os.chdir(server.root)
271270
except OSError:
272-
print >> sys.stderr, "can't enter root of underlying filesystem"
271+
print("can't enter root of underlying filesystem", file=sys.stderr)
273272
sys.exit(1)
274273

275274
server.main()

0 commit comments

Comments
 (0)