diff --git a/core/check.py b/core/check.py index d280071..585d3c1 100644 --- a/core/check.py +++ b/core/check.py @@ -1,9 +1,11 @@ import core.checks.executable as exe import core.checks.syntax_check as stx +import core.checks.kind as kind import core.checks.version_validity as version def check_package(pkg): exe.ExecCheck().run() stx.DescriptionCheck(pkg).run() + kind.KindCheck(pkg).run() version.VersionValidityCheck(pkg).run() diff --git a/core/checks/base.py b/core/checks/base.py index 2b3b3e1..115a1b4 100644 --- a/core/checks/base.py +++ b/core/checks/base.py @@ -76,6 +76,7 @@ def __init__(self, pkg, items): def edit(self, item): utils.open_editor(self.pkg.manifest_path) self.pkg.manifest = toml.load(self.pkg.manifest_path) + self.pkg.is_effective = self.pkg.manifest['kind'] == 'effective' def write_pkg_manifest(self): with open(self.pkg.manifest_path, 'w') as filename: diff --git a/core/checks/kind.py b/core/checks/kind.py new file mode 100644 index 0000000..42b3f3c --- /dev/null +++ b/core/checks/kind.py @@ -0,0 +1,60 @@ +import os +import core.log as log +import core.checks.base as base +import core.checks.utils as utils + + +class KindCheck(base.CheckWithManifest): + def __init__(self, pkg): + super().__init__(pkg, [None]) + + def run(self): + log.s("Checking package kind") + super().run() + + def validate(self, _): + length = len(os.listdir(self.pkg.cache)) + return (self.pkg.is_effective and length != 1) \ + or (not self.pkg.is_effective and length == 1) + + def show(self, _): + if self.pkg.is_effective: + log.e("Package is effective but is missing a data.tar.gz") + else: + log.e("Package is virtual but has a data.tar.gz") + + def diff(self, _): + target = 'virtual' if self.pkg.is_effective else 'effective' + log.i(f"Package kind would be changed to {target}") + + def fix(self, _): + target = 'virtual' if self.pkg.is_effective else 'effective' + self.pkg.manifest['kind'] = target + self.pkg.is_effective = not self.pkg.is_effective + self.write_pkg_manifest() + + def edit(self, _): + if self.pkg.is_effective: + ans = self._ask_1or2("Would you like to edit the manifest.toml (1) " + "or to add files to the package (2)? ") + if ans == 1: + super().edit(_) + elif ans == 2: + utils.open_shell(self.pkg.cache) + else: + + ans = self._ask_1or2("Would you like to edit the manifest.toml (1) " + "or to remove the files from the package? (2) ") + if ans == 1: + super().edit(_) + + @staticmethod + def _ask_1or2(question): + while True: + ans = log.q(question) + if ans == '1': + return 1 + elif ans == '2': + return 2 + else: + log.w("Only recognized answers are 1 and 2") diff --git a/core/package.py b/core/package.py index 2a91e9a..bdc642b 100644 --- a/core/package.py +++ b/core/package.py @@ -38,6 +38,8 @@ def wrap(self): self.show_manifest() if self.is_effective: self.create_data_tar() + else: + log.i("Ignoring data.tar.gz creation phase because package is virtual") self.create_nest_file() def update_manifest_toml_wrap_date(self): @@ -75,6 +77,7 @@ def create_nest_file(self): os.remove('data.tar.gz') new_path = f'{self.npf_path}.new' os.rename(os.path.join(self.cache, new_nest_file_path), new_path) + log.s(f"New NPF is located at {new_path}") def show_manifest(self): m = self.manifest