You are not logged in.

#1 2010-10-21 08:39:24

ELWisty
Member
From: Helsinki, Finland
Registered: 2009-10-13
Posts: 55
Website

[SOLVED] Help for fixing an openbox pipe menu script?

Hi,

Anybody out there who could help me with this? Am trying to sort out a firefox bookmarks pipe menu which worked before the python upgrade. Script:

#!/usr/bin/python2

import sqlite3
from xml.sax.saxutils import quoteattr

import shutil
import tempfile

browser = 'firefox'
ffsqlite= '/home/maria/.mozilla/firefox/61z24o9x.default/places.sqlite'

def print_label(title, url):
    print '<item label=%s>' % (browser, quoteattr(title.encode('utf-8')))
    print '<action name="Execute">'
    print '<command>%s %</command>' % (browser, quoteattr(url.encode('utf-8')))
    print '</action>'
    print '</item>'

def rbuild_tree(id, title, conn, first_run=False):
        if first_run:
            print '<openbox_pipe_menu>'
        else:
            print '<menu id="%s" label=%s>' % (id, quoteattr(title.encode('utf-8')))

        c2 = conn.cursor()
        c2.execute('select id, title, type from moz_bookmarks b where parent=? and type=2;', (id, ))
        for sid, stitle, type in c2:
            rbuild_tree(sid, stitle, conn)
        c2.execute('select b.title, p.title, p.url from moz_bookmarks b, moz_places p where b.fk = p.id and b.type=1 and parent=?;', (id, ))
        for btitle, ptitle, url in c2:
            if url == None or url.startswith('place'):
                continue
            if btitle != None:
                print_label(btitle, url)
            else:
                print_label(btitle, url)

        if first_run:
            print '</openbox_pipe_menu>'
        else:
            print '</menu>'

def main():

    tf = tempfile.NamedTemporaryFile('r', suffix='.sqlite')

    shutil.copyfile(ffsqlite, tf.name)
    conn = sqlite3.connect(tf.name)

    rbuild_tree(2, '', conn, True)

    conn.close()
    tf.close()

if __name__ == '__main__':
    main()

The first line was originally:

#!/usr/bin/env python

Which I changed to the current because of the python upgrade. Otherwise the script is unchanged, This worked for another pipe menu, but here I get:

Traceback (most recent call last):
  File "/home/maria/.config/openbox/scripts/ffbookmarks.py", line 56, in <module>
    main()
  File "/home/maria/.config/openbox/scripts/ffbookmarks.py", line 50, in main
    rbuild_tree(2, '', conn, True)
  File "/home/maria/.config/openbox/scripts/ffbookmarks.py", line 28, in rbuild_tree
    rbuild_tree(sid, stitle, conn)
  File "/home/maria/.config/openbox/scripts/ffbookmarks.py", line 34, in rbuild_tree
    print_label(btitle, url)
  File "/home/maria/.config/openbox/scripts/ffbookmarks.py", line 13, in print_label
    print '<item label=%s>' % (browser, quoteattr(title.encode('utf-8')))
TypeError: not all arguments converted during string formatting

Something I'm missing that I should've done here?

Many thanks in advance for any help.

Last edited by ELWisty (2010-10-25 11:08:32)

Offline

#2 2010-10-21 15:07:42

awkwood
Member
From: .au <=> .ca
Registered: 2009-04-23
Posts: 91

Re: [SOLVED] Help for fixing an openbox pipe menu script?

Hi ELWisty,

You could modify your code to use str.format rather than % which would make it compatible with both versions of Python.

http://bugs.python.org/issue8359#msg102765
http://www.python.org/dev/peps/pep-3101/

Offline

#3 2010-10-23 06:36:49

quigybo
Member
Registered: 2009-01-15
Posts: 223

Re: [SOLVED] Help for fixing an openbox pipe menu script?

ELWisty wrote:
  File "/home/maria/.config/openbox/scripts/ffbookmarks.py", line 13, in print_label
    print '<item label=%s>' % (browser, quoteattr(title.encode('utf-8')))
TypeError: not all arguments converted during string formatting

I don't see how it worked before the upgrade either. You pass the string formatting operator % a tuple with two values, but have only one %x identifier in the string. You need something like this:

print '<item label="%s %s">' % (browser, quoteattr(title.encode('utf-8')))

The same will happen on line 15.

Offline

#4 2010-10-23 08:10:37

ELWisty
Member
From: Helsinki, Finland
Registered: 2009-10-13
Posts: 55
Website

Re: [SOLVED] Help for fixing an openbox pipe menu script?

quigybo wrote:
ELWisty wrote:
  File "/home/maria/.config/openbox/scripts/ffbookmarks.py", line 13, in print_label
    print '<item label=%s>' % (browser, quoteattr(title.encode('utf-8')))
TypeError: not all arguments converted during string formatting

I don't see how it worked before the upgrade either. You pass the string formatting operator % a tuple with two values, but have only one %x identifier in the string. You need something like this:

print '<item label="%s %s">' % (browser, quoteattr(title.encode('utf-8')))

The same will happen on line 15.

Hm, I've done that. Now running the script in command line lists the pipe menu contents but it still doesn't work in the openbox menu, i.e. the pipe menu doesn't open up.

I have the menu entry as:

<menu execute="/usr/bin/python2 ~/.config/openbox/scripts/ffbookmarks.py" id="ff-menu" label="Firefox Bookmarks"/>

So I don't quite see where the error is.

Offline

#5 2010-10-25 11:08:02

ELWisty
Member
From: Helsinki, Finland
Registered: 2009-10-13
Posts: 55
Website

Re: [SOLVED] Help for fixing an openbox pipe menu script?

D'oh. My own fault (of course): for some stupid reason I had added the 'browser' value to line 13 of the script, wasn't there when I got the script.

Offline

Board footer

Powered by FluxBB