Broken examples

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • norseman

    Broken examples


    I'm only talking about IPC related.
    I have googled, yahooed, and so forth for several months now. ALL
    examples I've come across have failed including those pertinent in the
    Python doc area.

    Outline:
    cd somedir
    ls -1 *.xls >thislist #ls hyphen one
    python process.py
    (yes - ls can go here if wanted. easier to edit outside)
    open thislist
    loop until done
    start excel (or scalc)
    have it open file
    have it save file as a .csv (or .dbf)
    close excell (or scalc)

    Would seem to be a trivial exercise.
    Starting Excel or any other executable in system path works fine.
    popen3 opens whatever and reports no errors. r,w,and e all check as
    being created.

    r,w,e= os.popen3('ls -l')
    print r.read() # works as expected

    ALL attempts to send instructions to Excel or scalc FAIL COMPLETELY.
    Actually, any attempt to communicate with a 'Point'n'Click' program
    fails without errors being cited. They don't use redirectable command
    line interfaces (like piping between programs) do they? :)

    Trying to use the examples I have found that supposedly setup IPC's of
    one type or another have all failed with errors that point to things
    that make no sense in the first place.

    Before you post a code example or a link to one be kind enough to run it
    yourself first. You may get a surprise. The OOo examples do not work.
    Not even when switching my system to their version. One problem they
    have is asking a general user to change to places the user has no place
    being and then to work there without permissions. I guess somebody
    insists on doing all their work with root clearance down in the middle
    of the vendor's tree. I don't think that's a healthy way to do things,
    do you?

    In OOo in particular, using their version of VBA one can create the
    macro and even port it to python. If one found the correct Microsoft
    suite docs I suspect that same could be done there too. But that doesn't
    activate it from a python control. As for setting the macro to run at
    startup, well... maybe I had other uses in mind today???? Besides the
    moment I change it, coworker in other room is going to decide to... :)

    Let's stick to Microsoft Office and OpenSource products for now. My
    final goal will require specific conversations with a commercial vendor.
    I would like those spread sheets working though.


    Thanks

    Steve
    norseman@hughes .net
  • Lawrence D'Oliveiro

    #2
    Re: Broken examples

    In message <mailman.574.12 16863664.922.py thon-list@python.org >, norseman
    wrote:
    The OOo examples do not work.
    I have done OOo scripting in Python. What exactly does not work?

    Comment

    • norseman

      #3
      Re: Broken examples


      Lawrence D'Oliveiro wrote:
      In message <mailman.574.12 16863664.922.py thon-list@python.org >, norseman
      wrote:
      >
      >The OOo examples do not work.
      >
      I have done OOo scripting in Python. What exactly does not work?
      --

      >
      =============== ========


      file: z.scr
      ----------
      #!/bin/bash

      cd /opt/openoffice.org2 .0/program

      soffice "-accept=socket,h ost=localhost,p ort=2002;urp;" &
      sleep 9

      ../python ./zhw.py

      echo "Did this Run?"
      # end of file
      ---------

      file: zhw.py
      ---------
      import uno

      # get the uno component context from the PyUNO runtime
      localContext = uno.getComponen tContext()

      # create the UnoUrlResolver
      resolver =
      localContext.Se rviceManager.cr eateInstanceWit hContext("com.s un.star.b
      ridge.UnoUrlRes olver", localContext )

      # connect to the running office
      ctx =
      resolver.resolv e("uno:socket,h ost=localhost,p ort=2002;urp;St arOffice.Compo
      nentContext" )
      smgr = ctx.ServiceMana ger

      # get the central desktop object
      desktop = smgr.createInst anceWithContext ( "com.sun.star.f rame.Desktop",c tx)

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

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

      # create a cursor
      cursor = text.createText Cursor()

      # insert the text into the document
      text.insertStri ng( cursor, "Hello World", 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 (getPropertyVal ue).
      ctx.ServiceMana ger
      # end of file
      ------------

      file: results
      -----------
      SysOp(P):sh z.scr
      Traceback (most recent call last):
      File "./zhw.py", line 20, in ?
      text = model.Text
      AttributeError: Text
      Did this Run?
      SysOp(P):====== =======NO!!!!!!
      -----------------------

      Haven't found any specific to scalc.
      The zhw contents is closest to working I have found to date.
      The z script was used to get to stated place and minimize typos.
      As results shows - I ran as root. As user it screams lots. (Permissions)

      The above is best effort so far. Others before it were even worse.

      If you have working code I would like to tryout your linkage (process).
      Before you send anything, can you use python to have scalc open a .xls
      and save it as a csv? I can get python to have scalc open a specific
      file and then point'n'click myself, but that isn't productive. I cannot
      get scalc to do a saveas instruction issued by a python program. I have
      no intentions of staying up all night pointing and clicking. Humans
      think, computers do the repetitive. Yes? Besides, it is far easier to
      train the computer than to train the ..... :)


      Any help is appreciated.

      Steve
      norseman@hughes .net

      Comment

      • Lawrence D'Oliveiro

        #4
        Re: Broken examples

        In message <mailman.609.12 16919661.922.py thon-list@python.org >, norseman
        wrote:
        Lawrence D'Oliveiro wrote:
        >
        >In message <mailman.574.12 16863664.922.py thon-list@python.org >, norseman
        >wrote:
        >>
        >>The OOo examples do not work.
        >>
        >I have done OOo scripting in Python. What exactly does not work?
        >
        soffice "-accept=socket,h ost=localhost,p ort=2002;urp;" &
        sleep 9
        >
        ./python ./zhw.py
        I've never tried that. I've run Python scripts from the "Tools/Macros/Run
        Macro..." dialog.

        Comment

        • Tim Roberts

          #5
          Re: Broken examples

          norseman <norseman@hughe s.netwrote:
          >
          >I'm only talking about IPC related.
          >I have googled, yahooed, and so forth for several months now. ALL
          >examples I've come across have failed including those pertinent in the
          >Python doc area.
          >
          >Outline:
          > cd somedir
          > ls -1 *.xls >thislist #ls hyphen one
          > python process.py
          (yes - ls can go here if wanted. easier to edit outside)
          > open thislist
          > loop until done
          > start excel (or scalc)
          > have it open file
          > have it save file as a .csv (or .dbf)
          > close excell (or scalc)
          >
          >Would seem to be a trivial exercise.
          Excel is a COM-driven application. You have to drive it through the object
          model.

          import win32com.client
          excel = win32com.client .Dispatch( 'Excel.Applicat ion' )
          xlCSV = 6
          ...
          for nm in list_of_file_na mes:
          csv = os.path.splitex t( nm )[0] + '.csv'
          wb = excel.Workbooks .Open( nm )
          wb.SaveAs( csv, xlCSV )
          wb.Close()

          If you want to watch the progress, add "excel.Visible= 1" after the
          dispatch.
          --
          Tim Roberts, timr@probo.com
          Providenza & Boekelheide, Inc.

          Comment

          Working...