Example #1
0
def expandUri(uri):
    if uri.startswith("vnd.sun.star.expand:"):
        uri = uri.replace("vnd.sun.star.expand:", "", 1)
        uri = uno.getComponentContext().getByName("/singletons/com.sun.star.util.theMacroExpander").expandMacros(uri)
    if uri.startswith("file:"):
        uri = uno.absolutize("", uri)  # necessary to get rid of .. in uri
    return uri
Example #2
0
    def createAddress(self, id):
        # get the central desktop object
        desktop = self.smgr.createInstanceWithContext( "com.sun.star.frame.Desktop",self.ctx)
        path = os.environ['CUON_OO_DOC']
        inProps = PropertyValue( "Hidden" , 0 , True, 0 ),
        fileUrl = uno.absolutize('test.sxc' , systemPathToFileUrl(path) )
        model = desktop.loadComponentFromURL( fileUrl , "_blank", 0, inProps)


        # access the current writer document
        #model = desktop.getCurrentComponent()

        # access the document's text property
        text = model.Text

        # create a cursor
        cursor = text.createTextCursor()

        liAddress = self.unpickleObject(id)
        for i in range(0,len(liAddress)):
            # insert the text into the document
            text.insertString( cursor, `liAddress[i]`, 0 )


        # Do a nasty thing before exiting the python process. In case the
        # last call is a oneway call (e.g. see idl-spec of insertString),
        # it must be forced out of the remote-bridge caches before python
        # exits the process. Otherwise, the oneway call may or may not reach
        # the target object.
        # I do this here by calling a cheap synchronous call (getPropertyValue).
        self.ctx.ServiceManager
Example #3
0
def expandUri(uri):
    if uri.startswith("vnd.sun.star.expand:"):
        uri = uri.replace("vnd.sun.star.expand:", "", 1)
        uri = uno.getComponentContext().getByName(
            "/singletons/com.sun.star.util.theMacroExpander").expandMacros(uri)
    if uri.startswith("file:"):
        uri = uno.absolutize("", uri)  # necessary to get rid of .. in uri
    return uri
Example #4
0
def main():
    retVal = 0
    doc = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "hc:",
                                   ["help", "connection-string=", "html"])
        format = None
        url = "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
        filterName = "Text (Encoded)"
        for o, a in opts:
            if o in ("-h", "--help"):
                usage()
                sys.exit()
            if o in ("-c", "--connection-string"):
                url = "uno:" + a + ";urp;StarOffice.ComponentContext"
            if o == "--html":
                filterName = "HTML (StarWriter)"

        print filterName
        if not len(args):
            usage()
            sys.exit()

        ctxLocal = uno.getComponentContext()
        smgrLocal = ctxLocal.ServiceManager

        resolver = smgrLocal.createInstanceWithContext(
            "com.sun.star.bridge.UnoUrlResolver", ctxLocal)
        ctx = resolver.resolve(url)
        smgr = ctx.ServiceManager

        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop",
                                                 ctx)

        cwd = systemPathToFileUrl(getcwd())
        outProps = (PropertyValue("FilterName", 0, filterName, 0),
                    PropertyValue("OutputStream", 0, OutputStream(), 0))
        inProps = PropertyValue("Hidden", 0, True, 0),
        for path in args:
            try:
                fileUrl = uno.absolutize(cwd, systemPathToFileUrl(path))
                doc = desktop.loadComponentFromURL(fileUrl, "_blank", 0,
                                                   inProps)

                if not doc:
                    raise UnoException(
                        "Couldn't open stream for unknown reason", None)

                doc.storeToURL("private:stream", outProps)
            except IOException, e:
                sys.stderr.write("Error during conversion: " + e.Message +
                                 "\n")
                retVal = 1
            except UnoException, e:
                sys.stderr.write("Error (" + repr(e.__class__) +
                                 ") during conversion:" + e.Message + "\n")
                retVal = 1
