Skip to content

Instantly share code, notes, and snippets.

@freedomfury
Created September 15, 2025 13:16
Show Gist options
  • Select an option

  • Save freedomfury/adc5dbe3f3d49e16be4555b46a941ca1 to your computer and use it in GitHub Desktop.

Select an option

Save freedomfury/adc5dbe3f3d49e16be4555b46a941ca1 to your computer and use it in GitHub Desktop.
=====./__init__.py====
import os
import sys
import importlib
from invoke import Collection
ns = Collection()
mod_list = []
path = os.path.dirname(os.path.realpath(__file__))
bin = f"{os.path.dirname(path)}/bin"
ns.configure(dict(bin=bin))
for root, dirs, files in os.walk(path):
base = root.replace(path + "/", "")
if root == path or "/" in base:
continue
for file in files:
if not file.endswith(".py"):
print(f"Warning: skipped: '{file}'.", file=sys.stderr)
prefix = os.path.basename(root)
package = os.path.splitext(file)[0]
basename = os.path.basename(root)
module = f"{basename}.{package}"
label = f"{basename}/{package}"
try:
imported = importlib.import_module(module)
except ModuleNotFoundError:
print(f"Warning: failed to loadfile: '{file}'.", file=sys.stderr)
else:
ns.add_collection(imported, label)
=====./invoke.yaml====
---
run:
echo: true
echo_format: "$ \e[1;93m{command}\e[0m"=====./tools/lxc.py====
import json
from json import JSONDecodeError
from invoke import task, Exit
from pprint import pprint
def lxc_json(c, command, **kwargs):
lxc_path = f"{c.bin}/go/lxc"
response = c.run(f"{lxc_path} -f json {command}", **kwargs)
try:
json_results = json.loads(response.stdout)
except JSONDecodeError:
raise Exit("Unable to parse json results from lxc.")
return json_results
@task
def setup(c):
json_results = lxc_json(c, 'remote list', hide=True)
if "lxc" not in json_results:
lxc_cmd = "remote add lxc unix:///var/snap/lxd/common/lxd/unix.socket"
c.run(f"{c.bin}/go/lxc {lxc_cmd}")
c.run(f"{c.bin}/go/lxc remote switch lxc")
print("Added remote with default snap socket...")
c.run(f"{c.bin}/go/lxc remote get-default")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment