本文整理汇总了Python中uno.systemPathToFileUrl函数的典型用法代码示例。如果您正苦于以下问题:Python systemPathToFileUrl函数的具体用法?Python systemPathToFileUrl怎么用?Python systemPathToFileUrl使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了systemPathToFileUrl函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: convert
def convert(self, inputFile, outputFile):
"""
Convert the input file (a spreadsheet) to a CSV file.
"""
# Start openoffice if needed.
if not self.desktop:
if not self.oorunner:
self.oorunner = ooutils.OORunner()
self.desktop = self.oorunner.connect()
inputUrl = uno.systemPathToFileUrl(os.path.abspath(inputFile))
outputUrl = uno.systemPathToFileUrl(os.path.abspath(outputFile))
document = self.desktop.loadComponentFromURL(inputUrl, "_blank", 0, ooutils.oo_properties(Hidden=True))
try:
# Additional property option:
# FilterOptions="59,34,0,1"
# 59 - Field separator (semicolon), this is the ascii value.
# 34 - Text delimiter (double quote), this is the ascii value.
# 0 - Character set (system).
# 1 - First line number to export.
#
# For more information see:
# http://wiki.services.openoffice.org/wiki/Documentation/DevGuide/Spreadsheets/Filter_Options
#
document.storeToURL(outputUrl, ooutils.oo_properties(FilterName="Text - txt - csv (StarCalc)"))
finally:
document.close(True)
示例2: __call__
def __call__(self, xsl_path, inp_path, out_path):
import uno
import unohelper
import os.path
from hwp5.plat._uno import ucb
from hwp5.plat._uno.adapters import OutputStreamToFileLike
xsl_path = os.path.abspath(xsl_path)
xsl_url = uno.systemPathToFileUrl(xsl_path)
inp_path = os.path.abspath(inp_path)
inp_url = uno.systemPathToFileUrl(inp_path)
inp_stream = ucb.open_url(self.context, inp_url)
out_path = os.path.abspath(out_path)
with file(out_path, 'w') as out_file:
out_stream = OutputStreamToFileLike(out_file, dontclose=True)
from com.sun.star.io import XStreamListener
class XSLTListener(unohelper.Base, XStreamListener):
def __init__(self):
self.event = OneshotEvent()
def started(self):
logger.info('XSLT started')
def closed(self):
logger.info('XSLT closed')
self.event.signal()
def terminated(self):
logger.info('XSLT terminated')
self.event.signal()
def error(self, exception):
logger.error('XSLT error: %s', exception)
self.event.signal()
def disposing(self, source):
logger.info('XSLT disposing: %s', source)
self.event.signal()
listener = XSLTListener()
transformer = XSLTTransformer(self.context, xsl_url, '', '')
transformer.InputStream = inp_stream
transformer.OutputStream = out_stream
transformer.addListener(listener)
transformer.start()
import os.path
xsl_name = os.path.basename(xsl_path)
logger.info('xslt.soffice(%s) start', xsl_name)
try:
listener.event.wait()
finally:
logger.info('xslt.soffice(%s) end', xsl_name)
transformer.removeListener(listener)
return dict()
示例3: load_presentation
def load_presentation(self):
"""
Called when a presentation is added to the SlideController. It builds the environment, starts communcations with
the background OpenOffice task started earlier. If OpenOffice is not present is is started. Once the environment
is available the presentation is loaded and started.
"""
log.debug('Load Presentation OpenOffice')
if is_win():
desktop = self.controller.get_com_desktop()
if desktop is None:
self.controller.start_process()
desktop = self.controller.get_com_desktop()
url = 'file:///' + self.file_path.replace('\\', '/').replace(':', '|').replace(' ', '%20')
else:
desktop = self.controller.get_uno_desktop()
url = uno.systemPathToFileUrl(self.file_path)
if desktop is None:
return False
self.desktop = desktop
properties = []
properties.append(self.create_property('Hidden', True))
properties = tuple(properties)
try:
self.document = desktop.loadComponentFromURL(url, '_blank', 0, properties)
except:
log.warning('Failed to load presentation %s' % url)
return False
self.presentation = self.document.getPresentation()
self.presentation.Display = ScreenList().current['number'] + 1
self.control = None
self.create_thumbnails()
self.create_titles_and_notes()
return True
示例4: getResultUrl
def getResultUrl(self):
'''Returns the path of the result file in the format needed by OO. If
the result type and the input type are the same (ie the user wants to
refresh indexes or some other action and not perform a real
conversion), the result file is named
<inputFileName>.res.<resultType>.
Else, the result file is named like the input file but with a
different extension:
<inputFileName>.<resultType>
'''
import uno
baseName = os.path.splitext(self.docPath)[0]
if self.resultType != self.inputType:
res = '%s.%s' % (baseName, self.resultType)
else:
res = '%s.res.%s' % (baseName, self.resultType)
try:
f = open(res, 'w')
f.write('Hello')
f.close()
os.remove(res)
return uno.systemPathToFileUrl(res)
except (OSError, IOError), ioe:
raise ConverterError(CANNOT_WRITE_RESULT % (res, ioe))
示例5: create_thumbnails
def create_thumbnails(self):
"""
Create thumbnail images for presentation.
"""
log.debug('create thumbnails OpenOffice')
if self.check_thumbnails():
return
if os.name == 'nt':
thumb_dir_url = 'file:///' + self.get_temp_folder().replace('\\', '/') \
.replace(':', '|').replace(' ', '%20')
else:
thumb_dir_url = uno.systemPathToFileUrl(self.get_temp_folder())
properties = []
properties.append(self.create_property('FilterName', 'impress_png_Export'))
properties = tuple(properties)
doc = self.document
pages = doc.getDrawPages()
if not pages:
return
if not os.path.isdir(self.get_temp_folder()):
os.makedirs(self.get_temp_folder())
for index in range(pages.getCount()):
page = pages.getByIndex(index)
doc.getCurrentController().setCurrentPage(page)
url_path = '%s/%s.png' % (thumb_dir_url, str(index + 1))
path = os.path.join(self.get_temp_folder(), str(index + 1) + '.png')
try:
doc.storeToURL(url_path, properties)
self.convert_thumbnail(path, index + 1)
delete_file(path)
except ErrorCodeIOException as exception:
log.exception('ERROR! ErrorCodeIOException %d' % exception.ErrCode)
except:
log.exception('%s - Unable to store openoffice preview' % path)
示例6: xslt_with_libreoffice
def xslt_with_libreoffice(xsl_path, inp_path, out_path):
import os.path
xsl_path = os.path.abspath(xsl_path)
xsl_name = os.path.basename(xsl_path)
xsl_url = uno.systemPathToFileUrl(xsl_path)
inp_path = os.path.abspath(inp_path)
inp_file = file(inp_path)
inp_strm = InputStreamFromFileLike(inp_file, dontclose=True)
out_path = os.path.abspath(out_path)
out_file = file(out_path, 'w')
out_strm = OutputStreamToFileLike(out_file, dontclose=True)
transformer = XSLTTransformer(xsl_url, '', '')
transformer.InputStream = inp_strm
transformer.OutputStream = out_strm
listener = XSLTListener()
transformer.addListener(listener)
transformer.start()
logger.info('xslt.soffice(%s) start', xsl_name)
try:
listener.event.wait()
finally:
logger.info('xslt.soffice(%s) end', xsl_name)
transformer.removeListener(listener)
return dict()
示例7: create_thumbnails
def create_thumbnails(self):
"""
Create thumbnail images for presentation
"""
log.debug(u'create thumbnails OpenOffice')
if self.check_thumbnails():
return
if os.name == u'nt':
thumbdirurl = u'file:///' + self.get_temp_folder().replace(u'\\', u'/') \
.replace(u':', u'|').replace(u' ', u'%20')
else:
thumbdirurl = uno.systemPathToFileUrl(self.get_temp_folder())
props = []
props.append(self.create_property(u'FilterName', u'impress_png_Export'))
props = tuple(props)
doc = self.document
pages = doc.getDrawPages()
if not pages:
return
if not os.path.isdir(self.get_temp_folder()):
os.makedirs(self.get_temp_folder())
for idx in range(pages.getCount()):
page = pages.getByIndex(idx)
doc.getCurrentController().setCurrentPage(page)
urlpath = u'%s/%s.png' % (thumbdirurl, unicode(idx + 1))
path = os.path.join(self.get_temp_folder(), unicode(idx + 1) + u'.png')
try:
doc.storeToURL(urlpath, props)
self.convert_thumbnail(path, idx + 1)
delete_file(path)
except ErrorCodeIOException, exception:
log.exception(u'ERROR! ErrorCodeIOException %d' % exception.ErrCode)
except:
示例8: open
def open( self, filename ):
"""Open an OpenOffice document"""
#http://www.oooforum.org/forum/viewtopic.phtml?t=35344
properties = []
properties.append( OpenOfficeDocument._makeProperty( 'Hidden', True ) )
properties = tuple( properties )
self.oodocument = self.openoffice.loadComponentFromURL( uno.systemPathToFileUrl( os.path.abspath( filename ) ), "_blank", 0, properties )
示例9: addDocumentToEnd
def addDocumentToEnd( self, documentUrl, pageBreak=True ):
cursor = self.oodocument.Text.createTextCursor()
if cursor:
cursor.gotoEnd( False )
if pageBreak:
cursor.BreakType = PAGE_AFTER
cursor.insertDocumentFromURL( uno.systemPathToFileUrl( os.path.abspath( documentUrl ) ), () )
return True
return False
示例10: saveAs
def saveAs( self, filename ):
"""Save the open office document to a new file, and possibly filetype.
The type of document is parsed out of the file extension of the filename given."""
filename = uno.systemPathToFileUrl( os.path.abspath( filename ) )
#filterlist: http://wiki.services.openoffice.org/wiki/Framework/Article/Filter/FilterList_OOo_3_0
exportFilter = self._getExportFilter( filename )
props = exportFilter,
#storeToURL: #http://codesnippets.services.openoffice.org/Office/Office.ConvertDocuments.snip
self.oodocument.storeToURL( filename, props )
示例11: test_searchAndCursor
def test_searchAndCursor(self):
ood = WriterDocument()
ood.open("%s/docs/find_replace.odt" % self.path)
search = ood.oodocument.createSearchDescriptor()
search.setSearchString("search")
result = ood.oodocument.findFirst(search)
path = uno.systemPathToFileUrl("%s/docs/insertme.html" % self.path)
result.insertDocumentFromURL(path, tuple())
ood.saveAs("%s/docs/docInTheMiddle.pdf" % self.path)
ood.close()
示例12: getInputUrls
def getInputUrls(self, docPath):
'''Returns the absolute path of the input file. In fact, it returns a
tuple with some URL version of the path for OO as the first element
and the absolute path as the second element.'''
import uno
if not os.path.exists(docPath) and not os.path.isfile(docPath):
raise ConverterError(DOC_NOT_FOUND % docPath)
docAbsPath = os.path.abspath(docPath)
# Return one path for OO, one path for me.
return uno.systemPathToFileUrl(docAbsPath), docAbsPath
示例13: compare
def compare(self, path, original_path, save_path):
if not os.path.exists(path):
raise DocumentCompareException("%s does not exist" % (path,))
url = uno.systemPathToFileUrl(path)
if not os.path.exists(original_path):
raise DocumentCompareException("%s does not exist" % (original_path,))
url_original = uno.systemPathToFileUrl(original_path)
url_save = uno.systemPathToFileUrl(save_path)
### Load document
p = PropertyValue()
p.Name = "Hidden"
p.Value = True
properties = (p,)
doc = self.desktop.loadComponentFromURL(url, "_blank", 0, properties)
### Compare with original document
properties = []
p = PropertyValue()
p.Name = "URL"
p.Value = url_original
properties.append(p)
properties = tuple(properties)
dispatch_helper = self.servicemanager.createInstanceWithContext(
"com.sun.star.frame.DispatchHelper",
self.context)
dispatch_helper.executeDispatch(doc.getCurrentController().getFrame(),
".uno:CompareDocuments", "",
0, properties)
### Save File
p = PropertyValue()
p.Name = "Overwrite"
p.Value = True
properties = (p,)
doc.storeToURL(url_save, properties)
doc.dispose()
示例14: save
def save(self, path, file_format='MS Word 97'):
properties = (
PropertyValue("FilterName", 0, file_format, 0),
PropertyValue("Overwrite", 0, True, 0))
if self.document:
try:
self.document.storeToURL(uno.systemPathToFileUrl(path), properties)
except ErrorCodeIOException:
self.errors.append("Save file error (may be already open): %s" % path)
raise ODTFileError
示例15: save
def save(self, path):
from tools import Tools
if not hasattr(self.document, 'getArgs'):
return False
# import_extension = self.imp[self.filter]
if len(self.properties) == 0:
export_extension = Tools.get_extension(path)
properties = self.export_options[export_extension]
self.set_properties(properties)
self.document.storeToURL(uno.systemPathToFileUrl(abspath(path)), tuple(self.properties))
return True