Example #5
0
def main():
    retVal = 0
    doc = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "hc:",["help", "connection-string=" , "html"])
        format = None
        url = "uno:socket,host=localhost,port=2002;urp;StarOffice.ComponentContext"
        filterName = "Text (Encoded)"
        for o, a in opts:
            if o in ("-h", "--help"):
                usage()
                sys.exit()
            if o in ("-c", "--connection-string" ):
                url = "uno:" + a + ";urp;StarOffice.ComponentContext"
            if o == "--html":
                filterName = "HTML (StarWriter)"
            
        print filterName
        if not len( args ):
              usage()
              sys.exit()
              
        ctxLocal = uno.getComponentContext()
        smgrLocal = ctxLocal.ServiceManager

        resolver = smgrLocal.createInstanceWithContext(
                 "com.sun.star.bridge.UnoUrlResolver", ctxLocal )
        ctx = resolver.resolve( url )
        smgr = ctx.ServiceManager

        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx )

        cwd = systemPathToFileUrl( getcwd() )
        outProps = (
            PropertyValue( "FilterName" , 0, filterName , 0 ),
            PropertyValue( "OutputStream",0, OutputStream(),0))
        inProps = PropertyValue( "Hidden" , 0 , True, 0 ),
        for path in args:
            try:
                fileUrl = uno.absolutize( cwd, systemPathToFileUrl(path) )
                doc = desktop.loadComponentFromURL( fileUrl , "_blank", 0,inProps)

                if not doc:
                    raise UnoException( "Couldn't open stream for unknown reason", None )

                doc.storeToURL("private:stream",outProps)
            except IOException, e:
                sys.stderr.write( "Error during conversion: " + e.Message + "\n" )
                retVal = 1
            except UnoException, e:
                sys.stderr.write( "Error ("+repr(e.__class__)+") during conversion:" + e.Message + "\n" )
                retVal = 1
Example #6
0
def main(host, port, path, pagecountlimit):
    retVal = 0
    pagecountlimit = '50'
    doc = None

    url = "uno:socket,host=%s,port=%d;urp;StarOffice.ComponentContext" % (host,
                                                                          port)

    ctxLocal = uno.getComponentContext()
    smgrLocal = ctxLocal.ServiceManager

    resolver = smgrLocal.createInstanceWithContext(
        "com.sun.star.bridge.UnoUrlResolver", ctxLocal)
    ctx = resolver.resolve(url)
    smgr = ctx.ServiceManager

    desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)

    cwd = systemPathToFileUrl(getcwd())

    outProps = (
        #PropertyValue( "FilterName" , 0, "StarOffice XML (Writer)" , 0 ),
        PropertyValue("OutputStream", 0, OutputStream(), 0), )
    inProps = (PropertyValue("Hidden", 0, True, 0), )
    try:
        fileUrl = uno.absolutize(cwd, systemPathToFileUrl(path))
        doc = desktop.loadComponentFromURL(fileUrl, "_blank", 0, inProps)

        if not doc:
            raise UnoException("Couldn't open stream for unknown reason", None)

        # pdb.set_trace()

        try:
            cursor = doc.getCurrentController().getViewCursor()
            cursor.jumpToLastPage()
            pagecount = cursor.getPage()
            if pagecount > int(pagecountlimit):
                raise UnoException(
                    "Input document has %d pages which exceeeds the page count limit of %d."
                    % (pagecount, int(pagecountlimit)), None)
        except AttributeError:
            # opened picture files will not behave, but do not need to have their page counted
            pass

        doc.storeToURL("private:stream", outProps)
    except IOException, e:
        sys.stderr.write("Error during conversion: " + e.Message + "\n")
        retVal = 1
