Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
What's new
7
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Open sidebar
Sanjay Yadav
PPT Generator
Commits
fc37f711
Commit
fc37f711
authored
Oct 31, 2017
by
Sanjay Yadav
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ENH: Added a register function to extend command list.
parent
b99af677
Pipeline
#32590
passed with stage
in 1 minute and 10 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
pptgen/__init__.py
pptgen/__init__.py
+16
-14
No files found.
pptgen/__init__.py
View file @
fc37f711
...
...
@@ -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
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment