Re: [Zim-wiki] dump notes to mediawiki, or trac

2009-02-08 Thread Pablo Angulo
Jaap Karssenberg escribió:
> In fact the python port already has a fairly decent parser for the zim
> wiki format that can be used as a base for this kind of work. Your
> code will at least be very useful a example on how to format the trac
> output (btw. from your subject line I assume trac uses the mediawiki
> format - is that correct ?).
>
I think trac wiki format is similar to mediawiki, but there are
differences.
> I will add this piece of code to the python dev tree, so it can be
> used as a basis later.
>
The code is based in observation, I didn't try to read the full
specification of trac. If you have a parser, the whole approach is
doomed. I don't know if it's a good idea to add this code to the tree.
>>  The following python code is a hack, and it might fail on some syntax.
>> I took a choice regarding links with categories: I decided to flatten
>> zim links like [[:Software:note taking:zim|zim]] to wiki entries like
>> [Software_note_taking_zim zim].
>
> I don't know what characters are allowed in page names in trac - is
> there another character that can be used to make the hierarchy more
> obvious ? Or maybe flatten using a double "_" ?
You're right, a double "_"  is better. For mediawiki, it would be
important to take care of "mediawiki categories" too. Trac has a plugin
implemeting "tags", but it's not a standard plugin.

In a few months I'll have time to read and think about zim. I'm looking
forward to reading the python port.
Regards

___
Mailing list: https://launchpad.net/~zim-wiki
Post to : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp


Re: [Zim-wiki] dump notes to mediawiki, or trac

2009-02-08 Thread Jaap Karssenberg

Pablo Angulo wrote:

 I'll wait for the python port, read Jaap's code, and rewrite in the
future as an additional export format, if no one does it before. But, on
the meantime, I'll use this hack and solve problems manually.
  


In fact the python port already has a fairly decent parser for the zim 
wiki format that can be used as a base for this kind of work. Your code 
will at least be very useful a example on how to format the trac output 
(btw. from your subject line I assume trac uses the mediawiki format - 
is that correct ?).


I will add this piece of code to the python dev tree, so it can be used 
as a basis later.



 The following python code is a hack, and it might fail on some syntax.
I took a choice regarding links with categories: I decided to flatten
zim links like [[:Software:note taking:zim|zim]] to wiki entries like
[Software_note_taking_zim zim].


I don't know what characters are allowed in page names in trac - is 
there another character that can be used to make the hierarchy more 
obvious ? Or maybe flatten using a double "_" ?


Thanks a lot Pablo!

Jaap

___
Mailing list: https://launchpad.net/~zim-wiki
Post to : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp


Re: [Zim-wiki] dump notes to mediawiki, or trac

2009-02-05 Thread Pablo Angulo
  Hello:
 I was finally able to change the notes from zim wiki format to trac
wiki format. Just in case other people is interested, I'll post my
solution, despite its defects.

 The following python code is a hack, and it might fail on some syntax.
I took a choice regarding links with categories: I decided to flatten
zim links like [[:Software:note taking:zim|zim]] to wiki entries like
[Software_note_taking_zim zim].

  To use it, call

python trac2zim.py notebook output_folder prefix

  where prefix is a string you put before each wiki page name. It will
fill output_folder with plain text files ready to be loaded with trac-admin:

trac-admin /path/to/project wiki load output_folder

 I'll wait for the python port, read Jaap's code, and rewrite in the
future as an additional export format, if no one does it before. But, on
the meantime, I'll use this hack and solve problems manually.

 Regards

#

# -*- coding: utf-8 -*-
import re
import sys
import os

#buscaCabeceras=re.compile('(={1:5})([^=]*)(={1:5})')
def flatten(linkName):
'''Changes a zim link, possibly with categories, to a trac link

it also removes accents and other spanish special characters
'''
#remove final ':' character and
name=linkName[:-1] if linkName[-1]==':' else linkName
return removeSpecialChars(name.replace(':','_').replace(' ','_'))

def removeSpecialChars(s):
'''certain trac installation reported problems with special chars

other trac systems loaded all files without problem

the problem is only for file names and wiki pages names, not for content
'''
return
s.replace('á','a').replace('é','e').replace('í','i').replace('ó','o').replace('ú','u').replace('ñ','n').replace('Á','A').replace('É','E').replace('Í','I').replace('Ó','O').replace('Ú','U').replace('Ñ','ñ')

