Scrapbook+ on FF 3.5 beta, script to convert original scrapbook pages so they can be used with plus

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



Hi,

The new FF 3.5 beta doesn't have the original scrapbook, it has the new
improved version scrapbook+.  When I copied over the data from FF3
scrapbook it wasn't recognized by the new version.  I didn't want to
lose all the captured pages I had saved over the years, so I wrote a
one off python program to convert the original scrapbook rdf to a
version suitable for use with scrapbook+. The data records are
identical and need no change, only the rdf now has an index list.  It
has worked for me and I am now able to use all my original pages, but
use it at your own risk. It prints all the relevant records so there
will be lots of output.  It won't run automatically, you need to type
python convert_scrapbook_to_plus.py. And it doesn't move the data, you
will have to copy that from the old firefox scrapbook data
directory to the data directory for the new firefox scrapbook+ version.
And merge the new scrapbook.rdf with the converted one from the program.
Change the filenames and paths to reflect your situation and names.
Entering them on the command line should work (I didn't test it), but it
is just much easier to cut and paste into the file.  The top
parameters don't matter, change only the bottom input_filename and
output_filename in the file. 

All that!!!  Is it worth all that trouble?  It was for me.  If it is
for you, here it is:

import os
import string
import re
import sys
import subprocess

def
convert_scrapbook_to_plus(input_filename='/home/stan/.mozilla/firefox/9lae9qev.default/ScrapBook/scrapbookf10.rdf',
output_filename='/home/stan/.mozilla/firefox/9lae9qev.default/ScrapBook/scrapbookf10_convert.rdf'):

  """  Read a scrapbook file in the old format, and write a new plus
  style data file so the pages can be listed in scrapbook plus.
  """

  for line in sys.argv:
    print line
  if len(sys.argv) not in (1, 3):  # need an input and output file
    help ()  # exit with some instruction
  # parse the rest of the command line arguments as filenames
  if len(sys.argv) == 3:  # both an input and output file
    input_filename = sys.argv [1]
    output_filename = sys.argv [2]
  print input_filename
  print output_filename
  scrap_list = convert_file (input_filename)
  save_file (input_filename, output_filename, scrap_list)

def convert_file (input_filename):
  """" Parse an rdf file and save the converted description records
       to a list. """

  # Compile a search for Description
  descsrch = re.compile('Description')
  scrap_list = []
  infile = open (input_filename, 'r')
  inline = infile.readline()
  while len (inline) != 0:
    if len(inline) > 0:
      if (descsrch.search(inline) != None):   # Description line
        print inline
        inline = inline [:-1]
        inline = inline.replace ("Description", "li")
        inline = inline.replace ("about", "resource")
        inline += "/>\n"
        scrap_list.append (inline)
    inline = infile.readline()
  infile.close()
  scrap_list.reverse()
  print scrap_list
  return scrap_list

def save_file (input_filename, output_filename, scrap_list):
  """" Save the plus version of the rdf file using the old version and
the list records.  """

  infile = open (input_filename, 'r')
  outfile = open (output_filename, 'w')
  inline = infile.readline()
  while len (inline) != 0:
    outfile.write (inline)
    if len(inline) > 0:
      offset = inline.find('22-rdf-syntax-ns')
      if offset != -1:  # xlmins:RDF line
        print inline
        outline = ("  " + '<RDF:Seq RDF:about="urn:scrapbook:root">\n')
        outfile.write (outline)
        for indexline in scrap_list:
          outline = ("    " + indexline)
          outfile.write (outline)
        outline = ("  " + "</RDF:Seq>\n")
        outfile.write (outline)
    inline = infile.readline()
  infile.close()
  outfile.close()

def help ():
  """ Print simple usage instructions for convert_scrapbook_to_plus.py.
"""

  print ("Usage for convert_scrapbook_to_plus.py is:")
  print ("python convert_scrapbook_to_plus.py input_filename, output_filename") 
  print ("python convert_scrapbook_to_plus.py")
  print ("""The input file and output file can be paths ending in a filename.""") 
  print ("""Couple of examples: 
    python convert_scrapbook_to_plus.py in.rdf out.rdf 
    will convert in.rdf to out.rdf, out.rdf in new plus format. 
    python convert_scrapbook_to_plus.py will convert the input rdf filename in
  the program to the output rdf program in the file.""")
  sys.exit()


if __name__ == '__main__':
  convert_scrapbook_to_plus(input_filename='/home/stan/.mozilla/firefox/9lae9qev.default/ScrapBook/scrapbookf10.rdf', 
                    output_filename='/home/stan/.mozilla/firefox/9lae9qev.default/ScrapBook/scrapbookf10_convert.rdf')

-- 
fedora-list mailing list
fedora-list@xxxxxxxxxx
To unsubscribe: https://www.redhat.com/mailman/listinfo/fedora-list
Guidelines: http://fedoraproject.org/wiki/Communicate/MailingListGuidelines

[Index of Archives]     [Current Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Yosemite News]     [Yosemite Photos]     [KDE Users]     [Fedora Tools]     [Fedora Docs]

  Powered by Linux