-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnewbiecontest-fuse.py
executable file
·70 lines (47 loc) · 1.73 KB
/
newbiecontest-fuse.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
#!/usr/bin/env python
# coding: utf-8
import fuse
import itertools
import modules
import modules.news as news
import modules.challenges as challenges
import modules.authrequests as authrequests
fuse.fuse_python_api = (0, 2)
class NewbiecontestFS(fuse.Fuse):
def __init__(self, *args, **kwargs):
super(NewbiecontestFS, self).__init__(*args, **kwargs)
req = authrequests.AuthRequests()
rootmodule = authrequests.Auth(req)
dirmodules = {}
dirmodules["news"] = news.News(req)
dirmodules["challenges"] = challenges.Challenges(req)
self.rootfsmodule = modules.FSSubModule(rootmodule, dirmodules)
def getattr(self, path):
path = path[1:]
return self.rootfsmodule.getattr(path)
def readdir(self, path, offset):
path = path[1:]
dotdot = [fuse.Direntry("."), fuse.Direntry("..")]
f = self.rootfsmodule.readdir(path, offset)
return itertools.chain(dotdot, f)
def open(self, path, *args, **kwargs):
path = path[1:]
return self.rootfsmodule.open(path, *args, **kwargs)
def read(self, path, *args, **kwargs):
path = path[1:]
return self.rootfsmodule.read(path, *args, **kwargs)
def write(self, path, *args, **kwargs):
path = path[1:]
return self.rootfsmodule.write(path, *args, **kwargs)
def truncate(self, path, *args, **kwargs):
path = path[1:]
return self.rootfsmodule.truncate(path, *args, **kwargs)
def main():
usage = "Newbiecontest File System\n\n"
usage += NewbiecontestFS.fusage
server = NewbiecontestFS(usage = usage)
args = server.parse(errex = 1)
args.add('default_permissions')
server.main()
if __name__ == '__main__':
main()