Skip to content

Commit

Permalink
Remove deprecated code (GourmandRecipeManager#3)
Browse files Browse the repository at this point in the history
  • Loading branch information
cydanil authored Jul 11, 2021
2 parents 3f872a4 + 4949552 commit 5454781
Show file tree
Hide file tree
Showing 10 changed files with 46 additions and 281 deletions.
80 changes: 5 additions & 75 deletions src/gourmand/exporters/eatdrinkfeelgood_exporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,11 @@
# USA.

import base64
import sys
import unittest
import xml.dom
import xml.sax.saxutils

import gourmand.convert as convert
from gourmand.exporters import exporter
from gourmand.gdebug import debug
from gourmand.gglobals import NAME_TO_ATTR


Expand Down Expand Up @@ -307,75 +304,8 @@ def __init__ (self, rd, recipe_table, out, one_file=True,
}
)

def write_footer (self):
self.xmlDoc.writexml(self.ofi, newl = '\n', addindent = "\t",
encoding = "UTF-8")

class ExportTestCase (unittest.TestCase):

TEST_RECS = [
[{'title':'Foo',
'source':'Bar',
'season':'Winter'},
['1 tsp. sugar',
'2 c. wine',
'3 cloves garlic',
'4 1/2 apples'
'salt',
'pepper'],
['Eat','Cook','Try\nSome\nNew\nLines']
],
[{'title':'Screwy',
'season':'123',
'servings':'34'},
['1- baseballs',
'2-3 cups',
'3-4 wild and crazy recipes.'],
[]],
]

out_file = 'eatdrinkfeelgood_test.xml'

def setUp (self):
import tempfile

import fake_db
from cozy_interactive_importer import CozyInteractiveImporter

from gourmand.importers.interactive_importer import ConvenientImporter
self.rd = fake_db.RecData(tempfile.mktemp('.db'))
import gourmand.convert
import gourmand.nutrition.nutrition as nutrition
c = gourmand.convert.Converter()
self.rd.nd = nutrition.NutritionData(self.rd,c)

class DumbImporter (CozyInteractiveImporter):
added_to = False
def __init__ (self, rd):
ConvenientImporter.__init__(self,rd,threaded=True)
def set_added_to (self,bool):
self.added_to = bool

imp = DumbImporter(self.rd)
for attrs,ings,steps in self.TEST_RECS:
imp.start_rec()
for a,v in list(attrs.items()): imp.add_attribute(a,v)
for i in ings:
imp.add_ing_from_text(i)
for s in steps:
imp.add_text('step',s)
imp.commit_rec()


def testExport (self):
from gourmand.exporters import exporter
e=EdfgXmlM(
self.rd,
[self.rd.recipe_table[k] for k in self.rd.recipe_table],
self.out_file,
#threaded = False
)
e.run()

if __name__ == '__main__':
unittest.main()
def write_footer(self):
self.xmlDoc.writexml(self.ofi,
newl='\n',
addindent="\t",
encoding="UTF-8")
2 changes: 0 additions & 2 deletions src/gourmand/exporters/exportManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,8 +127,6 @@ def get_extra_prefs (self, myexp, extra_prefs):
extra_prefs = myexp.run_extra_prefs_dialog() or {}
elif extra_prefs == EXTRA_PREFS_DEFAULT:
extra_prefs = myexp.get_default_prefs()
else:
extra_prefs = extra_prefs
return extra_prefs

