fixed config folder hierarchy
This commit is contained in:
parent
fc7a00ca66
commit
07f9da8655
5 changed files with 51 additions and 24 deletions
|
|
@ -1,3 +1,7 @@
|
|||
config:
|
||||
id3:
|
||||
types:
|
||||
- .wav
|
||||
files:
|
||||
TODO.md:
|
||||
contexts:
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ projects:
|
|||
- test
|
||||
- test2
|
||||
contexts:
|
||||
- frrr
|
||||
- frrreee
|
||||
howard:
|
||||
- fool
|
||||
---
|
||||
|
|
|
|||
|
|
@ -24,6 +24,8 @@ class OrvaniTag:
|
|||
CACHEFILE = '' # search index cache ('.index.yaml')
|
||||
DB = dict() # holds the folder context data
|
||||
CONFIG = dict()
|
||||
CONF_FILES = []
|
||||
ROOT_CONFIG = dict()
|
||||
FILENAME = '' # folder context data filename ('.context.yaml')
|
||||
FILE = '' # holds the folder context file path
|
||||
CTX = {}
|
||||
|
|
@ -54,26 +56,47 @@ class OrvaniTag:
|
|||
path (str): path of the new folder context
|
||||
|
||||
"""
|
||||
self.FILE = Path(path) / self.FILENAME
|
||||
|
||||
def __config(path):
|
||||
if self.CONF_FILES:
|
||||
for conf_file in self.CONF_FILES:
|
||||
if '.' + os.path.commonpath([conf_file[1:], path[1:]]) == conf_file:
|
||||
cfile = Path(conf_file) / self.FILENAME
|
||||
conf = yaml.safe_load(cfile.read_text())
|
||||
if 'config' in conf:
|
||||
self.CONFIG = conf['config']
|
||||
continue
|
||||
else:
|
||||
self.CONFIG = dict()
|
||||
|
||||
self.FILE = Path(str(path)) / self.FILENAME
|
||||
if self.FILE.exists():
|
||||
y = yaml.safe_load(self.FILE.read_text())
|
||||
self.DB = y['files']
|
||||
if 'config' in y:
|
||||
self.CONFIG = y['config']
|
||||
self.CONF_FILES.append(str(path))
|
||||
self.CONF_FILES = [x for x in self.CONF_FILES if x != '']
|
||||
self.CONF_FILES = sorted(list(set(self.CONF_FILES)), key=lambda x: x.count('/'), reverse=True)
|
||||
else:
|
||||
__config(path)
|
||||
else:
|
||||
self.DB = dict()
|
||||
# self.CONFIG = dict()
|
||||
__config(path)
|
||||
|
||||
def __save(self):
|
||||
"""
|
||||
Save current folder context to file
|
||||
|
||||
"""
|
||||
y = { 'files' : self.DB }
|
||||
if self.CONFIG:
|
||||
y['config'] = self.CONFIG
|
||||
with Path(self.FILE).open('w+') as data:
|
||||
yaml.safe_dump(y, data)
|
||||
file = Path(self.FILE)
|
||||
yf = { 'files' : self.DB }
|
||||
if file.is_file():
|
||||
tmp = yaml.safe_load(file.read_text())
|
||||
if 'config' in tmp:
|
||||
yf['config'] = tmp['config']
|
||||
with file.open('w+') as data:
|
||||
yaml.safe_dump(yf, data)
|
||||
|
||||
|
||||
def __context(self, argv) -> dict:
|
||||
|
|
@ -158,13 +181,13 @@ class OrvaniTag:
|
|||
target = Path(file)
|
||||
if target.exists():
|
||||
self.__cd(target.parent)
|
||||
if fop:
|
||||
target.unlink(missing_ok=True)
|
||||
if target.name in self.DB:
|
||||
del self.DB[target.name]
|
||||
self.__save()
|
||||
if not self.DB:
|
||||
Path(self.FILE).unlink(missing_ok=True)
|
||||
self.__save()
|
||||
if fop:
|
||||
target.unlink(missing_ok=True)
|
||||
|
||||
def move(self, source: str, dest: str, retain: bool=False, fop: bool=True):
|
||||
"""
|
||||
|
|
@ -187,11 +210,11 @@ class OrvaniTag:
|
|||
self.__cd(sourcefolder)
|
||||
if self.DB[sourcefile]:
|
||||
sourcedata = self.DB[sourcefile]
|
||||
if not retain:
|
||||
self.delete(source)
|
||||
self.__cd(destfolder)
|
||||
self.DB.update( { destfile : sourcedata } )
|
||||
self.__save()
|
||||
if not retain:
|
||||
self.delete(source)
|
||||
if fop:
|
||||
if retain:
|
||||
shutil.copy2(source, dest)
|
||||
|
|
@ -277,14 +300,16 @@ class OrvaniTag:
|
|||
self.__indexfolder(path)
|
||||
if recursive:
|
||||
for (root,dirs,files) in os.walk(path):
|
||||
if files:
|
||||
for file in files:
|
||||
fpath = os.path.join(root, file)
|
||||
self.__cd(root)
|
||||
self.metadata(fpath)
|
||||
if dirs:
|
||||
for dir in dirs:
|
||||
rpath = os.path.join(root, dir)
|
||||
self.__indexfolder(rpath)
|
||||
if files:
|
||||
for file in files:
|
||||
fpath = os.path.join(root, file)
|
||||
self.metadata(fpath)
|
||||
|
||||
if cache:
|
||||
with open(cachefile, 'w+') as data:
|
||||
yaml.dump(self.INDEX, data)
|
||||
|
|
@ -298,7 +323,7 @@ class OrvaniTag:
|
|||
"""
|
||||
target = Path(sub)
|
||||
if target.is_dir():
|
||||
self.__cd(target.name)
|
||||
self.__cd(sub)
|
||||
if self.DB:
|
||||
for file in self.DB.keys():
|
||||
path = os.path.join(sub, file)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ import re
|
|||
from pathlib import Path
|
||||
|
||||
NAME = 'hash//'
|
||||
TYPES = ['.md', '.txt', '.markdown', '.rst']
|
||||
TYPES = ['.md', '.txt', '.py']
|
||||
REGEX = r'\s*([@+]\w+|#\w+(?<!#//))'
|
||||
|
||||
def reader(o):
|
||||
|
|
|
|||
|
|
@ -1,13 +1,11 @@
|
|||
config:
|
||||
hash//:
|
||||
types:
|
||||
- .py
|
||||
id3:
|
||||
types:
|
||||
- .wav
|
||||
map:
|
||||
projects: artist
|
||||
contexts: genre
|
||||
projects: album
|
||||
contexts: artist
|
||||
tags: genre
|
||||
note: title
|
||||
files:
|
||||
test.txt:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue