@@ -106,8 +106,7 @@ def is_curdir_inside_path(base_path):
106106 # Iterate through the list of repository paths
107107 for repo_path in repo_paths :
108108 if not os .path .exists (repo_path ):
109- logger .warning (f"""Warning: { repo_path } not found. Considering it as a corrupt entry and deleting automatically...""" )
110- logger .warning (f"Deleting the { meta_yaml_path } entry from repos.json" )
109+ logger .warning (f"""Warning: { repo_path } not found. Considering it as a corrupt entry and deleting from repos.json...""" )
111110 from .repo_action import rm_repo
112111 res = rm_repo (repo_path , os .path .join (self .repos_path , 'repos.json' ), True )
113112
@@ -166,6 +165,10 @@ def load_repos(self):
166165 logger .error (f"Error reading file: { e } " )
167166 return None
168167
168+ def get_index (self ):
169+ if self ._index is None :
170+ self ._index = Index (self .repos_path , self .repos )
171+ return self ._index
169172
170173 def __init__ (self ):
171174 setup_logging (log_path = os .getcwd (), log_file = '.mlc-log.txt' )
@@ -201,7 +204,7 @@ def __init__(self):
201204
202205 self .repos = self .load_repos_and_meta ()
203206 #logger.info(f"In Action class: {self.repos_path}")
204- self .index = Index ( self . repos_path , self . repos )
207+ self ._index = None
205208
206209
207210 def add (self , i ):
@@ -381,7 +384,7 @@ def rm(self, i):
381384
382385 logger .info (f"{ target_name } item: { item_path } has been successfully removed" )
383386
384- self .index .rm (item_meta , target_name , item_path )
387+ self .get_index () .rm (item_meta , target_name , item_path )
385388
386389 return {
387390 "return" : 0 ,
@@ -414,7 +417,7 @@ def save_new_meta(self, i, item_id, item_name, target_name, item_path, repo):
414417 if save_result ["return" ] > 0 :
415418 return save_result
416419
417- self .index .add (item_meta , target_name , item_path , repo )
420+ self .get_index () .add (item_meta , target_name , item_path , repo )
418421 return {'return' : 0 }
419422
420423 def update (self , i ):
@@ -483,7 +486,7 @@ def update(self, i):
483486 # Save the updated meta back to the item
484487 item .meta = meta
485488 save_result = utils .save_json (item_meta_path , meta = meta )
486- self .index .update (meta , target_name , item .path , item .repo )
489+ self .get_index () .update (meta , target_name , item .path , item .repo )
487490
488491 return {'return' : 0 , 'message' : f"Tags updated successfully for { len (found_items )} item(s)." , 'list' : found_items }
489492
@@ -642,13 +645,13 @@ def mv(self, run_args):
642645 #Put the src uid to the destination path
643646 dest .meta ['uid' ] = src .meta ['uid' ]
644647 dest ._save_meta ()
645- self .index .update (dest .meta , target_name , dest .path , dest .repo )
648+ self .get_index () .update (dest .meta , target_name , dest .path , dest .repo )
646649 logger .info (f"""Item with uid { dest .meta ['uid' ]} successfully moved from { src .path } to { dest .path } """ )
647650
648651 return {'return' : 0 , 'src' : src , 'dest' : dest }
649652
650653 def search (self , i ):
651- indices = self .index .indices
654+ indices = self .get_index () .indices
652655 target = i .get ('target_name' , self .action_type )
653656 target_index = indices .get (target )
654657 result = []
0 commit comments