diff --git a/TODO.md b/TODO.md index 1d51301..71874c6 100644 --- a/TODO.md +++ b/TODO.md @@ -2,6 +2,5 @@ tags: - frrr --- -+ todo format import/export + documentation + rich verbosity \ No newline at end of file diff --git a/context.txt b/context.txt index f1a81e3..f392700 100644 --- a/context.txt +++ b/context.txt @@ -1,16 +1,14 @@ -./README.md --- @frrreee #fool #writeme -./TODO.md --- +bokertov @python #rusty #frrr Chawera -./requirements.txt --- pip reqs -./test --- @folder #spaces -./COMMANDS.md --- +coding @erfwegf #super #great This is awesome +./COMMANDS.md --- +coding @erfwegf #great #super This is awesome +./README.md --- @frrreee #writeme #fool +./TODO.md --- +bokertov @python #rusty Chawera #frrr +./test/chirpy.wav --- +parakeetio +sensorwatch @watch McFlu McFlu McFlu This is a title ./test/folder with spaces --- +totally #spaces -./test/office.odt --- +oopsie +orvani @this #whoa #that and a note +./test/office.odt --- +oopsie +orvani #whoa +orvani @this #that #whoa and a note ./test/sheet.xlsx --- +orvani @calc #tessssting ./test/sub --- @folder ./test/test.txt --- +test @test #faa #test frrr ./test/table.ods --- @calc #tessssting ./test/tableold.xls --- @calc #tessssting -./test/chirpy.wav --- +sensorwatch +parakeetio @Chripo @watch @Chripo McFlu #funk McFlu McFlu This is a title This is a title This is a title ./test/oldword.doc --- and a note ./test/word.docx --- @concon #tagz ./test/sub/statement_14793553_USD_2022-11-01_2023-01-31.pdf --- +yeeha @pdfcontext #yay #frrrrrrrr And a comment too diff --git a/orvani/cmd.py b/orvani/cmd.py index b511060..b85e1d3 100644 --- a/orvani/cmd.py +++ b/orvani/cmd.py @@ -12,7 +12,7 @@ def mktable(query: str, index: dict, filter=None): if len(index['found']) > 0: table = Table(title=f"Results for `{query}`") ctx = list(CONTEXTS.keys()) - table.add_column("Path", justify="right", style="white", no_wrap=True) + table.add_column("Path", style="white", no_wrap=True) styles = ["cyan", "yellow", "magenta", "green"] for i, c in enumerate(ctx): table.add_column(ctx[i].title(), style=styles[i]) diff --git a/orvani/orvani.py b/orvani/orvani.py index 4751157..7a6dc3b 100644 --- a/orvani/orvani.py +++ b/orvani/orvani.py @@ -85,13 +85,17 @@ class OrvaniTag: self.FILE = Path(str(path)) / self.FILENAME if self.FILE.exists(): y = yaml.safe_load(self.FILE.read_text()) - self.DB = y['items'] - 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) + if 'items' in y: + self.DB = y['items'] + 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() __config(path) else: self.DB = dict() @@ -334,6 +338,7 @@ class OrvaniTag: self.__updateindex(path, self.DB[file], context_key) def __updateindex(self, path: str, context: dict, context_key: str): + # Update files index for key, value in context.items(): if path in self.INDEX['items']: @@ -345,6 +350,8 @@ class OrvaniTag: else: self.INDEX['items'][path] = { key : value } + self.INDEX['items'] = {key: value for key, value in sorted(self.INDEX['items'].items())} + # Update context index if type(context[context_key]) == list: for item in context[context_key]: @@ -462,7 +469,7 @@ class OrvaniTag: for context_key in context.keys(): self.__updateindex(filename, context, context_key) - def __collect_contexts(self, context: dict): + def __collect_contexts(self, context: dict, delineate: bool = False): elements = [] context_keys = list(CONTEXTS.keys()) for context_key in context_keys: @@ -476,7 +483,10 @@ class OrvaniTag: if not type(context[context_key]) == str: elements.append(' '.join([prefix + tag for tag in context[context_key]])) else: - elements.append(context[context_key]) + if delineate: + elements.append(f"'{context[context_key]}'") + else: + elements.append(context[context_key]) return elements def write(self, filename: str, method: str): @@ -516,16 +526,42 @@ class OrvaniTag: index = self.list(file.parent, False, False, True, False, False, '') items = index['index']['items'] content = "" - for path in items: - string = ' '.join([x for x in self.__collect_contexts(items[path]) if x != None]) - content += f'{path} --- {string}\n' - file.write_text(content) + if len(items): + for path in items: + string = ' '.join([x for x in self.__collect_contexts(items[path]) if x != None]) + content += f'{path} --- {string}\n' + file.write_text(content) def load(self, filename:str): if filename == '' or filename == None: filename = 'context.txt' file = Path(filename) - imported = file.read_text() - known = self.list(file.parent, False, False, True, False, False, '')['index']['items'] - print(known) - + if file.exists(): + imported = file.read_text().split('\n') + if len(imported): + known = self.list(file.parent, False, False, True, False, False, '')['index']['items'] + for import_line in imported: + line_elements = import_line.split('---') + if len(line_elements) > 1: + path = line_elements[0].strip() + new_file = Path(path) + if new_file.exists(): + string = line_elements[1].strip() + if string: + new_file_context = self.__context(self.get_argv(string)) + if path in known.keys(): + known_file_context = known[path] + context = new_file_context.copy() + for new_context in new_file_context: + if type(new_file_context[new_context]) == list: + for context_item in new_file_context[new_context]: + if new_context in known_file_context.keys(): + if context_item in known_file_context[new_context]: + context[new_context].remove(context_item) + else: + if new_context in known_file_context.keys(): + if new_file_context[new_context] == known_file_context[new_context]: + del context[new_context] + ctx_str = self.__collect_contexts(context) + if ctx_str: + self.add(path, *ctx_str) \ No newline at end of file diff --git a/orvani/plugins/id3.py b/orvani/plugins/id3.py index 34e9485..f43e60e 100644 --- a/orvani/plugins/id3.py +++ b/orvani/plugins/id3.py @@ -33,6 +33,7 @@ def reader(o): for key in id3map.keys(): if key in context.keys(): context[key] += id3map[key] + context[universal] = '; '.join(context[universal]) return context def writer(o): diff --git a/test/.context.yaml b/test/.context.yaml index 40f4da9..4f2447a 100644 --- a/test/.context.yaml +++ b/test/.context.yaml @@ -6,33 +6,18 @@ config: projects: album tags: genre items: - folder with spaces: + chirpy.wav: contexts: [] + note: McFlu McFlu McFlu This is a title projects: - - totally - tags: - - spaces + - parakeetio + - sensorwatch + tags: [] office.odt: contexts: [] projects: + - oopsie - orvani - tags: [] - sheet.xlsx: - contexts: [] - projects: - - orvani - tags: [] - sub: - contexts: - - folder - projects: [] - tags: [] - test.txt: - contexts: - - test - note: frrr - projects: - - test tags: - - faa - - test + - whoa + - that diff --git a/todo.txt b/todo.txt new file mode 100644 index 0000000..8d12d6d --- /dev/null +++ b/todo.txt @@ -0,0 +1,13 @@ +./COMMANDS.md --- +coding @erfwegf #great #super This is awesome +./README.md --- @frrreee #fool #writeme +./TODO.md --- +bokertov @python #rusty #frrr Chawera +./orvani/plugins/hashdoubleslash.py --- +orvani @python #example It even works in Python code +./test/chirpy.wav --- +parakeetio +sensorwatch @watch @Chripo @Chripo McFlu #funk McFlu McFlu This is a title This is a title; This is a title +./test/folder with spaces/file with spaces.txt --- #spaces +./test/office.odt --- +oopsie +orvani @this #whoa #that and a note +./test/oldword.doc --- and a note +./test/sheet.xlsx --- +orvani @calc #tessssting +./test/sub/statement_14793553_USD_2022-11-01_2023-01-31.pdf --- +yeeha @pdfcontext #frrrrrrrr #yay And a comment too +./test/table.ods --- @calc #tessssting +./test/tableold.xls --- @calc #tessssting +./test/word.docx --- @concon #tagz