@@ -1697,14 +1697,25 @@ def list_source():
16971697 return sources_from_file ()
16981698
16991699
1700- def update_plugin (plugin_name : str ) -> Union [str , None ]:
1700+ class UpdateStatus (Enum ):
1701+ SUCCESS = 0
1702+ LATEST = 1
1703+ UNINSTALLED = 2
1704+ ERROR = 3
1705+ METADATA_MISSING = 4
1706+
1707+
1708+ def update_plugin (plugin_name : str ) -> tuple :
17011709 """Check for an installed plugin, if metadata for it exists, update
17021710 to the latest available while using the same source."""
17031711 log .info (f"updating { plugin_name } " )
1712+ if not (Path (RECKLESS_CONFIG .reckless_dir ) / plugin_name ).exists ():
1713+ log .error (f'{ plugin_name } is not installed' )
1714+ return (None , UpdateStatus .UNINSTALLED )
17041715 metadata_file = Path (RECKLESS_CONFIG .reckless_dir ) / plugin_name / '.metadata'
17051716 if not metadata_file .exists ():
17061717 log .warning (f"no metadata file for { plugin_name } " )
1707- return None
1718+ return ( None , UpdateStatus . METADATA_MISSING )
17081719
17091720 metadata = {'installation date' : None ,
17101721 'installation time' : None ,
@@ -1726,29 +1737,34 @@ def update_plugin(plugin_name: str) -> Union[str, None]:
17261737 metadata ['original source' ], None )
17271738 if not src .get_inst_details ():
17281739 log .error (f'cannot locate { plugin_name } in original source { metadata ["original_source" ]} ' )
1729- return None
1740+ return ( None , UpdateStatus . ERROR )
17301741 repo_commit = src .get_repo_commit ()
17311742 if not repo_commit :
17321743 log .debug ('source commit not available' )
1744+ else :
1745+ log .debug (f'source commit: { repo_commit } ' )
17331746 if repo_commit and repo_commit == metadata ['installed commit' ]:
1734- log .debug (f'Installed { plugin_name } is already latest - { repo_commit } ' )
1735- return None
1747+ log .info (f'Installed { plugin_name } is already latest @ { repo_commit } ' )
1748+ return ( None , UpdateStatus . LATEST )
17361749 uninstall (plugin_name )
17371750 try :
17381751 installed = _install_plugin (src )
17391752 except FileExistsError as err :
17401753 log .error (f'File exists: { err .filename } ' )
1741- return None
1742- return _enable_installed (installed , plugin_name )
1754+ return (None , UpdateStatus .ERROR )
1755+ result = _enable_installed (installed , plugin_name )
1756+ if result :
1757+ return (result , UpdateStatus .SUCCESS )
1758+ return (result , UpdateStatus .ERROR )
17431759
17441760
17451761def update_plugins (plugin_name : str ):
17461762 """user requested plugin upgrade(s)"""
17471763 if plugin_name :
17481764 installed = update_plugin (plugin_name )
1749- if not installed :
1765+ if not installed [ 0 ] and installed [ 1 ] != UpdateStatus . LATEST :
17501766 log .error (f'{ plugin_name } update aborted' )
1751- return installed
1767+ return installed [ 0 ]
17521768
17531769 log .info ("updating all plugins" )
17541770 update_results = []
@@ -1757,7 +1773,7 @@ def update_plugins(plugin_name: str):
17571773 continue
17581774 if len (plugin ) > 0 and plugin [0 ] == '.' :
17591775 continue
1760- update_results .append (update_plugin (plugin ))
1776+ update_results .append (update_plugin (plugin )[ 0 ] )
17611777 return update_results
17621778
17631779
0 commit comments