Skip to content

Commit 128788b

Browse files
committed
Refactoring (finally removing the 'dest' parameter from the Pageset class).
This revealed a bug: if an image failed to be exported we'd been completely removing them from the page set when we should have been recording the filename for the purposes of the OBZ. This bug was present in the regression tests (it only appeared for the arabic pageset) and so we had to update the test targets.
1 parent d2ac98c commit 128788b

File tree

10 files changed

+33
-12
lines changed

10 files changed

+33
-12
lines changed

main.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,7 @@
1414
if (len(sys.argv) > 2):
1515
parser.gridSize = int(sys.argv[3])
1616
obf_dest='templates/data/'
17-
pageset = Pageset(filename, obf_dest, parser.gridSize) #TODO: dest shouldn't appear here
17+
pageset = Pageset(filename, parser.gridSize) #TODO: dest shouldn't appear here
1818

19-
pageset.extract_and_label_images(obf_dest) #TODO - shouldn't be here at all.
2019
parser.write_to_obz(pageset.grids, obf_dest)
2120

pagesetparser/grid.py

+6
Original file line numberDiff line numberDiff line change
@@ -194,6 +194,12 @@ def create_obf_button(self,col,row):
194194
button["label"]=button['id']
195195
return button
196196

197+
def make_imagepaths(self):
198+
images = self.create_image_grid()
199+
for (x, y) in images:
200+
self.imagepaths[x][y] = "images/" + create_icon_name(x, y, self.labels, self.links, self.slide_number)
201+
202+
197203

198204

199205
def export_images(self, dest_folder, SAVE=True):

pagesetparser/pageset.py

+4-4
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ class Pageset:
99

1010
# TODO: should throw error if filename doesn't create a useable pageset
1111

12-
def __init__(self, filename, dest, grid_size, saveimages=True): #TODO: dest needs to go, it's needed for output NOT input
12+
def __init__(self, filename, grid_size, saveimages=True): #TODO: dest needs to go, it's needed for output NOT input
1313
try:
1414
self.prs = Presentation(filename)
1515
except:
@@ -19,7 +19,7 @@ def __init__(self, filename, dest, grid_size, saveimages=True): #TODO: dest nee
1919
self.grid_size=grid_size #TODO: we might NOT need to store this internally
2020
self.feedback = []
2121
self.split_pageset_into_grids()
22-
self.extract_and_label_images(dest, False) #This has to run to get the names right. TODO Call from somewhere else
22+
self.get_image_names() #This has to run to get the names right. TODO Call from somewhere else
2323

2424
def addfeedback(self, feedelement):
2525
self.feedback.append(feedelement)
@@ -34,9 +34,9 @@ def split_pageset_into_grids(self):
3434
for grid in self.grids:
3535
grid.update_links(self.grids) # We can only run this after every other page knows their own tag.
3636

37-
def extract_and_label_images(self, dest, SAVE=True): #TODO: this should only be called from one of the proper export files.
37+
def get_image_names(self): #TODO: this should only be called from one of the proper export files.
3838
for i in range(len(self.grids)):
39-
self.grids[i].export_images(dest, SAVE)
39+
self.grids[i].make_imagepaths()
4040

4141
def to_json(self): #TODO: put in pageset and then put the inner loop in grid
4242
# Start the JSON output.

pagesetparser/pagesetparser.py

+3
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,11 @@ def get_obf_manifest(root,boards_names_dic, image_names_dic):
3838

3939

4040
def write_to_obz(grids, dest): #TODO these three files should definately be moved into pageset.py
41+
4142
owd = os.getcwd()
4243
image_names_dic = {}
4344
for grid in grids:
45+
grid.export_images(dest)
4446
grid.write_obf_file(dest)
4547
for path in grid.get_image_paths():
4648
image_names_dic[path]=path
@@ -57,4 +59,5 @@ def write_to_obz(grids, dest): #TODO these three files should definately be mov
5759
w.write(x)
5860
except FileNotFoundError: #The try-except block is here so that we always change back to the right directly if there is an error.
5961
print("Error 23024982342 on file {}".format(x))
62+
print(x)
6063
os.chdir(owd)

