Difference between revisions of "WikiExporter"

From Inkscape Wiki
Jump to navigation Jump to search
m (* docpath -> docbase)
(*success! summary, how it works)
Line 1: Line 1:
These are LionKimbro's notes on developing a wiki exporter.
+
I've written 4 files that, together, make it so you can save to an [http://www.oddmuse.org/cgi-bin/wiki OddMuse] wiki.
  
Date: 2004-02-12
+
Basically, it goes like this:
Inkscape version: 0.40
+
* A script is called from Inkscape when the user saves,
Target: Oddmuse
+
* the script reads the SVG document to figure out what directory it was saved to,
 +
* the script reads it to figure out what filename was used as well,
 +
* information about the target wiki is read from the directory the SVG was saved to,
 +
* the Inkscape SVG is uploaded to the wiki,
 +
* and a PNG version is uploaded to the wiki as well.
  
That is, a system so that you can load from and save to a wiki.
+
This all requires 4 files:
 +
* odd_output.inx  -- Inkscape extension definition
 +
* svg2oddmuse.sh  -- coordinates most everything
 +
* svgattrs.py  -- scans the SVG file for <svg ...> attributes
 +
* wikiupload.py  -- oddmuse upload script
  
The wiki targetted by this exporter is Oddmuse. We have [http://www.oddmuse.org/cgi-bin/oddmuse/Automatic_Posting_and_Uploading#wikiupload an upload script for it.]
+
Furthermore, the user creates a custom file, "notes.txt".
 +
The file details the username and wiki URL for svg2oddmuse.sh.
  
I imagine it should be possible to use the Wiki XML-RPC interfaces as well, in the future, though they are usually turned off.
+
The [http://www.emacswiki.org/cw/InkscapeToOddmuse full description of how it works] is on [http://communitywiki.org/ CommunityWiki.]
  
'''odd_output.inx'''
+
Next, I intend to write code to ''read'' Inkscape SVG from the wiki as well.
 
 
This file goes in: /usr/share/inkscape/extensions
 
 
 
<inkscape-extension>
 
  <name>Oddwiki Output</name>
 
  <id>org.inkscape.output.odd</id>
 
  <dependency type="executable" location="extensions">svg2oddmuse.sh</dependency>
 
  <output>
 
      <extension>.odd</extension>
 
      <mimetype>image/x-svgz</mimetype>
 
      <filetypename>Oddmuse Wiki POST (*.odd)</filetypename>
 
      <filetypetooltip>Oddmuse Wiki proxy (SVG, PNG of Drawing)</filetypetooltip>
 
      <dataloss>FALSE</dataloss>
 
  </output>
 
  <script>
 
      <command reldir="extensions">svg2oddmuse.sh</command>
 
      <helper_extension>org.inkscape.output.svg.inkscape</helper_extension>
 
  </script>
 
</inkscape-extension>
 
 
 
'''What data am I receiving from Inkscape?'''
 
 
 
To see what you're getting from Inkscape, create the following script, and call it: '''svg2oddmuse.sh'''
 
 
 
#!/bin/bash
 
echo "hello, world" > /tmp/eraseme.txt
 
echo "invocation: $@"
 
echo
 
echo "$1:"
 
cat "$1"
 
echo "- - - - - - - - - - - - - - - - - - - - - - - - - - - -"
 
env
 
 
 
It appears that no environment variables are being set. The first (and only) argument is the location of a file in /tmp that contains the Inkscape SVG data.
 
 
 
'''Now what?'''
 
 
 
The strategy is this:
 
 
 
* create a directory, representing the wiki
 
* place a file in the directory, "oddmuse.txt", representing necessary details about the wiki
 
* when the user saves a file to the directory (.odd extension,) do the following:
 
** push the SVG to the wiki
 
** render a PNG, and push the PNG to the wiki
 
** perhaps append the name of the wikipage containing the SVG to a page on the wiki
 
 
 
We don't have command-line access (bash argument, environment variable) to the filename or
 
directory it was saved in. But we CAN get this data from the Inkscape SVG.
 
 
 
The <svg> element has attributes:
 
* "sodipodi:docbase" -- path up to the save location
 
* "sodpodi:docname" -- filaname, including extension (".odd", in this case)
 
 
 
 
 
== Inkscape Export process ==
 
 
 
* User hits "Save" in "Save As" dialog
 
* Inkscape writes a file with a random name to /tmp
 
* Inkscape calls export bash script, with /tmp file as only argument
 
* Whatever bash outputs to /dev/stdout, Inkscape records to the file chosen by the user.
 
 
 
== Inkscape SVG Attributes ==
 
 
 
Here's a Python script that outputs <svg> attributes:
 
 
 
'''svgattrs.py''':
 
 
 
#!/usr/bin/python2.3
 
"""Expose Inkscape SVG attributes.
 
 
Read an Inkscape SVG from stdin.
 
Output attributes to the "<svg>" element to stdout.
 
"""
 
 
import sys
 
import xml.sax
 
 
 
class InkscapeSvgHandler(xml.sax.ContentHandler):
 
 
    """Print attributes to svg element."""
 
 
    def startElement(self, name, attrs):
 
        if name == "svg":
 
            for (k,v) in attrs.items():
 
                print k + " " + v
 
 
 
if __name__ == "__main__":
 
    parser = xml.sax.make_parser()
 
    parser.setContentHandler(InkscapeSvgHandler())
 
    parser.parse(sys.stdin)
 
    sys.exit(0)
 
 
 
You can use it like so:
 
 
 
DOCNAME=`cat "$1" | ./svgattrs.py | grep -e "^sodipodi:docname" | cut -d" " -f2`
 
DOCBASE=`cat "$1" | ./svgattrs.py | grep -e "^sodipodi:docbase" | cut -d" " -f2`
 

Revision as of 10:09, 13 February 2005

I've written 4 files that, together, make it so you can save to an OddMuse wiki.

Basically, it goes like this:

  • A script is called from Inkscape when the user saves,
  • the script reads the SVG document to figure out what directory it was saved to,
  • the script reads it to figure out what filename was used as well,
  • information about the target wiki is read from the directory the SVG was saved to,
  • the Inkscape SVG is uploaded to the wiki,
  • and a PNG version is uploaded to the wiki as well.

This all requires 4 files:

  • odd_output.inx -- Inkscape extension definition
  • svg2oddmuse.sh -- coordinates most everything
  • svgattrs.py -- scans the SVG file for <svg ...> attributes
  • wikiupload.py -- oddmuse upload script

Furthermore, the user creates a custom file, "notes.txt". The file details the username and wiki URL for svg2oddmuse.sh.

The full description of how it works is on CommunityWiki.

Next, I intend to write code to read Inkscape SVG from the wiki as well.