Initial commit

This commit is contained in:
Suzanne Soy 2023-09-09 18:18:03 +01:00
commit 23d3773a58
10 changed files with 78 additions and 0 deletions

2
.gitignore vendored Normal file
View File

@ -0,0 +1,2 @@
/cache/
/mnt/

66
fs.py Executable file
View File

@ -0,0 +1,66 @@
#!/usr/bin/env python
import os, sys, shutil, pathlib
from fuse import FUSE, FuseOSError, Operations
class FilterFS(Operations):
def __init__(self, source, cache):
self.source = source
self.cache = cache
def _original(self, path):
print(path)
p = os.path.join(self.source, path.lstrip('/'))
if os.path.islink(p):
rl = os.readlink(p)
if rl.startswith('/!/'):
cached_output = os.path.join(self.cache, path.lstrip('/'))
if not os.path.exists(cached_output):
rl = rl[3:]
d = os.path.dirname(p)
# begin hack
old_cwd = os.getcwd()
os.chdir(d)
os.system(rl)
os.chdir(old_cwd)
pathlib.Path(os.path.dirname(cached_output)).mkdir(parents = True, exist_ok = True)
shutil.move(os.path.join(d, 'out'), cached_output)
# end hack
p = cached_output
return p
# directory
def readdir(self, path, fh):
yield '.'
yield '..'
if os.path.isdir(self._original(path)):
for d in os.listdir(self._original(path)):
yield d
# directory, file etc.
def getattr(self, path, file_handle = None):
st = os.lstat(self._original(path))
return {
'st_mode': st.st_mode, # 0o100775 file, 0o40775 dir
#'st_ino': 42,
#'st_dev': 123,
'st_nlink': st.st_nlink,
'st_uid': st.st_uid,
'st_gid': st.st_gid,
'st_size': st.st_size,
'st_atime': st.st_atime,
'st_mtime': st.st_mtime,
'st_ctime': st.st_ctime,
}
# file
def open(self, path, flags):
return os.open(self._original(path), flags)
def read(self, path, length, offset, file_handle):
os.lseek(file_handle, offset, os.SEEK_SET)
return os.read(file_handle, length)
def main(source, cache, mountpoint):
FUSE(FilterFS(source, cache), mountpoint, nothreads=True, foreground=True)
if __name__ == '__main__':
main(sys.argv[1], sys.argv[2], sys.argv[3])

7
source/*.ogg Normal file
View File

@ -0,0 +1,7 @@
output(filename) {
return filename + '.mp3'
}
contents(filename) {
... create an mp3 from the ogg
}

0
source/bar.ogg Normal file
View File

0
source/baz.ogg Normal file
View File

1
source/foo.mp3 Symbolic link
View File

@ -0,0 +1 @@
/!/lame -vbr -b 240 foo.ogg output.mp3; mv output.mp3 out

0
source/foo.ogg Normal file
View File

0
source/quux.ogg Normal file
View File

1
source/some_dir/aaa Normal file
View File

@ -0,0 +1 @@
Hello World!

1
source/some_dir/bbb Symbolic link
View File

@ -0,0 +1 @@
/!/tr '[:lower:]' '[:upper:'] < aaa > out