Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

winazurestorage integration, readdir, getattr

  • Loading branch information...
commit 69e918bec270f726f2500644720e9e499a41ee6b 1 parent 51b1525
@ahmetalpbalkan authored
Showing with 97 additions and 16 deletions.
  1. +1 −0  .gitignore
  2. +93 −6 azurefs.py
  3. +0 −8 azuretest.py
  4. +3 −2 winazurestorage.py
View
1  .gitignore
@@ -1,2 +1,3 @@
*.pyc
+*.swp
tmp/*
View
99 azurefs.py
@@ -1,5 +1,10 @@
import logging
from sys import argv, exit
+from stat import S_IFDIR, S_IFREG
+from errno import ENOENT, ENOSYS
+from os import getuid
+import time
+from datetime import datetime
from fuse import FUSE, FuseOSError, Operations, LoggingMixIn
from winazurestorage import *
@@ -10,23 +15,105 @@
log.addHandler(ch)
log.setLevel(logging.DEBUG)
-blobs = None
class AzureFS(LoggingMixIn, Operations):
'Azure Blob Storage filesystem'
+ blobs = None
+
+ dirs = {}
+ files = {} #key: dirname
+
def __init__(self, account, key):
- blobs = BlobStorage(CLOUD_BLOB_HOST, account, key)
- containers = blobs.list_containers()
- for i in containers: print(i)
+ self.blobs = BlobStorage(CLOUD_BLOB_HOST, account, key)
+ now = time.time()
+ uid = getuid()
+
+ self._refresh_dirs()
+
+ def _fetch_containers(self):
+ r = {}
+ for c in self.blobs.list_containers():
+ r['/'+c[0]] = dict(st_mode = (S_IFDIR | 0755), st_uid = getuid(),
+ st_mtime = int(time.mktime(c[2])), st_size = 0,
+ st_nlink = 2)
+ return r
+
+ def _refresh_dirs(self):
+ self.dirs = self._fetch_containers()
+ max_date = sorted([self.dirs[c]['st_mtime'] for c in self.dirs])[-1]
+
+ self.dirs['/'] = dict(st_mode = (S_IFDIR | 0755), st_uid = getuid(),
+ st_mtime = max_date, st_size=0 , st_nlink=2)
+ return self.dirs
+
+ def _parse_path(self, path): # returns </dir, file(=None)>
+ if path.count('/') > 1: #file
+ return path[:path.rfind('/')], path[path.rfind('/')+1:]
+ else: #dir
+ return path[:path[1:].rfind('/')], None
+
+ def _get_container(self, path):
+ base_container = path[1:] #/abc/def/g --> abc
+ if base_container.find('/') > -1:
+ base_container = base_container[:base_container.find('/')]
+ return base_container
+
+ def _list_container_blobs(self, path):
+ d,f = self._parse_path(path)
+ if d in self.files:
+ log.debug("LISTING %s, found" % d)
+ return self.files[d]
+ c = self._get_container(path)
+ log.info("LISTING %s, CONTAINER %s, PATH %s" % (d,c, path))
+
+ blobs = self.blobs.list_blobs(c)
+
+ l = dict()
+ for f in blobs:
+ l[f[0]] = dict(st_mode=(S_IFREG | 0755), st_size=f[3],
+ st_mtime=int(time.mktime(f[2])), st_uid=getuid())
+
+
+ self.files[d] = l
+ return l
+
+ # FUSE
def mkdir(self, path, mode):
log.info('Create directory %s' % path)
+ d = dict(st_mode = (S_IFDIR | mode), st_nlink = 2, st_size = 0)
+ #st_ctime = time(), st_mtime = time(), st_atime = time())
+ self.dirs[path] = d
+ #TODO refresh containers needed?
+ #TODO PUT container
def getattr(self, path, fh=None):
- log.info('Requesting attributes for %s' % path)
- return None
+ d,f = self._parse_path(path)
+
+ if f is None: # dir
+ if path not in self.dirs:
+ raise FuseOSError(ENOENT)
+ return self.dirs[path]
+ else:
+ blobs = self._list_container_blobs(path)
+ if f not in blobs:
+ raise FuseOSError(ENOSYS)
+ else:
+ return blobs[f]
+
+ def getxattr(self, path, name, position=0):
+ return ''
+
+ def readdir(self, path, fh):
+ if path == '/':
+ return ['.', '..'] + [(x[1:]) for x in self.dirs if x != '/']
+ else:
+ blobs = self._list_container_blobs(path)
+ return ['.', '..'] + blobs.keys()
+ def chown(self, path, uid, gid): pass
+ def chmod(self, path, mode): pass
if __name__ == '__main__':
if len(argv) < 4:
View
8 azuretest.py
@@ -1,8 +0,0 @@
-from winazurestorage import *
-
-if __name__=='__main__':
- account = 'ollaa'
- key = u'sPxSZjJAIxonBHG3CAIgMhZOaR+aVBcd1EbpVOblZ7dHBWDhj4T9Jev09rfR+bPqn+GTKzl8baI4UxCqlf4D6Q=='
- blobs = BlobStorage(CLOUD_BLOB_HOST, account, key)
- containers = blobs.list_containers()
- for i in containers: print(i)
View
5 winazurestorage.py
@@ -383,8 +383,9 @@ def list_blobs(self, container_name, blob_prefix=None):
for blob in blobs:
blob_name = blob.getElementsByTagName("Name")[0].firstChild.data
etag = blob.getElementsByTagName("Etag")[0].firstChild.data
+ size = long(blob.getElementsByTagName("Content-Length")[0].firstChild.data)
last_modified = time.strptime(blob.getElementsByTagName("Last-Modified")[0].firstChild.data, TIME_FORMAT)
- yield (blob_name, etag, last_modified)
+ yield (blob_name, etag, last_modified, size)
try: marker = dom.getElementsByTagName("NextMarker")[0].firstChild.data
except: marker = None
if marker is None: break
@@ -405,4 +406,4 @@ def main():
pass
if __name__ == '__main__':
- main()
+ main()
Please sign in to comment.
Something went wrong with that request. Please try again.