1313from pathlib import Path
1414from colorama import Fore , Style , init
1515import shutil
16+
1617# Initialize colorama for Windows support
1718init (autoreset = True )
1819class ColoredFormatter (logging .Formatter ):
@@ -29,31 +30,13 @@ def format(self, record):
2930 record .levelname = f"{ self .COLORS [record .levelname ]} { record .levelname } { Style .RESET_ALL } "
3031 return super ().format (record )
3132
32-
33- logging .basicConfig (level = logging .INFO , format = '%(asctime)s - %(name)s - %(levelname)s - %(message)s' )
34-
3533logger = logging .getLogger (__name__ )
36- logger .setLevel (logging .INFO )
37-
38- # Create console handler with the custom formatter
39- console_handler = logging .StreamHandler ()
40- console_handler .setFormatter (ColoredFormatter ('%(asctime)s - %(name)s - %(levelname)s - %(message)s' ))
41-
42- # Remove any existing handlers and add our custom handler
43- if logger .hasHandlers ():
44- logger .handlers .clear ()
45-
46- logger .addHandler (console_handler )
47-
48- # # Set up logging configuration
49- # logging.basicConfig(level=logging.INFO, format='%(asctime)s - %(name)s - %(levelname)s - %(message)s')
50- # logger = logging.getLogger(__name__)
51-
5234
5335# Set up logging configuration
5436def setup_logging (log_path = 'mlc' ,log_file = 'mlc-log.txt' ):
5537
56- logFormatter = logging .Formatter ('%(asctime)s - %(name)s - %(levelname)s - %(message)s' )
38+ logFormatter = ColoredFormatter ('%(asctime)s - %(name)s - %(levelname)s - %(message)s' )
39+ logger .setLevel (logging .INFO )
5740
5841 # File hander for logging in file in the specified path
5942 file_handler = logging .FileHandler ("{0}/{1}" .format (log_path , log_file ))
@@ -65,10 +48,6 @@ def setup_logging(log_path = 'mlc',log_file = 'mlc-log.txt'):
6548 consoleHandler .setFormatter (logFormatter )
6649 logger .addHandler (consoleHandler )
6750
68- # Testing the log
69- # setup_logging(log_path='.',log_file='mlc-log2.txt')
70- # logger = logging.getLogger(__name__)
71- # logger.info('This is an info message')
7251
7352# Base class for CLI actions
7453class Action :
@@ -262,7 +241,8 @@ def unregister_repo(self, repo_path):
262241
263242
264243 def __init__ (self ):
265- self .logger = logging .getLogger ()
244+ setup_logging (log_path = '.' ,log_file = 'mlc-log.txt' )
245+ self .logger = logger
266246 temp_repo = os .environ .get ('MLC_REPOS' ,'' ).strip ()
267247 if temp_repo == '' :
268248 self .repos_path = os .path .expanduser ('~/MLC/repos' )
@@ -424,18 +404,26 @@ def rm(self, i):
424404 if len (res ['list' ]) == 0 :
425405 return {'return' : 1 , 'error' : f'No { target_name } found for { inp } ' }
426406 elif len (res ['list' ]) > 1 :
427- return {'return' : 1 , 'error' : f'More than 1 { action_target } found for { inp } : { res ["list" ]} ' }
428- else :
429- result = res ['list' ][0 ]
407+ print (f"More than 1 { target_name } found for { inp } :" )
408+ if not i .get ('all' ):
409+ for idx , item in enumerate (res ["list" ]):
410+ print (f"{ idx } . Path: { item .path } , Meta: { item .meta } " )
411+
412+ user_choice = input ("Would you like to proceed with all items? (yes/no): " ).strip ().lower ()
413+ if user_choice not in ['yes' , 'y' ]:
414+ return {'return' : 1 , 'error' : "Operation aborted by user." }
415+ results = res ['list' ]
416+
417+ for result in results :
430418 item_path = result .path
431419 item_meta = result .meta
432420
433421
434- if os .path .exists (item_path ):
435- shutil .rmtree (item_path )
436- logger .info (f"{ target_name } item: { item_path } has been successfully removed" )
422+ if os .path .exists (item_path ):
423+ shutil .rmtree (item_path )
424+ logger .info (f"{ target_name } item: { item_path } has been successfully removed" )
437425
438- self .index .rm (item_meta , target_name , item_path )
426+ self .index .rm (item_meta , target_name , item_path )
439427
440428 return {
441429 "return" : 0 ,
@@ -1326,7 +1314,7 @@ def main():
13261314 pull_parser .add_argument ('extra' , nargs = argparse .REMAINDER , help = 'Extra options (e.g., -v)' )
13271315
13281316 # Script and Cache-specific subcommands
1329- for action in ['run' , 'test' , 'show' , 'update' , ' list' , 'find' , 'search' , 'rm' , 'cp' , 'mv' ]:
1317+ for action in ['run' , 'test' , 'show' , 'list' , 'find' , 'search' , 'rm' , 'cp' , 'mv' ]:
13301318 action_parser = subparsers .add_parser (action , help = f'{ action } a target.' )
13311319 action_parser .add_argument ('target' , choices = ['repo' , 'script' , 'cache' ], help = 'Target type (repo, script, cache).' )
13321320 # the argument given after target and before any extra options like --tags will be stored in "details"
@@ -1359,6 +1347,9 @@ def main():
13591347 if hasattr (args , 'repo' ) and args .repo :
13601348 run_args ['repo' ] = args .repo
13611349
1350+ if hasattr (args , 'details' ) and args .details and "," in args .details and not run_args .get ("tags" ) and args .target in ["script" , "cache" ]:
1351+ run_args ['tags' ] = args .details
1352+
13621353 if args .command in ["cp" , "mv" ]:
13631354 run_args ['target' ] = args .target
13641355 if hasattr (args , 'details' ) and args .details :
@@ -1380,4 +1371,3 @@ def main():
13801371if __name__ == '__main__' :
13811372 main ()
13821373
1383- #__version__ = "0.0.1"
0 commit comments