Compare commits

...

3 commits

3 changed files with 44 additions and 18 deletions

View file

@ -1,4 +1,4 @@
__version__ = "0.2.5-6" __version__ = "0.2.5-7"
__author__ = "Reid D. 'arrdem' McKenzie <me@arrdem.com>" __author__ = "Reid D. 'arrdem' McKenzie <me@arrdem.com>"
__copyright__ = "Copyright 2020" __copyright__ = "Copyright 2020"
__license__ = "https://anticapitalist.software/" __license__ = "https://anticapitalist.software/"

View file

@ -102,7 +102,7 @@ def expandvars(s: str) -> str:
return os.uname()[1] return os.uname()[1]
elif var == "${home}": elif var == "${home}":
return os.path.expanduser("~") return os.path.expanduser("~")
elif var == "${uname}" | "${sysname}": elif var == "${uname}" or var == "${sysname}":
return platform.system().lower() return platform.system().lower()
elif var == "${arch}": elif var == "${arch}":
return platform.machine() return platform.machine()

View file

@ -19,7 +19,12 @@ def tempf(global_config, name):
root = Path(global_config["cram"]["root"]) root = Path(global_config["cram"]["root"])
assert root.exists() and root.is_dir() assert root.exists() and root.is_dir()
cache_dir = global_config.get("cram", {}).get("task", {}).get("default", {}).get("cache_dir") cache_dir = (
global_config.get("cram", {})
.get("task", {})
.get("default", {})
.get("cache_dir")
)
cache_root = cache_dir and Path(expandvars(cache_dir)) or root / ".cache" cache_root = cache_dir and Path(expandvars(cache_dir)) or root / ".cache"
return cache_root / name[0:2] / name return cache_root / name[0:2] / name
@ -38,7 +43,9 @@ class PackageV1(Package):
return self._config return self._config
def test(self): def test(self):
return (self.root / self.SPECIAL_FILES[0]).exists() and self.config().get("cram", {}).get("version") == 1 return (self.root / self.SPECIAL_FILES[0]).exists() and self.config().get(
"cram", {}
).get("version") == 1
def requires(self): def requires(self):
"""Get the dependencies of this package.""" """Get the dependencies of this package."""
@ -49,11 +56,15 @@ class PackageV1(Package):
elif isinstance(it, dict): elif isinstance(it, dict):
return it["name"] return it["name"]
return [ return [_name(it) for it in self.config().get("package", {}).get("require", [])]
_name(it) for it in self.config().get("package", {}).get("require", [])
]
def do_sh_or_script(self, content: Optional[Union[List[str], str]], fs: Vfs, dest: Path, cwd: Path = "/tmp"): def do_sh_or_script(
self,
content: Optional[Union[List[str], str]],
fs: Vfs,
dest: Path,
cwd: Path = "/tmp",
):
if content is None: if content is None:
pass pass
@ -66,7 +77,7 @@ class PackageV1(Package):
content["run"], content["run"],
fs, fs,
dest, dest,
{"cwd": self.root}.get(content.get("root"), "/tmp") {"cwd": self.root}.get(content.get("root"), "/tmp"),
) )
elif isinstance(content, str): elif isinstance(content, str):
@ -93,19 +104,24 @@ class PackageV1(Package):
with open(installf, "r") as fp: with open(installf, "r") as fp:
self.do_sh_or_script(fp.read(), fs, dest) self.do_sh_or_script(fp.read(), fs, dest)
def do_build(self, fs: Vfs, dest: Path): def do_build(self, fs: Vfs, dest: Path):
self.do_sh_or_script(self.config().get("package", {}).get("build"), fs, dest) self.do_sh_or_script(self.config().get("package", {}).get("build"), fs, dest)
def pre_install(self, fs: Vfs, dest: Path): def pre_install(self, fs: Vfs, dest: Path):
self.do_sh_or_script(self.config().get("package", {}).get("pre_install"), fs, dest) self.do_sh_or_script(
self.config().get("package", {}).get("pre_install"), fs, dest
)
def do_install(self, fs: Vfs, dest: Path): def do_install(self, fs: Vfs, dest: Path):
if not self.do_sh_or_script(self.config().get("package", {}).get("install"), fs, dest): if not self.do_sh_or_script(
self.config().get("package", {}).get("install"), fs, dest
):
stow(fs, self.root, dest, self.SPECIAL_FILES) stow(fs, self.root, dest, self.SPECIAL_FILES)
def post_install(self, fs: Vfs, dest: Path): def post_install(self, fs: Vfs, dest: Path):
self.do_sh_or_script(self.config().get("package", {}).get("post_install"), fs, dest) self.do_sh_or_script(
self.config().get("package", {}).get("post_install"), fs, dest
)
def json(self): def json(self):
return self.config() return self.config()
@ -124,16 +140,24 @@ class LightPackageV1(PackageV1):
return self._config return self._config
def test(self): def test(self):
return self.root.exists() \ return (
and self.root.is_file() \ self.root.exists()
and self.root.name.endswith(".toml") \ and self.root.is_file()
and self.root.name.endswith(".toml")
and self.config().get("cram", {}).get("version") == 1 and self.config().get("cram", {}).get("version") == 1
)
class ProfileV1(PackageV1): class ProfileV1(PackageV1):
"""Unline packages, profiles don't support recursive stow of contents.""" """Unline packages, profiles don't support recursive stow of contents."""
_LEGACY_SPECIAL_FILES = ["BUILD", "PRE_INSTALL", "INSTALL", "POST_INSTALL", "REQUIRES"] _LEGACY_SPECIAL_FILES = [
"BUILD",
"PRE_INSTALL",
"INSTALL",
"POST_INSTALL",
"REQUIRES",
]
SPECIAL_FILES = [] SPECIAL_FILES = []
_config = None _config = None
@ -141,7 +165,9 @@ class ProfileV1(PackageV1):
return {} return {}
def test(self): def test(self):
return self.root.is_dir() and not any((self.root / f).exists() for f in self._LEGACY_SPECIAL_FILES) return self.root.is_dir() and not any(
(self.root / f).exists() for f in self._LEGACY_SPECIAL_FILES
)
def do_install(self, fs: Vfs, dest: Path): def do_install(self, fs: Vfs, dest: Path):
return return