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

added the ability to overide a command data (like first_key, last_key, jump and flags) #28

Merged
merged 4 commits into from
Jul 21, 2019
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
4 changes: 3 additions & 1 deletion RAMP/module_metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
MIN_REDIS_PACK_VERSION = "5.0"
RAMP_FORMAT_VERSION = 1
CONFIG_COMMAND = ""
OVERIDE_COMMAND = []

FIELDS = ["module_name", "module_file", "architecture", "version", "semantic_version",
"display_name", "author", "email", "description", "homepage", "license",
Expand Down Expand Up @@ -60,6 +61,7 @@ def create_default_metadata(module_path):
"commands": MODULE_COMMANDS,
"ramp_format_version": RAMP_FORMAT_VERSION,
"config_command": CONFIG_COMMAND,
"exclude_commands": EXCLUDE_COMMANDS
"exclude_commands": EXCLUDE_COMMANDS,
"overide_command": OVERIDE_COMMAND
}
return metadata
16 changes: 15 additions & 1 deletion RAMP/packer.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ def archive(module_path, metadata, archive_name='module.zip'):
def package(module, output, verbose, manifest, display_name, module_name, author,
email, architecture, description, homepage, license, cmdargs,
redis_min_version, redis_pack_min_version, config_command, os, os_list, capabilities,
print_filename_only, exclude_commands):
print_filename_only, exclude_commands, overide_command):
module_path = module
metadata = set_defaults(module_path)

Expand All @@ -87,13 +87,27 @@ def package(module, output, verbose, manifest, display_name, module_name, author
metadata["capabilities"] = capabilities
metadata["config_command"] = config_command
metadata["exclude_commands"] = exclude_commands
metadata["overide_command"] = overide_command

# Load module into redis and discover its commands
module = discover_modules_commands(module_path, metadata["command_line_args"])
metadata["module_name"] = module.name
metadata["version"] = module.version
metadata["semantic_version"] = str(version_to_semantic_version(module.version))
metadata["commands"] = [cmd.to_dict() for cmd in module.commands if cmd.command_name not in metadata["exclude_commands"]]

# overide requested commands data
for overide in metadata["overide_command"]:
if 'command_name' not in overide:
print("error: the given overide json does not contains command name: %s" % str(overide))
continue
overide_index = [i for i in range(len(metadata["commands"])) if metadata["commands"][i]['command_name'] == overide['command_name']]
if len(overide_index) != 1:
print("error: the given overide command appears more then once")
continue
if verbose:
print 'overiding %s with %s' % (str(metadata["commands"][overide_index[0]]), str(overide))
metadata["commands"][overide_index[0]] = overide

if module_name:
metadata["module_name"] = module_name
Expand Down
14 changes: 12 additions & 2 deletions RAMP/ramp.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,15 @@ def comma_seperated_to_list(ctx, param, value):
else:
items = value.split(',')
return list(set(items))

def jsons_str_tuple_to_jsons_tuple(ctx, param, value):
"""
Converts json str into python map
"""
if value is None:
return []
else:
return [json.loads(a) for a in value]

@click.group()
def ramp():
Expand Down Expand Up @@ -79,14 +88,15 @@ def unpack(bundle):
@click.option('--capabilities', '-C', callback=comma_seperated_to_list, help='comma seperated list of module capabilities')
@click.option('--print-filename-only', '-P', is_flag=True, help="Print package path, but don't generate file")
@click.option('--exclude-commands', '-E', callback=comma_seperated_to_list, help='comma seperated list of exclude commands')
@click.option('--overide-command', multiple=True, callback=jsons_str_tuple_to_jsons_tuple, help='gets a command json representation and overide it on the module json file')
def pack(module, output, verbose, manifest, display_name, module_name, author,
email, architecture, description, homepage, license, cmdargs,
redis_min_version, redis_pack_min_version, config_command, os, os_list, capabilities,
print_filename_only, exclude_commands):
print_filename_only, exclude_commands, overide_command):
return package(module, output, verbose, manifest, display_name, module_name, author,
email, architecture, description, homepage, license, cmdargs,
redis_min_version, redis_pack_min_version, config_command, os, os_list, capabilities,
print_filename_only, exclude_commands)
print_filename_only, exclude_commands, overide_command)

if __name__ == '__main__':
ramp()
1 change: 1 addition & 0 deletions example.manifest.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,3 +20,4 @@ capabilities:
- flash
exclude_commands:
- graph.BULK
overide_command: [{"command_name": "graph.EXPLAIN"}]
14 changes: 6 additions & 8 deletions test.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,7 @@ def validate_module_commands(commands):

# Expected commands:
expected_command = []
expected_command.append({"command_arity": -1,
"command_name": "graph.EXPLAIN",
"first_key": 1,
"flags": ["write","noscript"],
"last_key": 1,
"step": 1})
expected_command.append({"command_name": "graph.EXPLAIN"})

expected_command.append({"command_arity": -1,
"command_name": "graph.QUERY",
Expand All @@ -67,7 +62,9 @@ def validate_module_commands(commands):
def test_defaults():
"""Test auto generated metadata from module is as expected."""
runner = CliRunner()
result = runner.invoke(ramp.pack, [MODULE_FILE_PATH, '-o', BUNDLE_ZIP_FILE, '-E', 'graph.BULK'])
result = runner.invoke(ramp.pack, [MODULE_FILE_PATH, '-o', BUNDLE_ZIP_FILE,
'-E', 'graph.BULK',
'--overide-command', '{"command_name": "graph.EXPLAIN"}'])
assert result.exit_code == 0

metadata, _ = unpacker.unpack(BUNDLE_ZIP_FILE)
Expand Down Expand Up @@ -120,7 +117,8 @@ def test_bundle_from_cmd():
'-r', min_redis_version, '-R', min_redis_pack_version,
'-C', ','.join([cap['name'] for cap in MODULE_CAPABILITIES]),
'-o', BUNDLE_ZIP_FILE, '-cc', CONFIG_COMMAND, '-E', 'graph.bulk',
'-E', 'graph.BULK']
'-E', 'graph.BULK',
'--overide-command', '{"command_name": "graph.EXPLAIN"}']

runner = CliRunner()
result = runner.invoke(ramp.pack, argv)
Expand Down