@@ -14,7 +14,7 @@ def main():
1414
1515
1616@main .command (help = "Update database once, searches for all directories recursively." )
17- @click .argument ("path" , required = True )
17+ @click .argument ("path" , required = True , type = click . Path ( exists = True ) )
1818@click .option ("-v" , "--verbose" , "verbose" , flag_value = True , default = False )
1919@click .option (
2020 "--include-files" ,
@@ -42,7 +42,7 @@ def batch(path, verbose, include_files):
4242
4343
4444@main .command (help = "Update database continiously, watches for new or changed files." )
45- @click .argument ("path" , required = True )
45+ @click .argument ("path" , required = True , type = click . Path ( exists = True ) )
4646@click .option ("-v" , "--verbose" , "verbose" , flag_value = True , default = False )
4747def watch (path , verbose ):
4848 if verbose :
@@ -65,5 +65,34 @@ def watch(path, verbose):
6565 db .add_pathpair (pair )
6666
6767
68+ @main .command (help = "Get traits of a given path" )
69+ @click .argument ("path" , required = True , type = click .Path (exists = True ))
70+ @click .option ("-v" , "--verbose" , "verbose" , flag_value = True , default = False )
71+ def get (path , verbose ):
72+ if verbose :
73+ logging .basicConfig (level = logging .DEBUG )
74+
75+ abs_path = os .path .abspath (path )
76+ leaf_dir = os .path .dirname (abs_path ) if os .path .isfile (abs_path ) else abs_path
77+ dirs = leaf_dir .split ("/" )
78+ for i in reversed (range (0 , len (dirs ))):
79+ if i == 0 :
80+ db_dir = "/"
81+ else :
82+ db_dir = "/" .join (dirs [0 : i + 1 ])
83+
84+ db_path = db_dir + "/.pathtraits.db"
85+ if not os .path .exists (db_path ):
86+ continue
87+
88+ # TODO: recursive inheritance of pathtraits
89+ db = TraitsDB (db_dir )
90+ data = db .get ("data" , path = abs_path )
91+ print (yaml .safe_dump (data ))
92+ return
93+
94+ KeyError (f"No pathtraits database found in { abs_path } and its parents." )
95+
96+
6897if __name__ == "__main__" :
6998 main ()
0 commit comments