cabecera=re.compile("(={1,6})([^=\/]+?)(={1,6})")
inlineVerbatim=re.compile("''([^']+?)''")
#~ multilineVerbatim=re.compile("\n[\t](.+?)\n")
negrita=re.compile('\*\*([^\*]+?)\*\*')
italic=re.compile('\/\/([^\/\n\]]+?)\/\/')
bracketedURL=re.compile('\[\[(http:\/\/[^\|]+)\|([^\|]+?)\]\]')
#TODO: separar links relativos y absolutos
simpleRelLink=re.compile('\[\[([^:][^\|]+?)\]\]')
namedRelLink=re.compile('\[\[([^:][^\|]+?)\|([^\|]+?)\]\]')
simpleAbsLink=re.compile('\[\[:([^\|]+?)\]\]')
namedAbsLink=re.compile('\[\[:([^\|]+?)\|([^\|]+?)\]\]')
images=re.compile('([^\{])\{\{\/(.+?)\}\}')
def translate(nota,prefix1,prefix2):
'''Takes a note in zim format and returns a note in trac format
'''
#duplicate all line breaks
nota=nota.replace('\n','\n\n')
# Headings
mm=cabecera.search(nota)
lista=[]
lastIndex=0
while mm:
lista.append(nota[lastIndex:mm.start()])
gg=mm.groups()
iguales=len(gg[0])
lista.append("="*(7-iguales)+gg[1]+"="*(7-iguales))
lastIndex=mm.end()
mm=cabecera.search(nota,lastIndex)
lista.append(nota[lastIndex:])
nota=''.join(lista)
 
#inlineVerbatim
nota=inlineVerbatim.sub("{{{\\1}}}",nota)
#multiline verbatim
#TODO
#bold
nota=negrita.sub("'''\\1'''",nota)
#italic
nota=italic.sub("''\\1''",nota)

#bracketedURL
nota = bracketedURL.sub("[\\1 \\2]",nota)
#~ #simple links
#~ nota=simpleLink.sub("[wiki:\\1]",nota)
#~ #named links
#~ nota=namedLink.sub("[wiki:\\1 \\2]",nota)
#simple relative links
mm=simpleRelLink.search(nota)
lista=[]
lastIndex=0
while mm:
lista.append(nota[lastIndex:mm.start()])
gg0=mm.groups()[0]
lista.append("[wiki:"+prefix1+prefix2+flatten(gg0)+" "+gg0+"]")
lastIndex=mm.end()
mm=simpleRelLink.search(nota,lastIndex)
lista.append(nota[lastIndex:])
nota=''.join(lista)

mm=simpleAbsLink.search(nota)
lista=[]
lastIndex=0
while mm:
lista.append(nota[lastIndex:mm.start()])
gg0=mm.groups()[0]
lista.append("[wiki:"+prefix1+flatten(gg0)+" "+gg0+"]")
lastIndex=mm.end()
mm=simpleAbsLink.search(nota,lastIndex)
lista.append(nota[lastIndex:])
nota=''.join(lista)

#named relativelinks
mm=namedRelLink.search(nota)
lista=[]
lastIndex=0
while mm:
lista.append(nota[lastIndex:mm.start()])
gg=mm.groups()
lista.append("[wiki:"+prefix1+prefix2+flatten(gg[0])+" "+gg[1]+"]")
lastIndex=mm.end()
mm=namedRelLink.search(nota,lastIndex)
lista.append(nota[lastIndex:])
nota=''.join(lista)

#named absolute links
mm=namedAbsLink.search(nota)
lista=[]
lastIndex=0
while mm:
lista.append(nota[lastIndex:mm.start()])
gg=mm.groups()
lista.append("[wiki:"+prefix1+flatten(gg[0])+" "+gg[1]+"]")
lastIndex=mm.end()
mm=namedAbsLink.search(nota,lastIndex)
lista.append(nota[lastIndex:])
nota=''.join(lista)

#lists
nota=nota.replace('\n* ','\n * ')

#images
nota=images.sub("\\1[[I

Re: [Zim-wiki] dump notes to mediawiki, or trac

2009-02-02 Thread Jaap Karssenberg

Hi Pablo,

For mediawiki you might want to look into the "wikipediafs" fuse module. 
This allows mounting a mediawiki as a filesystem, which makes it easy to 
copy a bunch of files into it.


A plugin to make zim handle mediawiki format and use this fus module as 
data storage is on my wish list :)


Regards,

Jaap

Pablo Angulo wrote:

  Hello,
  Before I put my brains to the task: has anyone any experience in
dumping a whole notebook into a web based wiki like mediawiki, or trac?
  Both of them use sql databases, and a syntax similar to that of zim.
trac has a command line tool called trac-admin which might make it
trivial. I don't know of any such tool for mediawiki.
  Regards
Pablo

___
Mailing list: https://launchpad.net/~zim-wiki
Post to : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp

  



___
Mailing list: https://launchpad.net/~zim-wiki
Post to : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp


[Zim-wiki] dump notes to mediawiki, or trac

2009-02-02 Thread Pablo Angulo
  Hello,
  Before I put my brains to the task: has anyone any experience in
dumping a whole notebook into a web based wiki like mediawiki, or trac?
  Both of them use sql databases, and a syntax similar to that of zim.
trac has a command line tool called trac-admin which might make it
trivial. I don't know of any such tool for mediawiki.
  Regards
Pablo

___
Mailing list: https://launchpad.net/~zim-wiki
Post to : zim-wiki@lists.launchpad.net
Unsubscribe : https://launchpad.net/~zim-wiki
More help   : https://help.launchpad.net/ListHelp