Skip to content

Commit

Permalink
Merge pull request #22 from cfengine/local_module
Browse files Browse the repository at this point in the history
Fixed issue with undefined functions when adding local files
  • Loading branch information
olehermanse authored Oct 5, 2021
2 parents e100d74 + d110912 commit d067b2a
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 44 deletions.
43 changes: 0 additions & 43 deletions cfbs/commands.py
Original file line number Diff line number Diff line change
Expand Up @@ -161,49 +161,6 @@ def local_module_name(module_path):
return module


def local_module_data_cf_file(module):
target = os.path.basename(module)
return {
"description": "Local policy file added using cfbs command line",
"tags": ["local"],
"dependencies": ["autorun"],
"steps": [f"copy {module} services/autorun/{target}"],
"added_by": "cfbs add",
}


def local_module_data_json_file(module):
return {
"description": "Local augments file added using cfbs command line",
"tags": ["local"],
"steps": [f"json {module} def.json"],
"added_by": "cfbs add",
}


def local_module_data_subdir(module):
return {
"description": "Local subdirectory added using cfbs command line",
"tags": ["local"],
"dependencies": ["autorun"],
"steps": [f"copy {module} services/autorun/"],
"added_by": "cfbs add",
}


def local_module_data(module):
assert module.startswith("./")
assert module.endswith((".cf", ".json", "/"))
assert os.path.isfile(module) or os.path.isdir(module)

if os.path.isdir(module):
return local_module_data_subdir(module)
if module.endswith(".cf"):
return local_module_data_cf_file(module)
if module.endswith(".json"):
return local_module_data_json_file(module)


def prettify_name(name):
if "/" not in name:
return name
Expand Down
43 changes: 42 additions & 1 deletion cfbs/index.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,47 @@

from cfbs.pretty import pretty_file, pretty

def _local_module_data_cf_file(module):
target = os.path.basename(module)
return {
"description": "Local policy file added using cfbs command line",
"tags": ["local"],
"dependencies": ["autorun"],
"steps": [f"copy {module} services/autorun/{target}"],
"added_by": "cfbs add",
}


def _local_module_data_json_file(module):
return {
"description": "Local augments file added using cfbs command line",
"tags": ["local"],
"steps": [f"json {module} def.json"],
"added_by": "cfbs add",
}


def _local_module_data_subdir(module):
return {
"description": "Local subdirectory added using cfbs command line",
"tags": ["local"],
"dependencies": ["autorun"],
"steps": [f"copy {module} services/autorun/"],
"added_by": "cfbs add",
}


def generate_index_for_local_module(module):
assert module.startswith("./")
assert module.endswith((".cf", ".json", "/"))
assert os.path.isfile(module) or os.path.isdir(module)

if os.path.isdir(module):
return _local_module_data_subdir(module)
if module.endswith(".cf"):
return _local_module_data_cf_file(module)
if module.endswith(".json"):
return _local_module_data_json_file(module)

class Index:
def __init__(self, path):
Expand Down Expand Up @@ -73,5 +114,5 @@ def get_build_step(self, module):
return (
self.get_modules()[module]
if not module.startswith("./")
else local_module_data(module)
else generate_index_for_local_module(module)
)

0 comments on commit d067b2a

Please sign in to comment.