Revision 2152daa0 tools/storefs.py
b/tools/storefs.py | ||
---|---|---|
41 | 41 |
from sys import argv |
42 | 42 |
from time import time |
43 | 43 |
|
44 |
from lib.client import OOS_Client, Fault |
|
45 |
from lib.fuse import FUSE, FuseOSError, Operations |
|
46 |
|
|
47 | 44 |
from pithos.api.compat import parse_http_date |
48 | 45 |
|
49 |
DEFAULT_HOST = 'pithos.dev.grnet.gr' |
|
46 |
from lib.client import OOS_Client, Fault |
|
47 |
from lib.fuse import FUSE, FuseOSError, Operations |
|
48 |
from lib.util import get_user, get_auth, get_server |
|
50 | 49 |
|
51 | 50 |
|
52 | 51 |
epoch = int(time()) |
53 | 52 |
|
54 | 53 |
|
55 | 54 |
class StoreFS(Operations): |
56 |
def __init__(self, user, token, verbose=False):
|
|
55 |
def __init__(self, verbose=False): |
|
57 | 56 |
self.verbose = verbose |
58 |
self.client = OOS_Client(DEFAULT_HOST, token, user)
|
|
57 |
self.client = OOS_Client(get_server(), get_auth(), get_user())
|
|
59 | 58 |
|
60 | 59 |
def __call__(self, op, path, *args): |
61 | 60 |
container, sep, object = path[1:].partition('/') |
... | ... | |
147 | 146 |
return [k[len(prefix):] for k in meta if k.startswith(prefix)] |
148 | 147 |
|
149 | 148 |
def account_readdir(self, fh): |
150 |
return ['.', '..'] + self.client.list_containers() |
|
149 |
return ['.', '..'] + self.client.list_containers() or []
|
|
151 | 150 |
|
152 | 151 |
def account_removexattr(self, name): |
153 | 152 |
attr = 'xattr-' + name |
... | ... | |
198 | 197 |
self.client.create_container(container, mode=mode) |
199 | 198 |
|
200 | 199 |
def container_readdir(self, container, fh): |
201 |
params = {'delimiter': '/', 'prefix': ''} |
|
202 |
objects = self.client.list_objects(container, params=params) |
|
200 |
objects = self.client.list_objects(container, delimiter='/', prefix='') |
|
203 | 201 |
files = [o for o in objects if not o.endswith('/')] |
204 | 202 |
return ['.', '..'] + files |
205 | 203 |
|
... | ... | |
245 | 243 |
|
246 | 244 |
def object_getattr(self, container, object, fh=None): |
247 | 245 |
meta = self._get_object_meta(container, object) |
248 |
mode = int(meta.get('x-object-meta-mode', 0644)) |
|
249 | 246 |
modified = parse_http_date(meta['last-modified']) |
250 | 247 |
uid = int(meta.get('x-account-meta-uid', 0)) |
251 | 248 |
gid = int(meta.get('x-account-meta-gid', 0)) |
252 |
size = int(meta['content-length'])
|
|
249 |
size = int(meta.get('content-length', 0))
|
|
253 | 250 |
|
254 | 251 |
if meta['content-type'] == 'application/directory': |
252 |
mode = int(meta.get('x-object-meta-mode', 0755)) |
|
255 | 253 |
flags = S_IFDIR |
256 | 254 |
nlink = 2 |
257 | 255 |
else: |
256 |
mode = int(meta.get('x-object-meta-mode', 0644)) |
|
258 | 257 |
flags = S_IFREG |
259 | 258 |
nlink = 1 |
260 | 259 |
|
... | ... | |
287 | 286 |
return data[offset:offset + nbyte] |
288 | 287 |
|
289 | 288 |
def object_readdir(self, container, object, fh): |
290 |
params = {'delimiter': '/', 'prefix': object}
|
|
291 |
objects = self.client.list_objects(container, params=params)
|
|
289 |
objects = self.client.list_objects(container, delimiter='/',
|
|
290 |
prefix=object)
|
|
292 | 291 |
files = [o.rpartition('/')[2] for o in objects if not o.endswith('/')] |
293 | 292 |
return ['.', '..'] + files |
294 | 293 |
|
... | ... | |
325 | 324 |
return len(data) |
326 | 325 |
|
327 | 326 |
|
328 |
if __name__ == "__main__":
|
|
329 |
if len(argv) != 4:
|
|
330 |
print 'usage: %s <user> <token> <mountpoint>' % argv[0]
|
|
327 |
if __name__ == '__main__':
|
|
328 |
if len(argv) != 2:
|
|
329 |
print 'usage: %s <mountpoint>' % argv[0] |
|
331 | 330 |
exit(1) |
332 | 331 |
|
333 | 332 |
user = getuser() |
334 |
fs = StoreFS(argv[1], argv[2], verbose=True) |
|
335 |
fuse = FUSE(fs, argv[3], foreground=True) |
|
333 |
fs = StoreFS(verbose=True) |
|
334 |
fuse = FUSE(fs, argv[1], foreground=True) |
Also available in: Unified diff