tests/regressions/generate_regressions.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -34,8 +34,7 @@ def generate_obz(filename,gridSize):
3434
os.makedirs(obf_dest)
3535
if not os.path.exists(obf_dest+"boards/"):
3636
os.makedirs(obf_dest+"boards/")
37-
pageset = Pageset(filename,obf_dest, gridSize)
38-
pageset.extract_and_label_images(obf_dest)
37+
pageset = Pageset(filename, gridSize)
3938
parser.write_to_obz(pageset.grids, obf_dest)
4039

4140
def generate(filename, gridSize):
Binary file not shown.

tests/regressions/regression_tests_size_5/CK20V2_ara_regession.pptx.obz.target/boards/food.obf

+8-1
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@
190190
"background_color": "rgb(250,250,250)",
191191
"border_color": "rgb(68,68,68)",
192192
"id": "44",
193-
"image_id": "",
193+
"image_id": "images/S8X4Y4\u0637\u064e\u0639\u064e\u0627\u0645\u0645\u064f\u0641\u064e\u0636\u064e\u0651\u0644.png",
194194
"label": "\u0637\u064e\u0639\u064e\u0627\u0645 \u0645\u064f\u0641\u064e\u0636\u064e\u0651\u0644"
195195
}
196196
],
@@ -377,6 +377,13 @@
377377
"id": "images/S8X3Y4\u062f\u064e\u0631\u062f\u064e\u0634\u064e\u0629\u062d\u064e\u0648\u0644\u064e\u0627\u0644\u0637\u0651\u064e\u0639\u0627\u0645.png",
378378
"path": "images/S8X3Y4\u062f\u064e\u0631\u062f\u064e\u0634\u064e\u0629\u062d\u064e\u0648\u0644\u064e\u0627\u0644\u0637\u0651\u064e\u0639\u0627\u0645.png",
379379
"width": 300
380+
},
381+
{
382+
"content_type": "image/png",
383+
"height": 300,
384+
"id": "images/S8X4Y4\u0637\u064e\u0639\u064e\u0627\u0645\u0645\u064f\u0641\u064e\u0636\u064e\u0651\u0644.png",
385+
"path": "images/S8X4Y4\u0637\u064e\u0639\u064e\u0627\u0645\u0645\u064f\u0641\u064e\u0636\u064e\u0651\u0644.png",
386+
"width": 300
380387
}
381388
],
382389
"locale": "en",

tests/regressions/regression_tests_size_5/CK20V2_ara_regession.pptx.obz.target/boards/wml.obf

+8-1
Original file line numberDiff line numberDiff line change
@@ -105,7 +105,7 @@
105105
"background_color": "rgb(250,250,250)",
106106
"border_color": "rgb(68,68,68)",
107107
"id": "13",
108-
"image_id": "",
108+
"image_id": "images/S5X1Y3\u0623\u064a\u0651\u0627\u064b\u0643\u0627\u0646.png",
109109
"label": "\u0623\u064a\u0651\u0627\u064b \u0643\u0627\u0646"
110110
},
111111
{
@@ -265,6 +265,13 @@
265265
"path": "images/S5X0Y3\u0623\u0646\u062a\u062a\u064f\u0632\u0639\u0650\u062c\u064f\u0646\u064a.png",
266266
"width": 300
267267
},
268+
{
269+
"content_type": "image/png",
270+
"height": 300,
271+
"id": "images/S5X1Y3\u0623\u064a\u0651\u0627\u064b\u0643\u0627\u0646.png",
272+
"path": "images/S5X1Y3\u0623\u064a\u0651\u0627\u064b\u0643\u0627\u0646.png",
273+
"width": 300
274+
},
268275
{
269276
"content_type": "image/png",
270277
"height": 300,

tests/regressions/regression_tests_size_5/CK20V2_ara_regession.pptx.obz.target/manifest.json

+1-1
Large diffs are not rendered by default.

tests/test_grab_text.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def get_singleton_CK20(self):
3737
if not self.CK20:
3838
# prs = Presentation("tests/CK20V2cutdown.pptx")
3939
pagesetparser.gridSize=5
40-
self.CK20 = pagesetparser.Pageset("tests/testinputs/CK20V2cutdown.pptx","",pagesetparser.gridSize, False)
40+
self.CK20 = pagesetparser.Pageset("tests/testinputs/CK20V2cutdown.pptx",pagesetparser.gridSize, False)
4141

4242
return self.CK20
4343

0 commit comments

Comments
 (0)