+ basics
commit
c0aa9ae4e7
|
@ -0,0 +1,216 @@
|
|||
#!/usr/bin/env python3
|
||||
|
||||
import requests
|
||||
import random
|
||||
import os
|
||||
import sys
|
||||
import errno
|
||||
|
||||
from fuse import FUSE, FuseOSError, Operations, fuse_get_context
|
||||
|
||||
releases = []
|
||||
assets = {}
|
||||
headers = {"Authorization":"token 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"}
|
||||
repo = "owosoftware"
|
||||
|
||||
def getReleases():
|
||||
if not releases:
|
||||
a=requests.get("https://api.github.com/repos/DomiOwO/"+repo+"/releases", headers=headers);
|
||||
x=a.json()
|
||||
for i in x:
|
||||
releases.extend([{"name":i["tag_name"], "id":i["id"]}])
|
||||
for j in i["assets"]:
|
||||
assets[i["tag_name"]] = {} # change this later
|
||||
for j in i["assets"]:
|
||||
assets[i["tag_name"]][j["name"]]={"id": j["id"], "size": j["size"]}
|
||||
print(assets)
|
||||
|
||||
class Passthrough(Operations):
|
||||
def __init__(self, root):
|
||||
self.root = root
|
||||
|
||||
def _full_path(self, partial):
|
||||
if partial.startswith("/"):
|
||||
partial = partial[1:]
|
||||
path = os.path.join(self.root, partial)
|
||||
return path
|
||||
|
||||
def access(self, path, mode):
|
||||
print("-- access")
|
||||
#full_path = self._full_path(path)
|
||||
#if not os.access(full_path, mode):
|
||||
# raise FuseOSError(errno.EACCES)
|
||||
|
||||
def chmod(self, path, mode):
|
||||
print("-- chmod")
|
||||
#full_path = self._full_path(path)
|
||||
#return os.chmod(full_path, mode)
|
||||
return 0
|
||||
|
||||
def chown(self, path, uid, gid):
|
||||
print("-- chown")
|
||||
#full_path = self._full_path(path)
|
||||
#return os.chown(full_path, uid, gid)
|
||||
return 0
|
||||
|
||||
def getattr(self, path, fh=None):
|
||||
full_path = self._full_path(path)
|
||||
print("-- getattr", full_path)
|
||||
if full_path.split('/')[-2] in assets or len(full_path.split('/')) == 2:
|
||||
if len(full_path.split('/')) < 3:
|
||||
st_mode = 0o40744
|
||||
st_size = 1337
|
||||
else:
|
||||
st_mode = 0o100744
|
||||
print(full_path.split('/'))
|
||||
print(assets[full_path.split('/')[-2]])
|
||||
if full_path.split('/')[-1] in assets[full_path.split('/')[-2]]:
|
||||
st_size = assets[full_path.split('/')[-2]][full_path.split('/')[-1]]["size"]
|
||||
else:
|
||||
st_mode = 0o100000
|
||||
st_size = 0
|
||||
else:
|
||||
st_mode = 0o0
|
||||
st_size = 0
|
||||
|
||||
return {'st_atime': 1639567402.302016,
|
||||
'st_ctime': 1625937692.4645624,
|
||||
'st_gid': 1000,
|
||||
'st_mode': int(st_mode),
|
||||
'st_mtime': 1625937692.4645624,
|
||||
'st_nlink': 16,
|
||||
'st_size': st_size,
|
||||
'st_uid': 1000}
|
||||
|
||||
def readdir(self, path, fh):
|
||||
print("-- readdir")
|
||||
full_path = self._full_path(path)
|
||||
dirents = ['.', '..']
|
||||
print(full_path.split('/'))
|
||||
if len(full_path.split('/')) == 2 and full_path.endswith('/'):
|
||||
for i in releases:
|
||||
print(i)
|
||||
dirents.extend([i["name"]])
|
||||
else:
|
||||
if full_path.endswith('/'):
|
||||
p=full_path.split('/')[-2]
|
||||
else:
|
||||
p=full_path.split('/')[-1]
|
||||
|
||||
if p in assets:
|
||||
for i in assets[p]:
|
||||
dirents.extend([i])
|
||||
|
||||
for r in dirents:
|
||||
yield r
|
||||
|
||||
def readlink(self, path):
|
||||
print("-- readlink")
|
||||
pathname = os.readlink(self._full_path(path))
|
||||
if pathname.startswith("/"):
|
||||
# Path name is absolute, sanitize it.
|
||||
return os.path.relpath(pathname, self.root)
|
||||
else:
|
||||
return pathname
|
||||
|
||||
def mknod(self, path, mode, dev):
|
||||
print("-- mknod")
|
||||
return os.mknod(self._full_path(path), mode, dev)
|
||||
|
||||
def rmdir(self, path):
|
||||
print("-- rmdir")
|
||||
full_path = self._full_path(path)
|
||||
return os.rmdir(full_path)
|
||||
|
||||
def mkdir(self, path, mode):
|
||||
print("-- mkdir")
|
||||
return os.mkdir(self._full_path(path), mode)
|
||||
|
||||
def statfs(self, path):
|
||||
full_path = self._full_path(path)
|
||||
stv = os.statvfs(full_path)
|
||||
print("-- statfs")
|
||||
return dict((key, getattr(stv, key)) for key in ('f_bavail', 'f_bfree',
|
||||
'f_blocks', 'f_bsize', 'f_favail', 'f_ffree', 'f_files', 'f_flag',
|
||||
'f_frsize', 'f_namemax'))
|
||||
|
||||
def unlink(self, path):
|
||||
print("-- unlink")
|
||||
return os.unlink(self._full_path(path))
|
||||
|
||||
def symlink(self, name, target):
|
||||
print("-- symlink")
|
||||
return os.symlink(target, self._full_path(name))
|
||||
|
||||
def rename(self, old, new):
|
||||
print("-- rename")
|
||||
return os.rename(self._full_path(old), self._full_path(new))
|
||||
|
||||
def link(self, target, name):
|
||||
print("-- link")
|
||||
return os.link(self._full_path(name), self._full_path(target))
|
||||
|
||||
def utimens(self, path, times=None):
|
||||
print("-- utimens")
|
||||
#return os.utime(self._full_path(path), times)
|
||||
return 0
|
||||
|
||||
# File methods
|
||||
# ============
|
||||
|
||||
def open(self, path, flags):
|
||||
print("-- open")
|
||||
full_path = self._full_path(path)
|
||||
#return os.open(full_path, flags)
|
||||
return random.randrange(1,100) # TODO
|
||||
|
||||
def create(self, path, mode, fi=None):
|
||||
print("-- create")
|
||||
#uid, gid, pid = fuse_get_context()
|
||||
#full_path = self._full_path(path)
|
||||
#fd = os.open(full_path, os.O_WRONLY | os.O_CREAT, mode)
|
||||
#os.chown(full_path,uid,gid) #chown to context uid & gid
|
||||
return random.randrange(1,100)
|
||||
|
||||
def read(self, path, length, offset, fh):
|
||||
print("-- read: offset ", offset, " len ", length, " path ", path)
|
||||
#os.lseek(fh, offset, os.SEEK_SET)
|
||||
#return os.read(fh, length)
|
||||
return b"maeiscute"
|
||||
|
||||
def write(self, path, buf, offset, fh):
|
||||
print("-- write: offset ", offset, " buf ", buf, " path ", path)
|
||||
#os.lseek(fh, offset, os.SEEK_SET)
|
||||
#return os.write(fh, buf)
|
||||
return 0
|
||||
|
||||
def truncate(self, path, length, fh=None):
|
||||
print("-- truncate")
|
||||
full_path = self._full_path(path)
|
||||
#return random.randrange(1,100)
|
||||
return 0
|
||||
#with open(full_path, 'r+') as f:
|
||||
# f.truncate(length)
|
||||
|
||||
def flush(self, path, fh):
|
||||
print("-- flush")
|
||||
#return os.fsync(fh)
|
||||
return 0
|
||||
|
||||
def release(self, path, fh):
|
||||
print("-- release/close")
|
||||
#return os.close(fh)
|
||||
|
||||
def fsync(self, path, fdatasync, fh):
|
||||
print("-- fsync")
|
||||
return self.flush(path, fh)
|
||||
|
||||
|
||||
def main(mountpoint):
|
||||
root='b'
|
||||
getReleases()
|
||||
FUSE(Passthrough(root), mountpoint, nothreads=True, foreground=True, allow_other=True)
|
||||
|
||||
|
||||
if __name__ == '__main__':
|
||||
main(sys.argv[1])
|
|
@ -0,0 +1,2 @@
|
|||
fusepy
|
||||
requests
|
Loading…
Reference in New Issue