Skip to content
Permalink
boar-py3-devel
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Go to file
 
 
Cannot retrieve contributors at this time
executable file 146 lines (126 sloc) 4.91 KB
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright 2010 Mats Ekberg
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
import os, stat, errno, sys
import fuse
from fuse import Fuse
from blobrepo import repository
from front import Front
from common import *
if not hasattr(fuse, '__version__'):
raise RuntimeError, \
"your fuse-py doesn't know of fuse.__version__, probably it's too old."
fuse.fuse_python_api = (0, 2)
class MyStat(fuse.Stat):
def __init__(self):
self.st_mode = 0
self.st_ino = 0
self.st_dev = 0
self.st_nlink = 0
self.st_uid = 0
self.st_gid = 0
self.st_size = 0
self.st_atime = 0
self.st_mtime = 0
self.st_ctime = 0
class BoarFS(Fuse):
def __init__(self, front, revision, *args, **kwargs):
Fuse.__init__(self, *args, **kwargs)
self.front = front
self.revision = revision
bloblist = front.get_session_bloblist(revision)
self.files = {}
for i in bloblist:
i['type'] = "file"
i['dir'] = "/" + os.path.dirname(i['filename'])
assert i['filename'] not in self.files, "Dupes in bloblist - repository corruption?"
self.files[i['filename']] = i
dirname = os.path.dirname(i['filename'])
if dirname and dirname not in self.files: # Don't add an empty top dir name
self.files[dirname] = { 'filename': dirname, 'type': 'directory', 'size': 0, 'dir': "/" + os.path.dirname(dirname) }
def getattr(self, path):
path = unicode(path, locale.getpreferredencoding())
st = MyStat()
st.st_uid = os.geteuid()
st.st_gid = os.getegid()
fn = path[1:]
if path == '/':
st.st_mode = stat.S_IFDIR | 0755
st.st_nlink = 2
elif fn in self.files.keys():
info = self.files[fn]
if info['type'] == 'file':
st.st_mode = stat.S_IFREG | 0444
st.st_nlink = 1
st.st_size = self.files[fn]['size']
st.st_mtime = self.files[fn]['mtime']
st.st_ctime = self.files[fn]['ctime']
elif info['type'] == 'directory':
st.st_mode = stat.S_IFDIR | 0755
st.st_nlink = 2
else:
return -errno.ENOENT
return st
def readdir(self, path, offset):
for r in '.', '..':
yield fuse.Direntry(r)
for i in self.files.values():
fn = i['filename']
if i['dir'] == path:
yield fuse.Direntry(os.path.basename(fn).encode(locale.getpreferredencoding()))
def open(self, path, flags):
path = unicode(path, locale.getpreferredencoding())
fn = path[1:]
if fn not in self.files:
return -errno.ENOENT
accmode = os.O_RDONLY | os.O_WRONLY | os.O_RDWR
if (flags & accmode) != os.O_RDONLY:
return -errno.EACCES
def read(self, path, size, offset):
path = unicode(path, locale.getpreferredencoding())
fn = path[1:]
if fn not in self.files:
return -errno.ENOENT
repo = self.front.repo
fileinfo=self.files[fn]
assert repo.has_blob(fileinfo['md5sum']), "Blob does not exist in the repository. Corrupt repo?"
blob_size = repo.get_blob_size(fileinfo['md5sum'])
read_size = min(size, blob_size - offset)
reader = repo.get_blob_reader(fileinfo['md5sum'], offset=offset, size=read_size)
buf = reader.read()
return buf
def main():
usage="""Usage: boarmount <repository> <session name> <mount point>"""
if len(sys.argv) != 4:
print usage
exit()
repopath, sessionName = map(tounicode, sys.argv[1:3])
repopath = os.path.abspath(repopath)
front = Front(repository.Repo(repopath))
revision = front.find_last_revision(sessionName)
assert revision != None, "No such session found: " + sessionName
print "Connecting to revision", revision, "on session", sessionName
server = BoarFS(front=front,
revision = revision,
version="%prog " + fuse.__version__,
usage=usage,
dash_s_do='setsingle')
server.parse(errex=1)
server.main()
if __name__ == '__main__':
#log_stream = StreamEncoder(open("/tmp/boarmount.log", "w"))
#sys.stdout = log_stream
#sys.stderr = log_stream
main()