renamed files to items, taggable folders

This commit is contained in:
randogoth 2023-06-09 02:08:34 +03:00
parent b593c18511
commit 91ef2e9cbd
5 changed files with 35 additions and 170 deletions

View file

@ -17,7 +17,7 @@ def mktable(query: str, index: dict):
for i, c in enumerate(ctx):
table.add_column(ctx[i].title(), style=styles[i])
for file in index['found']:
fc = index['index']['files'][file]
fc = index['index']['items'][file]
elements = []
elements.append(file)
for c in ctx:

View file

@ -46,7 +46,7 @@ class OrvaniTag:
self.INDEX = self.CTX.copy()
for context_key in self.INDEX:
self.INDEX[context_key] = {}
self.INDEX['files'] = {}
self.INDEX['items'] = {}
self.__cd('')
def __cd(self, path: str):
@ -73,7 +73,7 @@ class OrvaniTag:
self.FILE = Path(str(path)) / self.FILENAME
if self.FILE.exists():
y = yaml.safe_load(self.FILE.read_text())
self.DB = y['files']
self.DB = y['items']
if 'config' in y:
self.CONFIG = y['config']
self.CONF_FILES.append(str(path))
@ -91,7 +91,7 @@ class OrvaniTag:
"""
file = Path(self.FILE)
yf = { 'files' : self.DB }
yf = { 'items' : self.DB }
if file.is_file():
tmp = yaml.safe_load(file.read_text())
if 'config' in tmp:
@ -322,14 +322,14 @@ class OrvaniTag:
def __updateindex(self, path: str, context: dict, context_key: str):
# Update files index
for key, value in context.items():
if path in self.INDEX['files']:
if key in self.INDEX['files'][path] and isinstance(self.INDEX['files'][path][key], list) and isinstance(value, list):
self.INDEX['files'][path][key] += value
self.INDEX['files'][path][key] = list(set(self.INDEX['files'][path][key]))
if path in self.INDEX['items']:
if key in self.INDEX['items'][path] and isinstance(self.INDEX['items'][path][key], list) and isinstance(value, list):
self.INDEX['items'][path][key] += value
self.INDEX['items'][path][key] = list(set(self.INDEX['items'][path][key]))
else:
self.INDEX['files'][path][key] = value
self.INDEX['items'][path][key] = value
else:
self.INDEX['files'][path] = { key : value }
self.INDEX['items'][path] = { key : value }
# Update context index
if type(context[context_key]) == list:
@ -391,7 +391,7 @@ class OrvaniTag:
min += sublist
result['found'] = list(set(min))
else:
result['found'] = self.INDEX['files'].keys()
result['found'] = self.INDEX['items'].keys()
result['found'] = sorted(result['found'], key=lambda x: x.count('/'))
return result