44import hashlib
55import json
66import logging
7- import pathlib
7+ from pathlib import Path
88
99from . import model , tag , utils , jasyncio
1010from .url import URL
1111from .status import derive_status
1212from .annotationhelper import _get_annotations , _set_annotations
1313from .client import client
1414from .errors import JujuError , JujuApplicationConfigError
15- from .bundle import get_charm_series
15+ from .bundle import get_charm_series , is_local_charm
1616from .placement import parse as parse_placement
1717from .origin import Channel , Source
1818
@@ -661,6 +661,8 @@ async def refresh(
661661 :param str switch: Crossgrade charm url
662662
663663 """
664+ if switch is not None and path is not None :
665+ raise ValueError ("switch and path are mutually exclusive" )
664666
665667 if switch is not None and revision is not None :
666668 raise ValueError ("switch and revision are mutually exclusive" )
@@ -677,17 +679,18 @@ async def refresh(
677679 if charm_url_origin_result .error is not None :
678680 err = charm_url_origin_result .error
679681 raise JujuError (f'{ err .code } : { err .message } ' )
680- charm_url = switch or charm_url_origin_result .url
681682 origin = charm_url_origin_result .charm_origin
682683
683- if path is not None :
684+ if path is not None or ( switch is not None and is_local_charm ( switch )) :
684685 await self .local_refresh (origin , force , force_series ,
685- force_units , path , resources )
686+ force_units , path or switch , resources )
686687 return
687688
688689 if resources is not None :
689690 raise NotImplementedError ("resources option is not implemented" )
690691
692+ # If switch is not None at this point, that means it's a switch to a store charm
693+ charm_url = switch or charm_url_origin_result .url
691694 parsed_url = URL .parse (charm_url )
692695 charm_name = parsed_url .name
693696
@@ -733,8 +736,6 @@ async def refresh(
733736 err = charm_origin_result .error
734737 raise JujuError (f'{ err .code } : { err .message } ' )
735738
736- # Now take care of the resources:
737-
738739 # Already prepped the charm_resources
739740 # Now get the existing resources from the ResourcesFacade
740741 request_data = [client .Entity (self .tag )]
@@ -808,22 +809,22 @@ async def local_refresh(
808809 path = None , resources = None ):
809810 """Refresh the charm for this application with a local charm.
810811
811- :param str channel: Channel to use when getting the charm from the
812- charm store, e.g. 'development'
812+ :param dict charm_origin: The charm origin of the destination charm
813+ we're refreshing to
814+ :param bool force: Refresh even if validation checks fail
813815 :param bool force_series: Refresh even if series of deployed
814816 application is not supported by the new charm
815817 :param bool force_units: Refresh all units immediately, even if in
816818 error state
817819 :param str path: Refresh to a charm located at path
818820 :param dict resources: Dictionary of resource name/filepath pairs
819- :param int revision: Explicit refresh revision
820- :param str switch: Crossgrade charm url
821821
822822 """
823823 app_facade = self ._facade ()
824824
825- if not isinstance (path , pathlib .Path ):
826- path = pathlib .Path (path )
825+ if isinstance (path , str ) and path .startswith ("local:" ):
826+ path = path [6 :]
827+ path = Path (path )
827828 charm_dir = path .expanduser ().resolve ()
828829 model_config = await self .get_config ()
829830
0 commit comments