Skip to content

Commit

Permalink
Merge pull request skonfig#82 from skonfig/4nd3r/gencodes_and_typeman…
Browse files Browse the repository at this point in the history
…ifests

add gencode-*s as dir, adjust type manifest checking
  • Loading branch information
4nd3r authored Dec 10, 2024
2 parents 64c223d + 5e1da2b commit ce22998
Show file tree
Hide file tree
Showing 3 changed files with 45 additions and 16 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ Most parts of [cdist documentation](https://www.cdi.st/manual/latest/) apply, bu
* `skonfig` does only `config` (see `skonfig -h`),
* types are managed in sets,
* type manifest can be directory of manifests,
* `gencode-*` can be directory of scripts,
* some types behave differently and it's recommended to consult manuals in *base* and *extra*.

## Split between *base* and *extra*
Expand Down
41 changes: 33 additions & 8 deletions cdist/core/code.py
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,23 @@ def _run_gencode(self, cdist_object, which):
cdist_type = cdist_object.cdist_type
gencode_attr = getattr(cdist_type, 'gencode_{}_path'.format(which))
script = os.path.join(self.local.type_path, gencode_attr)
if os.path.isfile(script):
if os.path.isdir(script):
init = os.path.join(script, "init")
if os.path.isfile(init):
scripts = [init]
else:
scripts = []
for s in os.listdir(script):
s = os.path.join(script, s)
if os.path.isfile(s):
scripts.append(s)
scripts.sort()
elif os.path.isfile(script):
scripts = [script]
else:
return
code = ""
for script in scripts:
env = os.environ.copy()
env.update(self.env)
env.update({
Expand All @@ -134,14 +150,23 @@ def _run_gencode(self, cdist_object, which):
stderr_path = os.path.join(cdist_object.stderr_path,
'gencode-' + which)
with open(stderr_path, 'ba+') as stderr:
return self.local.run_script(script, env=env,
return_output=True,
message_prefix=message_prefix,
stderr=stderr)
code += self.local.run_script(
script,
env=env,
return_output=True,
message_prefix=message_prefix,
stderr=stderr)
else:
return self.local.run_script(script, env=env,
return_output=True,
message_prefix=message_prefix)
code += self.local.run_script(
script,
env=env,
return_output=True,
message_prefix=message_prefix)
# Ensure generated code has an ending newline because
# types can generate oneliners with printf without \n.
if code and not code.endswith("\n"):
code += "\n"
return code

def run_gencode_local(self, cdist_object):
"""Run the gencode-local script for the given object."""
Expand Down
19 changes: 11 additions & 8 deletions cdist/core/manifest.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,14 +200,17 @@ def env_type_manifest(self, cdist_object):
def run_type_manifest(self, cdist_object):
type_manifest = os.path.join(self.local.type_path,
cdist_object.cdist_type.manifest_path)
type_init_manifest = os.path.join(type_manifest, "init")
if os.path.isfile(type_init_manifest):
type_manifests = [type_init_manifest]
elif os.path.isdir(type_manifest):
type_manifests = []
for m in os.listdir(type_manifest):
type_manifests.append(os.path.join(type_manifest, m))
type_manifests.sort()
if os.path.isdir(type_manifest):
type_init_manifest = os.path.join(type_manifest, "init")
if os.path.isfile(type_init_manifest):
type_manifests = [type_init_manifest]
else:
type_manifests = []
for m in os.listdir(type_manifest):
m = os.path.join(type_manifest, m)
if os.path.isfile(m):
type_manifests.append(m)
type_manifests.sort()
elif os.path.isfile(type_manifest):
type_manifests = [type_manifest]
else:
Expand Down

0 comments on commit ce22998

Please sign in to comment.