Skip to content

Commit

Permalink
Some housecleaning
Browse files Browse the repository at this point in the history
  • Loading branch information
btimby committed Mar 1, 2012
1 parent 0ef0a5b commit bf1b751
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 10 deletions.
1 change: 1 addition & 0 deletions tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from PIL import Image
from thumbnailer import library as thumb


class ThumbnailerTestCase(unittest.TestCase):
def assertDimensions(self, t):
w, h = Image.open(t).size
Expand Down
6 changes: 0 additions & 6 deletions thumbnailer/library/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,6 @@
'-vframes', '1',
'-ss', '1',
)
UC_ARGS = (
'unoconv',
)

def create(f, **kwargs):
if isinstance(f, basestring):
Expand Down Expand Up @@ -88,8 +85,6 @@ def create(self, f):


class OfficeBackend(PdfBackend):
# TODO: perhaps import unoconv and use some of it's internals.
# Particularly it would be nice to use a persistent server (OO.org/LibreOffice).
def __init__(self, connection=None, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT):
from . import unoclient
super(OfficeBackend, self).__init__(width, height)
Expand All @@ -101,7 +96,6 @@ def __init__(self, connection=None, width=DEFAULT_WIDTH, height=DEFAULT_HEIGHT):
self.client = unoclient.Client(connection)

def create(self, f):
args = list(UC_ARGS)
if not isinstance(f, basestring):
o, fname = tempfile.mkstemp()
try:
Expand Down
10 changes: 6 additions & 4 deletions thumbnailer/library/unoclient.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import os, uno
from unohelper import Base, systemPathToFileUrl, absolutize
from unohelper import Base, systemPathToFileUrl
from com.sun.star.beans import PropertyValue
from com.sun.star.connection import NoConnectException
from com.sun.star.io import IOException, XOutputStream
Expand All @@ -8,6 +8,9 @@
except ImportError:
from StringIO import StringIO

# Taken from example:
# http://www.openoffice.org/udk/python/samples/ooextract.py

# To run in Foreground:
# soffice --accept=socket,host=localhost,port=2002;urp;
# To run headless:
Expand Down Expand Up @@ -51,7 +54,6 @@ def __init__(self, connection):
'com.sun.star.frame.Desktop',
context,
)
self.cwd = systemPathToFileUrl(os.getcwd())

def export_to_pdf(self, path):
stream = OutputStream()
Expand All @@ -66,8 +68,8 @@ def export_to_pdf(self, path):
)
document = None
try:
fileUrl = absolutize(self.cwd, systemPathToFileUrl(path))
document = self.desktop.loadComponentFromURL(fileUrl, '_blank', 0, props_in)
pathUrl = systemPathToFileUrl(os.path.abspath(path))
document = self.desktop.loadComponentFromURL(pathUrl, '_blank', 0, props_in)
document.storeToURL('private:stream', props_out)
finally:
if document:
Expand Down

0 comments on commit bf1b751

Please sign in to comment.