Example #7
0
def main(host, port, path, pagecountlimit):
    retVal = 0
    pagecountlimit = '50'
    doc = None

    url = "uno:socket,host=%s,port=%d;urp;StarOffice.ComponentContext" % (host, port)

    ctxLocal = uno.getComponentContext()
    smgrLocal = ctxLocal.ServiceManager

    resolver = smgrLocal.createInstanceWithContext(
             "com.sun.star.bridge.UnoUrlResolver", ctxLocal )
    ctx = resolver.resolve( url )
    smgr = ctx.ServiceManager

    desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx )

    cwd = systemPathToFileUrl( getcwd() )

    outProps = (
        #PropertyValue( "FilterName" , 0, "StarOffice XML (Writer)" , 0 ),
        PropertyValue( "OutputStream",0, OutputStream(),0),)
    inProps = (PropertyValue( "Hidden" , 0 , True, 0 ),)
    try:
        fileUrl = uno.absolutize( cwd, systemPathToFileUrl(path) )
        doc = desktop.loadComponentFromURL( fileUrl, "_blank", 0, inProps)

        if not doc:
            raise UnoException( "Couldn't open stream for unknown reason", None )

        # pdb.set_trace()

        try:
            cursor = doc.getCurrentController().getViewCursor()
            cursor.jumpToLastPage()
            pagecount = cursor.getPage()
            if pagecount > int(pagecountlimit):
                raise UnoException( "Input document has %d pages which exceeeds the page count limit of %d." % (pagecount, int(pagecountlimit)), None )
        except  AttributeError:
             # opened picture files will not behave, but do not need to have their page counted
             pass

        doc.storeToURL("private:stream",outProps)
    except IOException, e:
        sys.stderr.write( "Error during conversion: " + e.Message + "\n" )
        retVal = 1
def main():
    retVal = 0
    doc = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "hc:o:f:", ["help", "connection-string=", "html"])
        url = "uno:socket,host=localhost,port=2004;urp;StarOffice.ComponentContext"
        filterName = "Text (encoded)"
        outputFile = "/tmp/ssnextract.dat"
        for o, a in opts:
            if o in ("-h", "--help"):
                usage()
                sys.exit()
            if o in ("-c", "--connection-string"):
                url = "uno:" + a + ";urp;StarOffice.ComponentContext"
            if o == "--html":
                filterName = "HTML (StarWriter)"
            if o == "-o":
                outputFile = a
            if o == "-f":
                filterName = a

        if not len(args):
            usage()
            sys.exit()
        
        ctxLocal = uno.getComponentContext()
        smgrLocal = ctxLocal.ServiceManager

        resolver = smgrLocal.createInstanceWithContext(
                 "com.sun.star.bridge.UnoUrlResolver", ctxLocal)
        ctx = resolver.resolve(url)
        smgr = ctx.ServiceManager

        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)

        cwd = systemPathToFileUrl(getcwd())
        outProps = (
            PropertyValue("FilterName" , 0, filterName, 0)
        )
        inProps = PropertyValue("Hidden", 0 , True, 0),
        for path in args:
            try:
                if outputFile is None:
                    outputFile = path + ".txt"
                fileUrl = uno.absolutize(cwd, systemPathToFileUrl(path))
                outputUrl = uno.absolutize(cwd, systemPathToFileUrl(outputFile))
                doc = desktop.loadComponentFromURL(fileUrl , "_blank", 0, inProps)

                if not doc:
                    raise UnoException("Could not open stream for unknown reason", None)
                
                srd = doc.createReplaceDescriptor()
                srd.setPropertyValue("SearchRegularExpression", True)
                srd.setSearchString("[0-9]{3}(-)?[0-9]{2}(-)?([0-9]{4})\\b")
                srd.setReplaceString("***$1**$2$3")

                doc.replaceAll(srd)
                doc.storeToURL(outputUrl, ())
            except IOException as e:
                sys.stderr.write("Error during conversion: " + e.Message + "\n")
                retVal = 1
            except UnoException as e:
                sys.stderr.write("Error (" + repr(e.__class__) + ") during conversion: " + e.Message + "\n")
                retVal = 1
            if doc:
                doc.dispose()

    except UnoException as e:
        sys.stderr.write("Error (" + repr(e.__class__) + "): " + e.Message + "\n")
        retVal = 1
    except getopt.GetoptError as e:
        sys.stderr.write(str(e) + "\n")
        usage()
        retVal = 1

    sys.exit(retVal)
