Logo Search packages:      
Sourcecode: zim version File versions  Download package

def zim::notebook::Notebook::upgrade_notebook (   self,
  callback = None 
)

Tries to update older notebook to format supported by the
latest version.

Definition at line 1095 of file notebook.py.

01095                                                :
            '''Tries to update older notebook to format supported by the
            latest version.
            '''
            # Currently we just assume upgrade from zim < 0.43
            # may need to add more sophisticated logic later..
            #
            # We check for links based on old pagename cleanup rules
            # also we write every page, just to be sure they are stored in
            # the latest wiki format.
            logger.info('Notebook update started')
            self.index.ensure_update(callback=callback)

            candidate_re = re.compile('[\W_]')
            for page in self.walk():
                  if callback:
                        cont = callback(page)
                        if not cont:
                              logger.info('Notebook update cancelled')
                              return

                  try:
                        tree = page.get_parsetree()
                  except:
                        # Some issue we can't fix
                        logger.exception('Error while parsing page: "%s"', page.name)
                        tree = None

                  if tree is None:
                        continue

                  changed = False
                  for tag in tree.getiterator('link'):
                        href = tag.attrib['href']
                        type = link_type(href)
                        if type == 'page' and candidate_re.search(href):
                              # Skip if we can resolve it already
                              try:
                                    link = self.resolve_path(href, source=page)
                                    link = self.get_page(link)
                              except:
                                    pass
                              else:
                                    if link and link.hascontent:
                                          # Do not check haschildren here, children could be placeholders as well
                                          continue

                              # Otherwise check if old version would have found a match
                              try:
                                    newhref = self.cleanup_pathname_zim028(href)
                                    if newhref != href:
                                          link = self.resolve_path(newhref, source=page)
                                          link = self.get_page(link)
                                    else:
                                          link = None
                              except:
                                    pass
                              else:
                                    if link and link.hascontent:
                                          # Do not check haschildren here, children could be placeholders as well
                                          tag.attrib['href'] = newhref
                                          changed = True
                                          logger.info('Changed link "%s" to "%s"', href, newhref)

                  # Store this page
                  try:
                        if changed:
                              page.set_parsetree(tree)

                        self.store_page(page)
                  except:
                        logger.exception('Could not store page: "%s"', page.name)

            # Update the version and we are done
            self.config['Notebook']['version'] = '.'.join(map(str, DATA_FORMAT_VERSION))
            self.config.write()
            logger.info('Notebook update done')

# Need to register classes defining gobject signals
gobject.type_register(Notebook)


class Path(object):


Generated by  Doxygen 1.6.0   Back to index