[ocrfeeder] Use the dedicated temporary folder consistently
- From: Joaquim Manuel Pereira Rocha <jrocha src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [ocrfeeder] Use the dedicated temporary folder consistently
- Date: Fri, 28 Oct 2011 17:18:30 +0000 (UTC)
commit f7998cd314369036c4d4843aa88107f274e994e7
Author: Joaquim Rocha <jrocha igalia com>
Date: Fri Oct 21 22:39:11 2011 +0200
Use the dedicated temporary folder consistently
Some parts where honoring the configured temporary folder
while others simply used the one default one provided by
the tempfile module's functions.
Also it deletes that temporary folder so no temporary files
will be left undeleted.
bin/ocrfeeder-cli.in | 2 ++
src/ocrfeeder/feeder/documentGeneration.py | 7 +++++--
src/ocrfeeder/feeder/ocrEngines.py | 12 +++++++++---
src/ocrfeeder/studio/project.py | 4 ++--
src/ocrfeeder/studio/studioBuilder.py | 6 ++++--
src/ocrfeeder/studio/widgetModeler.py | 6 ++++--
src/ocrfeeder/studio/widgetPresenter.py | 4 ++--
7 files changed, 28 insertions(+), 13 deletions(-)
---
diff --git a/bin/ocrfeeder-cli.in b/bin/ocrfeeder-cli.in
index 3256698..51c6978 100644
--- a/bin/ocrfeeder-cli.in
+++ b/bin/ocrfeeder-cli.in
@@ -114,3 +114,5 @@ if 'html' in export_format:
for page in pages:
document_generator.addPage(page)
document_generator.save()
+
+configuration_manager.removeTemporaryFolder()
diff --git a/src/ocrfeeder/feeder/documentGeneration.py b/src/ocrfeeder/feeder/documentGeneration.py
index ffa768a..b5b0061 100644
--- a/src/ocrfeeder/feeder/documentGeneration.py
+++ b/src/ocrfeeder/feeder/documentGeneration.py
@@ -27,6 +27,7 @@ from pango import WEIGHT_BOLD, WEIGHT_NORMAL, STYLE_ITALIC, STYLE_NORMAL, \
STYLE_OBLIQUE
from ocrfeeder.util import TEXT_TYPE, IMAGE_TYPE, ALIGN_LEFT, ALIGN_RIGHT, ALIGN_CENTER, \
ALIGN_FILL
+from ocrfeeder.util.configuration import ConfigurationManager
from ocrfeeder.util.graphics import getImagePrintSize
from ocrfeeder.util.lib import debug
from reportlab.pdfgen import canvas
@@ -104,7 +105,8 @@ class HtmlGenerator(DocumentGenerator):
def addImage(self, data_box):
format = 'PNG'
- image_file = tempfile.mkstemp(suffix = '.' + format.lower())[1]
+ image_file = tempfile.mkstemp(dir = ConfigurationManager.TEMPORARY_FOLDER,
+ suffix = '.' + format.lower())[1]
data_box.image.save(image_file, format = format)
self.images.append(image_file)
new_div = '''
@@ -249,7 +251,8 @@ class OdtGenerator(DocumentGenerator):
def addImage(self, data_box):
format = 'PNG'
- image_file = tempfile.mkstemp(suffix = '.' + format)[1]
+ image_file = tempfile.mkstemp(dir = ConfigurationManager.TEMPORARY_FOLDER,
+ suffix = '.' + format)[1]
data_box.image.save(image_file, format = format)
x, y, width, height = data_box.getBoundsPrintSize(self.current_page_resolution)
photo_frame = Frame(stylename=self.photo_style, x = '%sin' % x, y = '%sin' % y, width = '%sin' % width, height = '%sin' % height, anchortype='paragraph')
diff --git a/src/ocrfeeder/feeder/ocrEngines.py b/src/ocrfeeder/feeder/ocrEngines.py
index a26e423..07c791d 100644
--- a/src/ocrfeeder/feeder/ocrEngines.py
+++ b/src/ocrfeeder/feeder/ocrEngines.py
@@ -50,7 +50,8 @@ class Engine:
self.__color_information = None
def setImage(self, image):
- image_file = tempfile.mkstemp(suffix = '.' + self.image_format.lower())[1]
+ image_file = tempfile.mkstemp(dir = self.temporary_folder,
+ suffix = '.' + self.image_format.lower())[1]
image = image.convert('L')
try:
image.save(image_file, format = self.image_format)
@@ -166,13 +167,18 @@ class OcrEnginesManager:
arg_name = child.tag
arg_value = child.text
arguments[arg_name] = arg_value
- return Engine(**arguments)
+ engine = Engine(**arguments)
+ engine.temporary_folder = self.configuration_manager.TEMPORARY_FOLDER
+ return engine
def getXmlFilesInFolder(self, folder):
return [os.path.join(folder, file) for file in os.listdir(folder) if file.endswith('.xml')]
def newEngine(self, name, engine_path, arguments, image_format, failure_string):
- engine = Engine(name = name, engine_path = engine_path, arguments = arguments, image_format = image_format, failure_string = failure_string)
+ engine = Engine(name = name, engine_path = engine_path,
+ arguments = arguments, image_format = image_format,
+ temporary_folder = self.configuration_manager.TEMPORARY_FOLDER,
+ failure_string = failure_string)
return engine
def delete(self, index):
diff --git a/src/ocrfeeder/studio/project.py b/src/ocrfeeder/studio/project.py
index f25bfb6..4586275 100644
--- a/src/ocrfeeder/studio/project.py
+++ b/src/ocrfeeder/studio/project.py
@@ -35,7 +35,7 @@ class ProjectSaver:
self.pages_data = pages_data
self.document = minidom.Document()
self.images = {}
- self.temp_dir = ConfigurationManager().temporary_dir
+ self.temp_dir = ConfigurationManager.TEMPORARY_FOLDER
def __handleImageEmbedding(self, page_data):
base_name = os.path.basename(page_data.image_path)
@@ -113,7 +113,7 @@ class ProjectSaver:
class ProjectLoader:
def __init__(self, project_file):
- self.temp_dir = ConfigurationManager().temporary_dir
+ self.temp_dir = ConfigurationManager.TEMPORARY_FOLDER
if not (os.path.isfile(project_file) and project_file.endswith('.ocrf')):
#raise
pass
diff --git a/src/ocrfeeder/studio/studioBuilder.py b/src/ocrfeeder/studio/studioBuilder.py
index db425bf..0ef9c1c 100644
--- a/src/ocrfeeder/studio/studioBuilder.py
+++ b/src/ocrfeeder/studio/studioBuilder.py
@@ -168,7 +168,8 @@ class Studio:
paths.append(path)
for path in paths:
if os.path.splitext(path)[1] == '.pdf':
- folder = lib.convertPdfToImages(path, self.configuration_manager.temporary_dir)
+ folder = lib.convertPdfToImages(path,
+ self.configuration_manager.TEMPORARY_FOLDER)
self.__addImagesToReviewer(lib.getImagesFromFolder(folder))
else:
try:
@@ -261,7 +262,7 @@ class Studio:
self.main_window.window)
item = AsyncItem(lib.convertPdfToImages,
(file_name,
- self.configuration_manager.temporary_dir),
+ self.configuration_manager.TEMPORARY_FOLDER),
self.__loadPdfFinishedCb,
(dialog,))
info = (_('Loading PDF'), _(u'Please waitâ'))
@@ -464,4 +465,5 @@ class Studio:
def __main_quit(self):
self.configuration_manager.configurationToXml()
+ self.configuration_manager.removeTemporaryFolder()
gtk.main_quit()
diff --git a/src/ocrfeeder/studio/widgetModeler.py b/src/ocrfeeder/studio/widgetModeler.py
index 850eaa3..db3b512 100644
--- a/src/ocrfeeder/studio/widgetModeler.py
+++ b/src/ocrfeeder/studio/widgetModeler.py
@@ -506,7 +506,7 @@ class ImageReviewer_Controler:
def __deskewImage(self, image_path, target_image_path = None):
if not target_image_path:
- tmp_dir = self.configuration_manager.temporary_dir
+ tmp_dir = self.configuration_manager.TEMPORARY_FOLDER
target_image_path = os.path.join(tmp_dir,
os.path.basename(image_path))
if os.path.exists(target_image_path):
@@ -841,7 +841,9 @@ class ImageReviewer_Controler:
def unpaperTool(self):
current_reviewer = self.__getCurrentReviewer()
- unpaper_dialog = UnpaperDialog(current_reviewer, self.configuration_manager.unpaper, self.configuration_manager.temporary_dir)
+ unpaper_dialog = UnpaperDialog(current_reviewer,
+ self.configuration_manager.unpaper,
+ self.configuration_manager.TEMPORARY_FOLDER)
if unpaper_dialog.run() == gtk.RESPONSE_ACCEPT:
unpapered_image = unpaper_dialog.getUnpaperedImage()
current_reviewer.updateBackgroundImage(unpapered_image)
diff --git a/src/ocrfeeder/studio/widgetPresenter.py b/src/ocrfeeder/studio/widgetPresenter.py
index 086f760..6df1cda 100644
--- a/src/ocrfeeder/studio/widgetPresenter.py
+++ b/src/ocrfeeder/studio/widgetPresenter.py
@@ -1282,7 +1282,7 @@ class PreferencesDialog(gtk.Dialog):
return (red >> 8, green >> 8, blue >> 8, alpha >> 8)
def saveToManager(self):
- self.configuration_manager.temporary_dir =self.__getTemporaryDir()
+ self.configuration_manager.TEMPORARY_FOLDER = self.__getTemporaryDir()
self.configuration_manager.setWindowSize(self.__getWindowSize())
self.configuration_manager.setTextFill(self.__getColor(self.text_fill_color))
self.configuration_manager.setBoxesStroke(
@@ -1318,7 +1318,7 @@ class PreferencesDialog(gtk.Dialog):
def __makeTemporaryFolder(self):
temporary_dir_frame = PlainFrame(_('Temporary folder'))
self.temporary_folder = gtk.Entry()
- self.temporary_folder.set_text(self.configuration_manager.temporary_dir)
+ self.temporary_folder.set_text(self.configuration_manager.TEMPORARY_FOLDER)
self.temporary_folder.set_width_chars(30)
self.temporary_folder_button = gtk.Button(_('Choose'), gtk.STOCK_OPEN)
temporary_folder_hbox = gtk.HBox()
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]