Esempio n. 1
0
    def push(self, doc_name, library_name, module_name, source, save=False):
        """Pushes the module code for `macro_name` from `source`.

        If the library does not exist, it is created.

        If `save` is truthy, the updated document will be saved to disk.

        Returns the updated document.

        >>> Exchange().push(doc_name='Untitled 1',
        ...                 library_name='Standard', module_name='Fraggle',
        ...                 source=open('project/src/basic/fraggle.bas'))
        ... # doctest: +SKIP
        """
        # TODO: There should probably be some exception-handling in here.
        doc, libs = context.resolve_doc_name(self.context, self.smgr,
                                             self.desktop, doc_name)
        joined_source = '\n'.join(line.rstrip('\n') for line in source)
        try:
            libs[library_name][module_name] = joined_source
        except KeyError:
            libs.createLibrary(library_name)
            libs[library_name][module_name] = joined_source

        if save:
            doc.store()
        else:
            # There doesn't appear to be any way to cause an open Basic editor
            # to change its save icon to active.
            # That functionality seems to be semi-broken anyway,
            # so probably people will be expecting to save the document
            # in order to be sure.
            libs.setModified(True)
            doc.setModified(True)
        return doc
Esempio n. 2
0
    def invoke(self, doc_name, macro_name):
        """Invoke the macro in the running OOo instance.

        `macro_name` should be a fully-qualified macro name,
        for example 'Standard.Module1.main'.
        """
        doc, libs = context.resolve_doc_name(self.context, self.smgr,
                                             self.desktop, doc_name)
        document.invoke_macro(doc, macro_name)
Esempio n. 3
0
    def pull(self, doc_name, library_name, module_name):
        """Gets the module code for `macro_name` from `source`.

        Yields the lines of source.

        >>> Exchange().pull(doc_name: 'Untitled 1',
        ...                 library_name: 'Standard',
        ...                 module_name: 'Module1')
        ... # doctest: +SKIP
        ['sub main',
         '    MsgBox("This is the main macro in Standard.Module1.")',
         'end sub']
        """
        doc, libs = context.resolve_doc_name(self.context, self.smgr,
                                             self.desktop, doc_name)
        lib = libs[library_name][module_name]
        return (line + "\n" for line in lib.rstrip('\n').split('\n'))