for dir in dirs:
#dir = dirs[0]
#if True: 
    os.chdir(dir)
    files = os.listdir(dir)
    cwd = systemPathToFileUrl( os.getcwd() )

    print "for directory '" + dir + "' we found " + str(len(files)) + " files."

    for file in files:
        if file.endswith('.xml'):
            print 'skipping: ' + file
            continue

        try:
            inProps = (PropertyValue( "Hidden" , 0 , True, 0 ),)
            fileUrl = uno.absolutize( cwd, systemPathToFileUrl(file) )
            doc = desktop.loadComponentFromURL( fileUrl, "_blank", 0, inProps)

            cursor = doc.getCurrentController().getViewCursor()
            cursor.jumpToLastPage()
            page_count = cursor.getPage()
            print file + ',' + str(page_count)
            result.write(str(page_count) + '\n')
            result.flush()
            doc.dispose()
        except:
            pass

result.close()
Example #10
0
        resolver = smgrLocal.createInstanceWithContext(
                 "com.sun.star.bridge.UnoUrlResolver", ctxLocal )
        ctx = resolver.resolve( url )
        smgr = ctx.ServiceManager

        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx )

        cwd = systemPathToFileUrl( getcwd() )
        outProps = (
            PropertyValue( "FilterName" , 0, filterName , 0 ),
            )
        inProps = PropertyValue( "Hidden" , 0 , True, 0 ),
        for path in args:
		try:
			fileUrl = uno.absolutize( cwd, systemPathToFileUrl(path + ".sxw") )
			doc = desktop.loadComponentFromURL( fileUrl , "_blank", 0,inProps)

			if not doc:
				raise UnoException( "Couldn't open " + fileUrl, None )

			saveUrl = uno.absolutize( cwd, systemPathToFileUrl(path) )
			doc.storeToURL(saveUrl + "." + extension ,outProps)
        
		except IOException, e:
			sys.stderr.write( "Error during conversion: " + e.Message + "\n" )
			retVal = 1
		except UnoException, e:
			sys.stderr.write( "Error ("+repr(e.__class__)+") during conversion:" + e.Message + "\n" )
			retVal = 1
	if doc:
Example #11
0
def main():
    retVal = 0
    doc = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "hc:o:f:s:r:x:",
                                   ["help", "connection-string="])
        url = "uno:socket,host=localhost,port=2004;urp;StarOffice.ComponentContext"
        outputPath = "/tmp/"
        search = ""
        replace = "*"
        regex = False
        for o, a in opts:
            if o in ("-h", "--help"):
                usage()
                sys.exit()
            elif o in ("-c", "--connection-string"):
                url = "uno:" + a + ";urp;StarOffice.ComponentContext"
            elif o == "-o":
                outputPath = a
            elif o == "-s":
                search = a
            elif o == "-r":
                replace = a
            elif o == "-x":
                regex = a == "true"

        if not len(args):
            usage()
            sys.exit()

        ctxLocal = uno.getComponentContext()
        smgrLocal = ctxLocal.ServiceManager

        resolver = smgrLocal.createInstanceWithContext(
            "com.sun.star.bridge.UnoUrlResolver", ctxLocal)
        ctx = resolver.resolve(url)
        smgr = ctx.ServiceManager

        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop",
                                                 ctx)

        cwd = systemPathToFileUrl(getcwd())
        inProps = PropertyValue("Hidden", 0, True, 0),
        for path in args:
            try:
                outputFile = outputPath
                fileUrl = uno.absolutize(cwd, systemPathToFileUrl(path))
                outputUrl = uno.absolutize(cwd,
                                           systemPathToFileUrl(outputFile))
                doc = desktop.loadComponentFromURL(fileUrl, "_blank", 0,
                                                   inProps)

                if not doc:
                    raise UnoException(
                        "Could not open stream for unknown reason", None)

                srd = doc.createReplaceDescriptor()
                srd.setPropertyValue("SearchRegularExpression", regex)
                srd.setSearchString(search)
                srd.setReplaceString(replace)

                doc.replaceAll(srd)
                doc.storeToURL(outputUrl, ())
            except IOException as e:
                sys.stderr.write("Error during conversion: " + e.Message +
                                 "\n")
                retVal = 1
            except UnoException as e:
                sys.stderr.write("Error (" + repr(e.__class__) +
                                 ") during conversion: " + e.Message + "\n")
                retVal = 1
            if doc:
                doc.dispose()

    except UnoException as e:
        sys.stderr.write("Error (" + repr(e.__class__) + "): " + e.Message +
                         "\n")
        retVal = 1
    except getopt.GetoptError as e:
        sys.stderr.write(str(e) + "\n")
        usage()
        retVal = 1

    sys.exit(retVal)
