diff --git a/src/gourmand/exporters/eatdrinkfeelgood_exporter.py b/src/gourmand/exporters/eatdrinkfeelgood_exporter.py
index 50bf3e4e..6b7c98b3 100644
--- a/src/gourmand/exporters/eatdrinkfeelgood_exporter.py
+++ b/src/gourmand/exporters/eatdrinkfeelgood_exporter.py
@@ -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
@@ -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")
diff --git a/src/gourmand/exporters/exportManager.py b/src/gourmand/exporters/exportManager.py
index e621bbb2..d944c7d4 100644
--- a/src/gourmand/exporters/exportManager.py
+++ b/src/gourmand/exporters/exportManager.py
@@ -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,
diff --git a/src/gourmand/gtk_extras/ratingWidget.py b/src/gourmand/gtk_extras/ratingWidget.py
index cb81e492..7cfe04a8 100644
--- a/src/gourmand/gtk_extras/ratingWidget.py
+++ b/src/gourmand/gtk_extras/ratingWidget.py
@@ -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)
diff --git a/src/gourmand/importers/html_importer.py b/src/gourmand/importers/html_importer.py
index d6c3110c..db5d34d6 100644
--- a/src/gourmand/importers/html_importer.py
+++ b/src/gourmand/importers/html_importer.py
@@ -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.
diff --git a/src/gourmand/importers/importManager.py b/src/gourmand/importers/importManager.py
index f46389f7..6c03746f 100644
--- a/src/gourmand/importers/importManager.py
+++ b/src/gourmand/importers/importManager.py
@@ -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)
diff --git a/src/gourmand/plugins/import_export/mealmaster_plugin/mealmaster_importer.py b/src/gourmand/plugins/import_export/mealmaster_plugin/mealmaster_importer.py
index c9a2e9f0..c598fa54 100644
--- a/src/gourmand/plugins/import_export/mealmaster_plugin/mealmaster_importer.py
+++ b/src/gourmand/plugins/import_export/mealmaster_plugin/mealmaster_importer.py
@@ -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):
@@ -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()
diff --git a/src/gourmand/plugins/import_export/pdf_plugin/pdf_exporter.py b/src/gourmand/plugins/import_export/pdf_plugin/pdf_exporter.py
index 9ccbe0c4..6c121a65 100644
--- a/src/gourmand/plugins/import_export/pdf_plugin/pdf_exporter.py
+++ b/src/gourmand/plugins/import_export/pdf_plugin/pdf_exporter.py
@@ -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
@@ -31,14 +18,26 @@
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
@@ -46,12 +45,12 @@ 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
@@ -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('This is a paragraph with formatting!')
- sw.write_header('This is a formatted header & it is also nifty & cool')
- sw.write_paragraph('This is another formatted paragraph')
- sw.write_paragraph('This is color')
- 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 paragraph with some markup.')
- #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'
diff --git a/src/gourmand/plugins/import_export/pdf_plugin/print_plugin.py b/src/gourmand/plugins/import_export/pdf_plugin/print_plugin.py
index 28377a82..c467b23f 100644
--- a/src/gourmand/plugins/import_export/pdf_plugin/print_plugin.py
+++ b/src/gourmand/plugins/import_export/pdf_plugin/print_plugin.py
@@ -158,16 +158,18 @@ def close (self, *args, **kwargs):
self.export_commands.append(('close',[],{}))
self.setup_printer(self.parent)
- def begin_print (self, operation, context):
- fn = tempfile.mktemp()
+ def begin_print(self,
+ operation: Gtk.PrintOperation,
+ context: Gtk.PrintContext):
+ filename = tempfile.mkstemp()
writer = pdf_exporter.PdfWriter()
- writer.setup_document(fn,**self.args)
+ writer.setup_document(filename, **self.args)
# Playback all the commands we recorded
- for commandname,args,kwargs in self.export_commands:
- func = getattr(writer,commandname)
- func(*args,**kwargs)
+ for commandname, args, kwargs in self.export_commands:
+ func = getattr(writer, commandname)
+ func(*args, **kwargs)
# And now we trust the documents been written...
- self.set_document(fn,operation,context)
+ self.set_document(filename, operation, context)
class PDFRecipePrinter (PDFPrinter):
@@ -186,7 +188,7 @@ def __init__ (self, rd, recs,
def begin_print(self,
operation: Gtk.PrintOperation,
context: Gtk.PrintContext):
- fn = tempfile.mktemp()
+ fn = tempfile.mkstemp()
pe = pdf_exporter.PdfExporterMultiDoc(self.rd, self.recs, fn,
change_units=self.change_units,
mult=self.mult)
diff --git a/src/gourmand/plugins/import_export/website_import_plugins/cooksillustrated_plugin.py b/src/gourmand/plugins/import_export/website_import_plugins/cooksillustrated_plugin.py
index f0ebfa8b..f4f424ff 100644
--- a/src/gourmand/plugins/import_export/website_import_plugins/cooksillustrated_plugin.py
+++ b/src/gourmand/plugins/import_export/website_import_plugins/cooksillustrated_plugin.py
@@ -29,24 +29,17 @@ def __init__ (self, url):
def do_run (self):
self.read()
- def get_username_and_pw (self):
- print('Let us get a password...')
+ def get_username_and_pw(self):
+ pw = ''
username = self.prefs.get('cooksillustrated-username','')
- print('Username=',username)
if username:
pw = keyring.get_password(
'http://www.cooksillustrated.com',
username
)
else:
- pw = ''
- print('Initial password: ',pw)
- print('Launch dialog...')
- #
- username, pw = de.getUsernameAndPassword(
- username=username,
- pw=pw
- )
+ username, pw = de.getUsernameAndPassword(username=username,
+ pw=pw)
# broken :( - temporary workaround?
#username,pw = 'USERNAME','PASSWORD'
print('Done with dialog')
diff --git a/src/gourmand/plugins/unit_display_prefs/__init__.py b/src/gourmand/plugins/unit_display_prefs/__init__.py
index df598c95..3a2890ba 100644
--- a/src/gourmand/plugins/unit_display_prefs/__init__.py
+++ b/src/gourmand/plugins/unit_display_prefs/__init__.py
@@ -42,7 +42,7 @@ def activate (self, db):
db.add_hook(PRE,'get_amount_and_unit',self.get_amount_and_unit_hook)
def get_amount_and_unit_hook (self, db, *args, **kwargs):
- kwargs['preferred_unit_groups'] = Prefs.instance()().get('preferred_unit_groups',[])
+ kwargs['preferred_unit_groups'] = Prefs.instance().get('preferred_unit_groups',[])
return args,kwargs