@@ -165,6 +165,10 @@ def load_repos(self):
165165 logger .error (f"Error reading file: { e } " )
166166 return None
167167
168+ def get_index (self ):
169+ if self ._index is None :
170+ self ._index = Index (self .repos_path , self .repos )
171+ return self ._index
168172
169173 def __init__ (self ):
170174 setup_logging (log_path = os .getcwd (), log_file = '.mlc-log.txt' )
@@ -200,7 +204,7 @@ def __init__(self):
200204
201205 self .repos = self .load_repos_and_meta ()
202206 #logger.info(f"In Action class: {self.repos_path}")
203- self .index = Index ( self . repos_path , self . repos )
207+ self ._index = None
204208
205209
206210 def add (self , i ):
@@ -380,7 +384,7 @@ def rm(self, i):
380384
381385 logger .info (f"{ target_name } item: { item_path } has been successfully removed" )
382386
383- self .index .rm (item_meta , target_name , item_path )
387+ self .get_index () .rm (item_meta , target_name , item_path )
384388
385389 return {
386390 "return" : 0 ,
@@ -413,7 +417,7 @@ def save_new_meta(self, i, item_id, item_name, target_name, item_path, repo):
413417 if save_result ["return" ] > 0 :
414418 return save_result
415419
416- self .index .add (item_meta , target_name , item_path , repo )
420+ self .get_index () .add (item_meta , target_name , item_path , repo )
417421 return {'return' : 0 }
418422
419423 def update (self , i ):
@@ -482,7 +486,7 @@ def update(self, i):
482486 # Save the updated meta back to the item
483487 item .meta = meta
484488 save_result = utils .save_json (item_meta_path , meta = meta )
485- self .index .update (meta , target_name , item .path , item .repo )
489+ self .get_index () .update (meta , target_name , item .path , item .repo )
486490
487491 return {'return' : 0 , 'message' : f"Tags updated successfully for { len (found_items )} item(s)." , 'list' : found_items }
488492
@@ -641,13 +645,13 @@ def mv(self, run_args):
641645 #Put the src uid to the destination path
642646 dest .meta ['uid' ] = src .meta ['uid' ]
643647 dest ._save_meta ()
644- self .index .update (dest .meta , target_name , dest .path , dest .repo )
648+ self .get_index () .update (dest .meta , target_name , dest .path , dest .repo )
645649 logger .info (f"""Item with uid { dest .meta ['uid' ]} successfully moved from { src .path } to { dest .path } """ )
646650
647651 return {'return' : 0 , 'src' : src , 'dest' : dest }
648652
649653 def search (self , i ):
650- indices = self .index .indices
654+ indices = self .get_index () .indices
651655 target = i .get ('target_name' , self .action_type )
652656 target_index = indices .get (target )
653657 result = []
0 commit comments