Compare commits

..

No commits in common. "a54e64242b2d24c0b0f969d85271c9ccd0f88d56" and "e90055e3bd181961a2609435e2afd044bf6172f6" have entirely different histories.

3 changed files with 18 additions and 44 deletions

View file

@ -1,4 +1,4 @@
__version__ = "0.2.5-7" __version__ = "0.2.5-6"
__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}" or var == "${sysname}": elif var == "${uname}" | "${sysname}":
return platform.system().lower() return platform.system().lower()
elif var == "${arch}": elif var == "${arch}":
return platform.machine() return platform.machine()

View file

@ -19,12 +19,7 @@ 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 = ( cache_dir = global_config.get("cram", {}).get("task", {}).get("default", {}).get("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
@ -43,9 +38,7 @@ 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( return (self.root / self.SPECIAL_FILES[0]).exists() and self.config().get("cram", {}).get("version") == 1
"cram", {}
).get("version") == 1
def requires(self): def requires(self):
"""Get the dependencies of this package.""" """Get the dependencies of this package."""
@ -56,15 +49,11 @@ class PackageV1(Package):
elif isinstance(it, dict): elif isinstance(it, dict):
return it["name"] return it["name"]
return [_name(it) for it in self.config().get("package", {}).get("require", [])] return [
_name(it) for it in self.config().get("package", {}).get("require", [])
]
def do_sh_or_script( def do_sh_or_script(self, content: Optional[Union[List[str], str]], fs: Vfs, dest: Path, cwd: Path = "/tmp"):
self,
content: Optional[Union[List[str], str]],
fs: Vfs,
dest: Path,
cwd: Path = "/tmp",
):
if content is None: if content is None:
pass pass
@ -77,7 +66,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):
@ -104,24 +93,19 @@ 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.do_sh_or_script(self.config().get("package", {}).get("pre_install"), fs, dest)
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( if not self.do_sh_or_script(self.config().get("package", {}).get("install"), fs, dest):
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.do_sh_or_script(self.config().get("package", {}).get("post_install"), fs, dest)
self.config().get("package", {}).get("post_install"), fs, dest
)
def json(self): def json(self):
return self.config() return self.config()
@ -140,24 +124,16 @@ class LightPackageV1(PackageV1):
return self._config return self._config
def test(self): def test(self):
return ( return self.root.exists() \
self.root.exists() and self.root.is_file() \
and self.root.is_file() and self.root.name.endswith(".toml") \
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 = [ _LEGACY_SPECIAL_FILES = ["BUILD", "PRE_INSTALL", "INSTALL", "POST_INSTALL", "REQUIRES"]
"BUILD",
"PRE_INSTALL",
"INSTALL",
"POST_INSTALL",
"REQUIRES",
]
SPECIAL_FILES = [] SPECIAL_FILES = []
_config = None _config = None
@ -165,9 +141,7 @@ class ProfileV1(PackageV1):
return {} return {}
def test(self): def test(self):
return self.root.is_dir() and not any( return self.root.is_dir() and not any((self.root / f).exists() for f in self._LEGACY_SPECIAL_FILES)
(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