def get_multiple_exporter (self, recs, fn, exp_type=None,
Expand Down
2 changes: 1 addition & 1 deletion src/gourmand/gtk_extras/ratingWidget.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ def get_file (self, n, max=10, ext='.jpg'):
os.path.exists(self.image_files[(n,max,ext)])
):
return self.image_files[(n,max,ext)]
fi = tempfile.mktemp("%s_of_%s.%s"%(n,max,ext))
fi = tempfile.mkstemp("%s_of_%s.%s"%(n,max,ext))
i = self.get_image(n,max)
i = i.convert('RGB')
i.save(fi)
Expand Down
4 changes: 2 additions & 2 deletions src/gourmand/importers/html_importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -451,8 +451,8 @@ def __init__ (self, rd, url, add_webpage_source=True,
self.url = url
self.prog = prog
self.interactive = interactive
importer.Importer.__init__(self,rd,threaded=threaded,total=total,prog=prog,do_markup=True,
conv=conv)
importer.Importer.__init__(self, rd, total=total, prog=prog,
do_markup=True, conv=conv)

def run (self):
"""Import our recipe to our database.
Expand Down
4 changes: 2 additions & 2 deletions src/gourmand/importers/importManager.py
Original file line number Diff line number Diff line change
Expand Up @@ -240,9 +240,9 @@ def get_tempfilename(self, url: str,
elif content_type:
ext = self.guess_extension(content_type)
if ext:
tf = tempfile.mktemp('.'+ext)
tf = tempfile.mkstemp('.' + ext)
else:
tf = tempfile.mktemp()
tf = tempfile.mkstemp()
self.tempfiles[url] = tf
with open(tf, "wb") as fout:
fout.write(data)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,10 @@
import array
import os.path
import re
import string

from gourmand import check_encodings, convert
from gourmand.gdebug import TimeAction, debug
from gourmand.importers import importer, plaintext_importer

#from gourmand.gglobals import gt

class mmf_constants:
def __init__ (self):
Expand Down Expand Up @@ -556,25 +553,3 @@ def find_columns (strings, char=" "):
columns.sort()
testtimer.end()
return columns



if __name__ == '__main__':
import os.path
import profile
import sys
import tempfile

import gourmand.recipeManager as recipeManager
print('Testing MealMaster import')
tmpfile = tempfile.mktemp()
import backends.db
rd = backends.db.RecipeManager(tmpfile)
if not args: args = ['/home/tom/Projects/recipe/Data/200_Recipes.mmf']
for a in args:
profi = os.path.join(tempfile.tempdir,'MMI_PROFILE')
profile.run("mmf_importer(rd,a,prog=lambda *args: sys.stdout.write('|'),threaded=False)",
profi)
import pstats
p = pstats.Stats(profi)
p.strip_dirs().sort_stats('cumulative').print_stats()
175 changes: 21 additions & 154 deletions src/gourmand/plugins/import_export/pdf_plugin/pdf_exporter.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,15 @@
import math
import os.path
import re
import tempfile
import types
import webbrowser
import xml.sax.saxutils
from gettext import ngettext
from io import BytesIO

import reportlab
import reportlab.lib.colors as colors
import reportlab.lib.fonts as fonts
import reportlab.lib.pagesizes as pagesizes
import reportlab.lib.styles as styles
import reportlab.lib.units as units
from reportlab.lib import colors, pagesizes, styles
import reportlab.platypus as platypus
from gi.repository import Gtk
from reportlab.lib.units import inch, mm
from reportlab.pdfbase import pdfmetrics
from reportlab.pdfgen import canvas
from reportlab.platypus.flowables import ParagraphAndImage

import gourmand.exporters.exporter as exporter
from gourmand import convert, gglobals, image_utils
from gourmand import convert, gglobals
from gourmand.gtk_extras import cb_extras
from gourmand.gtk_extras import dialog_extras as de
from gourmand.gtk_extras import optionTable
Expand All @@ -31,27 +18,39 @@

from .page_drawer import PageDrawer

DEFAULT_PDF_ARGS = {'bottom_margin': 72, 'pagesize': 'letter', 'right_margin': 72, 'top_margin': 72, 'left_margin': 72, 'pagemode': 'portrait', 'base_font_size': 10, 'mode': ('column', 1)}
DEFAULT_PDF_ARGS = {
'bottom_margin': 72,
'pagesize': 'letter',
'right_margin': 72,
'top_margin': 72,
'left_margin': 72,
'pagemode': 'portrait',
'base_font_size': 10,
'mode': ('column', 1),
}


# Code for MCLine from:
# http://two.pairlist.net/pipermail/reportlab-users/2005-February/003695.html
class MCLine(platypus.Flowable):
"""Line flowable --- draws a line in a flowable"""
"""Line flowable.
Draw a line in a flowable. Code for MCLine from:
http://two.pairlist.net/pipermail/reportlab-users/2005-February/003695.html
"""

def __init__(self,width):
def __init__(self, width):
platypus.Flowable.__init__(self)
self.width = width

def __repr__(self):
return "Line(w=%s)" % self.width

def draw(self):
self.canv.line(0,0,self.width,0)
self.canv.line(0, 0, self.width, 0)


class Star (platypus.Flowable):
'''A hand flowable.'''
def __init__(self, size=None, fillcolor=colors.tan, strokecolor=colors.green):
from reportlab.lib.units import inch
if size is None: size=12 # 12 point
self.fillcolor, self.strokecolor = fillcolor, strokecolor
self.size = size
Expand Down Expand Up @@ -1027,135 +1026,3 @@ def get_pdf_prefs (defaults=None):
if defaults: print('WARNING: ignoring provided defaults and using prefs system instead')
pdf_pref_getter = PdfPrefGetter()
return pdf_pref_getter.run()

if __name__ == '__main__':
w = Gtk.Window()
cuo = CustomUnitOption(44)
cuo2 = CustomUnitOption(98)
cuo.sync_to_other_cuo(cuo2)
cuo2.sync_to_other_cuo(cuo)
vb = Gtk.VBox()
l = Gtk.Label(label='Hello World')
vb.add(l)
vb.pack_start(cuo, True, True, 0)
vb.pack_start(cuo2, True, True, 0)
w.add(vb)
vb.show(); cuo.show(); cuo2.show()
w.show()
w.connect('delete_event',Gtk.main_quit)
Gtk.main()
raise Exception("Hell")

import os.path
from tempfile import tempdir

#opts = get_pdf_prefs(); print opts
test_3_x_5()

#star_file = open(os.path.join(tempdir,'star.pdf'),'wb')
#sw = PdfWriter()
#sw.setup_document(star_file,mode='two_column')
#for n in range(6,72,2):
# sw.write_paragraph("This is some text with a %s pt star"%n)
# sw.txt.append(FiveStars(n,filled=3.5))
#
#sw.close()
#star_file.close()
#import gnome
#gnome.program_init('1.0','Gourmet PDF Exporter Test')
#raise Exception("I don')t want to go any further")

if os.name == 'nt':
base = 'C:\\grm\grm'
else:
base = '/home/tom/Projects/grm'

#import gourmand.recipeManager as rm
#rd = rm.RecipeManager(file=os.path.join(base,'src','tests','reference_setup','recipes.db'))
#rd = rm.RecipeManager()
#ofi = open(os.path.join(tempdir,'test_rec.pdf'),'w')
#rr = []
#for n,rec in enumerate(rd.fetch_all(rd.recipe_table,deleted=False)):
# if rec.image:
# rr.append(rec)
#pe = PdfExporterMultiDoc(rd,rd.fetch_all(rd.recipe_table),os.path.join(tempdir,'fooby.pdf'))
#pe = PdfExporterMultiDoc(rd,rd.fetch_all(rd.recipe_table,deleted=False)[:10],os.path.join(tempdir,'fooby.pdf'))
#pe = PdfExporterMultiDoc(rd,rr,os.path.join(tempdir,'fooby.pdf'))
#pe.run()

def test_formatting ():
sw = PdfWriter()
with open(os.path.join(tempdir,'format.pdf'),'wb') as f:
sw.setup_document(f)
sw.write_header('This is a header & isn\'t it nifty')
sw.write_paragraph('<i>This</i> is a <b>paragraph</b> with <u>formatting</u>!')
sw.write_header('<u>This is a formatted header &amp; it is also nifty &amp; cool</u>')
sw.write_paragraph('<i>This is another formatted paragraph</i>')
sw.write_paragraph('<span fg="\#f00">This is color</span>')
sw.close()
return os.path.join(tempdir,'format.pdf')

def test_3_x_5 ():
print('Test 3x5 layout')
sw = PdfWriter()
with open(os.path.join(tempdir,'foo.pdf'), 'wb') as f:
sw.setup_document(f,
mode=('index_cards',(5*inch,3.5*inch)),
#pagesize=(5*inch,3.5*inch),
pagesize='letter',
pagemode='landscape',
left_margin=0.25*inch,right_margin=0.25*inch,
top_margin=0.25*inch,bottom_margin=0.25*inch,
base_font_size=8,
)
#sw.write_header('Heading')
#sw.write_subheader('This is a subheading')
for n in range(5):
sw.write_header(
"This is a header"
)
#sw.write_subheader(
# u"This is a subheader"
# )
sw.write_paragraph(
"%s: These are some sentences. Hopefully some of these will be quite long sentences. Some of this text includes unicode -- 45\u00b0F, for example... \u00bfHow's that?"%n*10
)
#sw.write_paragraph('This is a <i>paragraph</i> with <b>some</b> <u>markup</u>.')
#sw.write_paragraph(u"This is some text with unicode - 45\u00b0, \u00bfHow's that?".encode('iso-8859-1'))
#sw.write_paragraph(u"This is some text with a unicode object - 45\u00b0, \u00bfHow's that?")
sw.close()
return os.path.join(tempdir,'foo.pdf')

def test_grm_export (pdf_args=DEFAULT_PDF_ARGS):
fname = tempfile.mktemp('.pdf')
#if os.name == 'nt':
# base = 'C:\\grm\grm'
#else:
# base = '/home/tom/Projects/grm'
import gourmand.recipeManager as rm
rd = rm.get_recipe_manager(file=os.path.join(base,'src','tests','reference_setup','recipes.db'))
#rd = rm.RecipeManager()
rr = []
#for n,rec in enumerate(rd.fetch_all(rd.recipe_table,deleted=False)):
# if rec.image:
# rr.append(rec)
pe = PdfExporterMultiDoc(rd,rd.fetch_all(rd.recipe_table,deleted=False),fname,pdf_args=pdf_args)
pe.run()
return fname

#try:
# import gnome
# gnome.program_init('1.0','Gourmet PDF Exporter Test')
#except ImportError:
# print 'We must be on windows...'

#print 'TEST 3x5'
webbrowser.open('file://'+test_3_x_5())
webbrowser.open('file://'+test_formatting())
#print 'END TEST'
#print 'TEST GRM'
webbrowser.open('file://'+test_grm_export())
#print 'TEST CUSTOM GRM'
#ppg = PdfPrefGetter()
#print ppg.run()
#print 'END TEST'
Loading

0 comments on commit 5454781

Please sign in to comment.