-
Notifications
You must be signed in to change notification settings - Fork 529
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
Updated next_partname generation #646
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -10,3 +10,4 @@ _scratch/ | |
/spec/gen_spec/spec*.db | ||
tags | ||
/tests/debug.py | ||
venv | ||
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -7,6 +7,9 @@ | |
|
||
from __future__ import absolute_import | ||
|
||
import os | ||
from collections import defaultdict | ||
|
||
from pptx.util import lazyproperty | ||
|
||
from .constants import RELATIONSHIP_TYPE as RT | ||
|
@@ -26,6 +29,7 @@ class OpcPackage(object): | |
|
||
def __init__(self): | ||
super(OpcPackage, self).__init__() | ||
self.partnames = defaultdict(int) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid adding instance variables to the interface of the class (in other words, make instance variables private. If you need the value outside the class, make a property for it). So this would be |
||
|
||
def after_unmarshal(self): | ||
""" | ||
|
@@ -104,17 +108,15 @@ def main_document_part(self): | |
|
||
def next_partname(self, tmpl): | ||
""" | ||
Return a |PackURI| instance representing the next available partname | ||
Return a |PackURI| instance representing the next partname | ||
matching *tmpl*, which is a printf (%)-style template string | ||
containing a single replacement item, a '%d' to be used to insert the | ||
integer portion of the partname. Example: '/ppt/slides/slide%d.xml' | ||
""" | ||
partnames = [part.partname for part in self.iter_parts()] | ||
for n in range(1, len(partnames) + 2): | ||
candidate_partname = tmpl % n | ||
if candidate_partname not in partnames: | ||
return PackURI(candidate_partname) | ||
raise Exception("ProgrammingError: ran out of candidate_partnames") | ||
name = tmpl.split(os.sep)[2] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This seems unreliable. Are you sure you can count on the name always being the third item? Better to figure it is the last item, like |
||
self.partnames[name] += 1 | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I'm not seeing where |
||
candidate_partname = tmpl % self.partnames[name] | ||
return PackURI(candidate_partname) | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Where are the tests? You would have found most of these problems with good tests. |
||
@classmethod | ||
def open(cls, pkg_file): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A git-ignore particular to your personal development environment belongs in your own gitignore file, not the project's. You find that somewhere like
~/.config/git/ignore
or perhaps~/.gitconfig
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for that, will check it and update.