init, add, remove, purge
This commit is contained in:
commit
e9259dc7ba
6 changed files with 133 additions and 0 deletions
16
COMMANDS.md
Normal file
16
COMMANDS.md
Normal file
|
|
@ -0,0 +1,16 @@
|
|||
# Tagging
|
||||
|
||||
+ add file.txt @context +project #tag This is a note
|
||||
+ del file.txt @context
|
||||
|
||||
# File Operations
|
||||
|
||||
+ copy/cp file.txt dir/file.txt
|
||||
+ move/mv file.txt dir/file.txt
|
||||
+ del/rm file.txt
|
||||
|
||||
# DB Operations
|
||||
|
||||
+ dir/list/ls -r dir TERM
|
||||
+ listcon/lsc -r dir TERM
|
||||
+ listproj/lsprj -r dir TERM
|
||||
6
TODO.md
Normal file
6
TODO.md
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
+ yaml db
|
||||
+ command line tools
|
||||
+ todo.txt like commands
|
||||
+ recursion
|
||||
+ audio player (id3 tags)
|
||||
+ support for markdown tags
|
||||
17
context.yaml
Normal file
17
context.yaml
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
TODO.md:
|
||||
contexts: []
|
||||
note: and another note
|
||||
projects:
|
||||
- project2
|
||||
tags:
|
||||
- tag2
|
||||
file.txt:
|
||||
contexts: []
|
||||
projects: []
|
||||
tags:
|
||||
- frrr
|
||||
frrr.md:
|
||||
contexts: []
|
||||
projects: []
|
||||
tags:
|
||||
- frrr
|
||||
5
dir/context.yaml
Normal file
5
dir/context.yaml
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
file.txt:
|
||||
contexts: []
|
||||
note: weird
|
||||
projects: []
|
||||
tags: []
|
||||
0
dir/file.txt
Normal file
0
dir/file.txt
Normal file
89
orvani.py
Normal file
89
orvani.py
Normal file
|
|
@ -0,0 +1,89 @@
|
|||
import os
|
||||
import yaml
|
||||
|
||||
class OrvaniTag:
|
||||
|
||||
DB = dict()
|
||||
FILE = ''
|
||||
CTX = {
|
||||
'contexts' : '@',
|
||||
'projects' : '+',
|
||||
'tags' : '#'
|
||||
}
|
||||
|
||||
def __init__(self, path: str='context.yaml', contexts=CTX):
|
||||
self.FILE = path
|
||||
self.__cd()
|
||||
|
||||
def __cd(self):
|
||||
"""change file context to subdirectory"""
|
||||
if os.path.isfile(self.FILE):
|
||||
try:
|
||||
with open(self.FILE, 'r') as data:
|
||||
self.DB = yaml.safe_load(data)
|
||||
except Exception:
|
||||
print('File does not exist')
|
||||
else:
|
||||
self.DB = dict()
|
||||
|
||||
def __save(self):
|
||||
"""save context file to current directory"""
|
||||
try:
|
||||
with open(self.FILE, 'w+') as data:
|
||||
yaml.dump(self.DB, data)
|
||||
except Exception:
|
||||
print('File write error')
|
||||
|
||||
def __context(self, argv) -> dict:
|
||||
"""create context for given filename"""
|
||||
context = dict()
|
||||
for ctx in self.CTX.keys():
|
||||
context.update( { ctx : []})
|
||||
for arg in argv:
|
||||
for ctx in self.CTX.keys():
|
||||
if str(arg)[0] in self.CTX.values():
|
||||
if str(arg).startswith(self.CTX[ctx]):
|
||||
context[ctx].append(str(arg)[1:])
|
||||
else:
|
||||
context.update( { 'note' : str(arg)})
|
||||
return context
|
||||
|
||||
def add(self, file: str, *argv: str):
|
||||
if os.path.dirname(file):
|
||||
self.FILE = os.path.join(os.path.dirname(file), self.FILE)
|
||||
self.__cd()
|
||||
file = os.path.basename(file)
|
||||
context = self.__context(argv)
|
||||
if file in self.DB:
|
||||
for ctx in self.CTX.keys():
|
||||
self.DB[file][ctx] = list(set( self.DB[file][ctx] + context[ctx]))
|
||||
if 'note' in context.keys():
|
||||
self.DB[file]['note'] = context['note']
|
||||
else:
|
||||
self.DB.update( { file : context } )
|
||||
self.__save()
|
||||
|
||||
def remove(self, file: str, *argv: str):
|
||||
if os.path.dirname(file):
|
||||
self.FILE = os.path.join(os.path.dirname(file), self.FILE)
|
||||
self.__cd()
|
||||
file = os.path.basename(file)
|
||||
context = self.__context(argv)
|
||||
if file in self.DB:
|
||||
for ctx in self.CTX.keys():
|
||||
for item in context[ctx]:
|
||||
if item in self.DB[file][ctx]:
|
||||
self.DB[file][ctx].remove(item)
|
||||
self.__save()
|
||||
|
||||
def purge(self, file: str):
|
||||
if os.path.dirname(file):
|
||||
self.FILE = os.path.join(os.path.dirname(file), self.FILE)
|
||||
self.__cd()
|
||||
file = os.path.basename(file)
|
||||
if file in self.DB:
|
||||
del self.DB[file]
|
||||
self.__save()
|
||||
|
||||
o = OrvaniTag()
|
||||
o.add('dir/file.txt', 'weird')
|
||||
Loading…
Add table
Add a link
Reference in a new issue