Example #12
0
    ctxLocal = uno.getComponentContext()
    smgrLocal = ctxLocal.ServiceManager

    resolver = smgrLocal.createInstanceWithContext(
        "com.sun.star.bridge.UnoUrlResolver", ctxLocal)
    ctx = resolver.resolve(url)
    smgr = ctx.ServiceManager

    desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)

    cwd = systemPathToFileUrl(getcwd())
    outProps = (PropertyValue("FilterName", 0, filterName, 0), )
    inProps = PropertyValue("Hidden", 0, True, 0),
    for path in args:
        try:
            fileUrl = uno.absolutize(cwd, systemPathToFileUrl(path + ".sxw"))
            doc = desktop.loadComponentFromURL(fileUrl, "_blank", 0, inProps)

            if not doc:
                raise UnoException("Couldn't open " + fileUrl, None)

            saveUrl = uno.absolutize(cwd, systemPathToFileUrl(path))
            doc.storeToURL(saveUrl + "." + extension, outProps)

        except IOException, e:
            sys.stderr.write("Error during conversion: " + e.Message + "\n")
            retVal = 1
        except UnoException, e:
            sys.stderr.write("Error (" + repr(e.__class__) +
                             ") during conversion:" + e.Message + "\n")
            retVal = 1
def main():
    retVal = 0
    doc = None

    try:
        opts, args = getopt.getopt(sys.argv[1:], "hc:o:", ["help", "connection-string="])
        url = "uno:socket,host=localhost,port=2004;urp;StarOffice.ComponentContext"
        outputPath = "/tmp/"
        for o, a in opts:
            if o in ("-h", "--help"):
                usage()
                sys.exit()
            elif o in ("-c", "--connection-string"):
                url = "uno:" + a + ";urp;StarOffice.ComponentContext"
            elif o == "-o":
                outputPath = a

        if not len(args):
            usage()
            sys.exit()
        
        ctxLocal = uno.getComponentContext()
        smgrLocal = ctxLocal.ServiceManager

        resolver = smgrLocal.createInstanceWithContext(
                 "com.sun.star.bridge.UnoUrlResolver", ctxLocal)
        ctx = resolver.resolve(url)
        smgr = ctx.ServiceManager

        desktop = smgr.createInstanceWithContext("com.sun.star.frame.Desktop", ctx)

        cwd = systemPathToFileUrl(getcwd())
        inProps = PropertyValue("Hidden", 0 , True, 0),
        for path in args:
            try:
                outputFile = outputPath
                fileUrl = uno.absolutize(cwd, systemPathToFileUrl(path))
                outputUrl = uno.absolutize(cwd, systemPathToFileUrl(outputFile))
                doc = desktop.loadComponentFromURL(fileUrl , "_blank", 0, inProps)

                if not doc:
                    raise UnoException("Could not open stream for unknown reason", None)

                doc.getDocumentProperties().resetUserData("Properties Removed")

                doc.storeToURL(outputUrl, ())
            except IOException as e:
                sys.stderr.write("Error during update: " + e.Message + "\n")
                retVal = 1
            except UnoException as e:
                sys.stderr.write("Error (" + repr(e.__class__) + ") during update: " + e.Message + "\n")
                retVal = 1
            if doc:
                doc.dispose()

    except UnoException as e:
        sys.stderr.write("Error (" + repr(e.__class__) + "): " + e.Message + "\n")
        retVal = 1
    except getopt.GetoptError as e:
        sys.stderr.write(str(e) + "\n")
        usage()
        retVal = 1

    sys.exit(retVal)
Example #14
0
File: test.py Project: hanya/pyuno3
 def test_absolutize(self):
     relative_path = "../.."
     url = "file:///home/foo/bar/hoge/123.ods"
     desired = "file:///home/foo/bar/"
     result = uno.absolutize(url, relative_path)
     self.assertEqual(result, desired)