forked from canonical/jhack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhelpers.py
More file actions
30 lines (24 loc) · 740 Bytes
/
helpers.py
File metadata and controls
30 lines (24 loc) · 740 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
import contextlib
import os
from pathlib import Path
from juju.model import Model
@contextlib.asynccontextmanager
async def get_current_model() -> Model:
model = Model()
try:
# connect to the current model with the current user, per the Juju CLI
await model.connect()
yield model
finally:
if model.is_connected():
print('Disconnecting from model')
await model.disconnect()
def get_local_charm() -> Path:
is_charm = lambda file: file.suffix == '.charm'
cwd = Path(os.getcwd())
try:
return next(filter(is_charm, cwd.iterdir()))
except StopIteration:
raise FileNotFoundError(
f'could not find a charm file in {cwd}'
)