Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed issue with undefined functions when adding local files #22

Merged
merged 1 commit into from
Oct 5, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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)
)