File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1515import asyncio
1616import json
1717import logging
18- import zipfile
1918import os
20- import yaml
21- from pathlib import Path
2219
2320from . import model , tag
2421from .status import derive_status
2724from .errors import JujuError
2825from .bundle import get_charm_series
2926from .placement import parse as parse_placement
27+ from .charm import get_local_charm_metadata
3028
3129log = logging .getLogger (__name__ )
3230
@@ -719,16 +717,9 @@ async def local_refresh(
719717 default_series = model_config .get ("default-series" )
720718 if default_series :
721719 series = default_series .value
722-
723720 charm_url = await self .model .add_local_charm_dir (charm_dir , series )
721+ metadata = get_local_charm_metadata (path )
724722 if resources is not None :
725- if str (path ).endswith ('.charm' ):
726- with zipfile .ZipFile (path , 'r' ) as charm_file :
727- metadata = yaml .load (charm_file .read ('metadata.yaml' ), Loader = yaml .FullLoader )
728- else :
729- entity_path = Path (path )
730- metadata_path = entity_path / 'metadata.yaml'
731- metadata = yaml .load (metadata_path .read_text (), Loader = yaml .FullLoader )
732723 resources = await self .model .add_local_resources (self .entity_id ,
733724 charm_url ,
734725 metadata ,
Original file line number Diff line number Diff line change 1313# limitations under the License.
1414
1515import logging
16-
16+ import zipfile
17+ import yaml
18+ from pathlib import Path
1719from . import model
1820
1921log = logging .getLogger (__name__ )
2022
2123
24+ def get_local_charm_metadata (path ):
25+ """Retrieve Metadata of a Charm from its path
26+
27+ :patam str path: Path of charm directory or .charm file
28+
29+ :return: Object of charm metadata
30+ """
31+ if str (path ).endswith ('.charm' ):
32+ with zipfile .ZipFile (path , 'r' ) as charm_file :
33+ metadata = yaml .load (charm_file .read ('metadata.yaml' ), Loader = yaml .FullLoader )
34+ else :
35+ entity_path = Path (path )
36+ metadata_path = entity_path / 'metadata.yaml'
37+ metadata = yaml .load (metadata_path .read_text (), Loader = yaml .FullLoader )
38+
39+ return metadata
40+
41+
2242class Charm (model .ModelEntity ):
2343 pass
You can’t perform that action at this time.
0 commit comments