@@ -1697,14 +1697,25 @@ def list_source():
1697
1697
return sources_from_file ()
1698
1698
1699
1699
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 :
1701
1709
"""Check for an installed plugin, if metadata for it exists, update
1702
1710
to the latest available while using the same source."""
1703
1711
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 )
1704
1715
metadata_file = Path (RECKLESS_CONFIG .reckless_dir ) / plugin_name / '.metadata'
1705
1716
if not metadata_file .exists ():
1706
1717
log .warning (f"no metadata file for { plugin_name } " )
1707
- return None
1718
+ return ( None , UpdateStatus . METADATA_MISSING )
1708
1719
1709
1720
metadata = {'installation date' : None ,
1710
1721
'installation time' : None ,
@@ -1726,29 +1737,34 @@ def update_plugin(plugin_name: str) -> Union[str, None]:
1726
1737
metadata ['original source' ], None )
1727
1738
if not src .get_inst_details ():
1728
1739
log .error (f'cannot locate { plugin_name } in original source { metadata ["original_source" ]} ' )
1729
- return None
1740
+ return ( None , UpdateStatus . ERROR )
1730
1741
repo_commit = src .get_repo_commit ()
1731
1742
if not repo_commit :
1732
1743
log .debug ('source commit not available' )
1744
+ else :
1745
+ log .debug (f'source commit: { repo_commit } ' )
1733
1746
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 )
1736
1749
uninstall (plugin_name )
1737
1750
try :
1738
1751
installed = _install_plugin (src )
1739
1752
except FileExistsError as err :
1740
1753
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 )
1743
1759
1744
1760
1745
1761
def update_plugins (plugin_name : str ):
1746
1762
"""user requested plugin upgrade(s)"""
1747
1763
if plugin_name :
1748
1764
installed = update_plugin (plugin_name )
1749
- if not installed :
1765
+ if not installed [ 0 ] and installed [ 1 ] != UpdateStatus . LATEST :
1750
1766
log .error (f'{ plugin_name } update aborted' )
1751
- return installed
1767
+ return installed [ 0 ]
1752
1768
1753
1769
log .info ("updating all plugins" )
1754
1770
update_results = []
@@ -1757,7 +1773,7 @@ def update_plugins(plugin_name: str):
1757
1773
continue
1758
1774
if len (plugin ) > 0 and plugin [0 ] == '.' :
1759
1775
continue
1760
- update_results .append (update_plugin (plugin ))
1776
+ update_results .append (update_plugin (plugin )[ 0 ] )
1761
1777
return update_results
1762
1778
1763
1779
0 commit comments