Compare commits
No commits in common. "a8a1f425ccc0e9def00b98089373ff90a86deb79" and "d1fe9d55d5096b99d05c01813587ae9d40910844" have entirely different histories.
a8a1f425cc
...
d1fe9d55d5
@ -3,7 +3,8 @@ import sys
|
|||||||
from typing import Optional
|
from typing import Optional
|
||||||
import json
|
import json
|
||||||
|
|
||||||
from .static import colors, get_compiled_config_file
|
from .responses import COMPILED_CONFIG_FILE
|
||||||
|
from .static import colors
|
||||||
|
|
||||||
|
|
||||||
def get_response_from_situation(situation: str, colorize: Optional[bool] = None):
|
def get_response_from_situation(situation: str, colorize: Optional[bool] = None):
|
||||||
@ -11,7 +12,7 @@ def get_response_from_situation(situation: str, colorize: Optional[bool] = None)
|
|||||||
colorize = sys.stdout.isatty()
|
colorize = sys.stdout.isatty()
|
||||||
|
|
||||||
# get message
|
# get message
|
||||||
config = json.loads(get_compiled_config_file().read_text())
|
config = json.loads(COMPILED_CONFIG_FILE.read_text())
|
||||||
existing_moods = list(config["moods"].keys())
|
existing_moods = list(config["moods"].keys())
|
||||||
template_options = config["moods"][random.choice(existing_moods)][situation]
|
template_options = config["moods"][random.choice(existing_moods)][situation]
|
||||||
template: str = random.choice(template_options)
|
template: str = random.choice(template_options)
|
||||||
|
@ -3,14 +3,14 @@ from pathlib import Path
|
|||||||
import stat
|
import stat
|
||||||
import subprocess
|
import subprocess
|
||||||
import logging
|
import logging
|
||||||
import json
|
|
||||||
|
import toml
|
||||||
|
|
||||||
from . import get_response
|
from . import get_response
|
||||||
from .responses import compile_config
|
from .responses import compile_config
|
||||||
from .static import IS_VENV, VENV_DIRECTORY, CONFIG_DIRECTORY, COMPILED_CONFIG_FILE_NAME
|
|
||||||
|
|
||||||
logging.basicConfig(
|
logging.basicConfig(
|
||||||
format='%(message)s',
|
format=' %(message)s',
|
||||||
force=True,
|
force=True,
|
||||||
)
|
)
|
||||||
|
|
||||||
@ -82,13 +82,6 @@ PIP_HOOK = """# GENERATED BY MOMMY
|
|||||||
sys.exit(code)"""
|
sys.exit(code)"""
|
||||||
|
|
||||||
|
|
||||||
def assert_venv():
|
|
||||||
if not IS_VENV:
|
|
||||||
mommy_logger.error("mommy doesn't run in a virtual environment~")
|
|
||||||
serious_logger.error("this has to run in a virtual environment")
|
|
||||||
exit(1)
|
|
||||||
|
|
||||||
|
|
||||||
def wrap_interpreter(path: Path):
|
def wrap_interpreter(path: Path):
|
||||||
mommy_logger.info("mommy found a symlink to an interpreter~ %s", str(path))
|
mommy_logger.info("mommy found a symlink to an interpreter~ %s", str(path))
|
||||||
serious_logger.info("interpreter symlink found at %s", str(path))
|
serious_logger.info("interpreter symlink found at %s", str(path))
|
||||||
@ -137,23 +130,13 @@ def install_pip_hook(path: Path):
|
|||||||
|
|
||||||
|
|
||||||
def mommify_venv():
|
def mommify_venv():
|
||||||
assert_venv()
|
compile_config()
|
||||||
|
|
||||||
compile_local = False
|
v = ".venv"
|
||||||
compiled_base_dir = VENV_DIRECTORY if compile_local else CONFIG_DIRECTORY
|
if len(sys.argv) > 1:
|
||||||
compiled_config_file = compiled_base_dir / COMPILED_CONFIG_FILE_NAME
|
v = sys.argv[1]
|
||||||
|
|
||||||
compiled = compile_config()
|
bin_path = Path(v, "bin")
|
||||||
mommy_logger.info("mommy writes its moods in %s", compiled_config_file)
|
|
||||||
serious_logger.info("writing compiled config file to %s", compiled_config_file)
|
|
||||||
compiled_base_dir.mkdir(parents=True, exist_ok=True)
|
|
||||||
with compiled_config_file.open("w") as f:
|
|
||||||
json.dump(compiled, f, indent=4)
|
|
||||||
|
|
||||||
serious_logger.info("")
|
|
||||||
mommy_logger.info("")
|
|
||||||
|
|
||||||
bin_path = VENV_DIRECTORY / "bin"
|
|
||||||
bin_path = bin_path.resolve()
|
bin_path = bin_path.resolve()
|
||||||
|
|
||||||
mommy_logger.info("mommy looks in %s to mess your system up~ <33", str(bin_path))
|
mommy_logger.info("mommy looks in %s to mess your system up~ <33", str(bin_path))
|
||||||
@ -165,10 +148,10 @@ def mommify_venv():
|
|||||||
if path.is_symlink():
|
if path.is_symlink():
|
||||||
# could be python interpreter
|
# could be python interpreter
|
||||||
# check for both just to be more expressive
|
# check for both just to be more expressive
|
||||||
if name.startswith("inner_"):
|
if name.startswith("inner_") or not name.startswith("python"):
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if subprocess.run([str(path), '-c', '"exit(0)"']).returncode != 0:
|
if subprocess.run([str(path), '-c', '"exit()"']) != 0:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
wrap_interpreter(path)
|
wrap_interpreter(path)
|
||||||
@ -179,3 +162,6 @@ def mommify_venv():
|
|||||||
continue
|
continue
|
||||||
|
|
||||||
install_pip_hook(path)
|
install_pip_hook(path)
|
||||||
|
|
||||||
|
serious_logger.info("")
|
||||||
|
mommy_logger.info("")
|
||||||
|
@ -9,9 +9,8 @@ import requests
|
|||||||
|
|
||||||
from .static import get_config_file
|
from .static import get_config_file
|
||||||
|
|
||||||
mommy_logger = logging.getLogger("mommy")
|
|
||||||
serious_logger = logging.getLogger("serious")
|
|
||||||
|
|
||||||
|
logger = logging.Logger(__name__)
|
||||||
PREFIX = "MOMMY"
|
PREFIX = "MOMMY"
|
||||||
|
|
||||||
RESPONSES_URL = "https://raw.githubusercontent.com/diamondburned/go-mommy/refs/heads/main/responses.json"
|
RESPONSES_URL = "https://raw.githubusercontent.com/diamondburned/go-mommy/refs/heads/main/responses.json"
|
||||||
@ -69,8 +68,9 @@ def compile_config(disable_requests: bool = False) -> dict:
|
|||||||
data = json.loads(RESPONSES_FILE.read_text())
|
data = json.loads(RESPONSES_FILE.read_text())
|
||||||
|
|
||||||
if not disable_requests:
|
if not disable_requests:
|
||||||
mommy_logger.info("mommy downloads newest responses for her girl~ %s", RESPONSES_URL)
|
print("mommy downloads newest responses for her girl~")
|
||||||
serious_logger.info("downloading cargo mommy responses: %s", RESPONSES_URL)
|
print(RESPONSES_URL)
|
||||||
|
print()
|
||||||
r = requests.get(RESPONSES_URL)
|
r = requests.get(RESPONSES_URL)
|
||||||
data = r.json()
|
data = r.json()
|
||||||
|
|
||||||
@ -103,18 +103,7 @@ def compile_config(disable_requests: bool = False) -> dict:
|
|||||||
for mood in config["mood"]:
|
for mood in config["mood"]:
|
||||||
if mood not in mood_definitions:
|
if mood not in mood_definitions:
|
||||||
supported_moods_str = ", ".join(mood_definitions.keys())
|
supported_moods_str = ", ".join(mood_definitions.keys())
|
||||||
mommy_logger.error(
|
print(f"{random.choice(config['role'])} doesn't know how to feel {mood}... {random.choice(config['pronoun'])} moods are {supported_moods_str}")
|
||||||
"%s doesn't know how to feel %s... %s moods are %s",
|
|
||||||
random.choice(config['role']),
|
|
||||||
mood,
|
|
||||||
random.choice(config['pronoun']),
|
|
||||||
supported_moods_str,
|
|
||||||
)
|
|
||||||
serious_logger.error(
|
|
||||||
"mood '%s' doesn't exist. moods are %s",
|
|
||||||
mood,
|
|
||||||
supported_moods_str,
|
|
||||||
)
|
|
||||||
exit(1)
|
exit(1)
|
||||||
|
|
||||||
# compile
|
# compile
|
||||||
|
@ -4,7 +4,6 @@ from pathlib import Path
|
|||||||
import os
|
import os
|
||||||
import logging
|
import logging
|
||||||
from typing import Optional
|
from typing import Optional
|
||||||
import sys
|
|
||||||
|
|
||||||
|
|
||||||
logger = logging.Logger(__name__)
|
logger = logging.Logger(__name__)
|
||||||
@ -73,36 +72,12 @@ def _get_xdg_config_dir() -> Path:
|
|||||||
CONFIG_DIRECTORY = _get_xdg_config_dir() / "mommy"
|
CONFIG_DIRECTORY = _get_xdg_config_dir() / "mommy"
|
||||||
COMPILED_CONFIG_FILE_NAME = "compiled-mommy.json"
|
COMPILED_CONFIG_FILE_NAME = "compiled-mommy.json"
|
||||||
|
|
||||||
IS_VENV = sys.prefix != sys.base_prefix
|
|
||||||
VENV_DIRECTORY = Path(sys.prefix)
|
|
||||||
|
|
||||||
def get_config_file() -> Optional[Path]:
|
def get_config_file() -> Optional[Path]:
|
||||||
config_files = []
|
config_files = [
|
||||||
if IS_VENV:
|
|
||||||
config_files.extend([
|
|
||||||
VENV_DIRECTORY / "python-mommy.toml",
|
|
||||||
VENV_DIRECTORY / "mommy.toml",
|
|
||||||
])
|
|
||||||
config_files.extend([
|
|
||||||
CONFIG_DIRECTORY / "python-mommy.toml",
|
CONFIG_DIRECTORY / "python-mommy.toml",
|
||||||
CONFIG_DIRECTORY / "mommy.toml",
|
CONFIG_DIRECTORY / "mommy.toml",
|
||||||
])
|
]
|
||||||
|
|
||||||
for f in config_files:
|
for f in config_files:
|
||||||
if f.exists():
|
if f.exists():
|
||||||
return f
|
return f
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def get_compiled_config_file() -> Path:
|
|
||||||
compiled_config_files = [
|
|
||||||
VENV_DIRECTORY / "compiled-mommy.json",
|
|
||||||
CONFIG_DIRECTORY / "compiled-mommy.json",
|
|
||||||
]
|
|
||||||
|
|
||||||
for f in compiled_config_files:
|
|
||||||
if f.exists():
|
|
||||||
return f
|
|
||||||
|
|
||||||
raise Exception("couldn't find compiled config file")
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user