Commit fc37f711 authored by Sanjay Yadav's avatar Sanjay Yadav

ENH: Added a register function to extend command list.

parent b99af677
Pipeline #32590 passed with stage
in 1 minute and 10 seconds
......@@ -101,6 +101,21 @@ def replicate_slides(data, prs, change, slide, slides_to_remove, index):
copy_slide = None
def register(config):
"""Function to register a new `command` to command list."""
global COMMANDS_LIST
if 'register' in config:
resister_command = config.pop('register')
if not isinstance(resister_command, (dict,)):
raise NotImplementedError()
for command_name, command_function in resister_command.items():
if command_name not in COMMANDS_LIST:
if not isinstance(command_function, (dict,)):
command_function = {'function': command_function}
_vars = {'shape': None, 'spec': None, 'data': None}
COMMANDS_LIST[command_name] = build_transform(command_function, vars=_vars)
def pptgen(source, target, **config):
'''
Process a configuration. This loads a Presentation from source, applies the
......@@ -108,8 +123,6 @@ def pptgen(source, target, **config):
'''
# Config was being over written using PPTXHandler and data key was being
# removed from yaml config.
global COMMANDS_LIST
handler = config.pop('handler') if 'handler' in config else None
_config = copy.deepcopy(config)
if _config.get('is_formhandler', False):
......@@ -117,17 +130,6 @@ def pptgen(source, target, **config):
_config.pop('is_formhandler')
else:
data = AttrDict(load_data(_config.pop('data', {}), handler=handler))
if 'register' in _config:
resister_command = _config.pop('register')
if not(isinstance(resister_command), (dict),):
raise NotImplementedError()
for command_name, command_function in resister_command.items():
if command_name not in COMMANDS_LIST:
if not isinstance(command_function, (dict,)):
command_function = {'function': command_function}
COMMANDS_LIST[command_name] = build_transform(command_function)[0]
prs = Presentation(source)
slides = prs.slides
# Loop through each change configuration
......@@ -136,6 +138,7 @@ def pptgen(source, target, **config):
for key, change in _config.items():
# Apply it to every slide
register(change)
slide_data = copy.deepcopy(data)
slide_data['handler'] = handler
if 'data' in change and change['data'] is not None:
......@@ -236,6 +239,5 @@ def change_shapes(collection, change, data, **kwargs):
for cmd, method in COMMANDS_LIST.items():
if cmd in spec:
method(shape, spec, shape_data)
commands.copy_slide_elem(shape, dest)
commands.add_new_slide(dest, source_slide)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment