[cvs-annodex] commit (/annodex): +cmmlwiki/ +cmmlwiki/trunk/
+cmmlwiki/trunk/.edit.cgi.swp +cmmlwiki/trunk/cmmlwiki-admin
+cmmlwiki/trunk/edit.cgi +cmmlwiki/trunk/view.cgi
+cmmlwiki/trunk/xml-view.cgi
conrad
nobody at lists.annodex.net
Fri Apr 8 18:46:28 EST 2005
Update of /annodex (new revision 1219)
Added files:
cmmlwiki/
cmmlwiki/trunk/
cmmlwiki/trunk/.edit.cgi.swp
cmmlwiki/trunk/cmmlwiki-admin
cmmlwiki/trunk/edit.cgi
cmmlwiki/trunk/view.cgi
cmmlwiki/trunk/xml-view.cgi
Log Message:
initial import of cmmlwiki
Added: cmmlwiki/trunk/.edit.cgi.swp
===================================================================
(Binary files differ)
Property changes on: cmmlwiki/trunk/.edit.cgi.swp
___________________________________________________________________
Name: svn:mime-type
+ application/octet-stream
Added: cmmlwiki/trunk/cmmlwiki-admin
===================================================================
--- cmmlwiki/trunk/cmmlwiki-admin 2005-04-07 08:56:39 UTC (rev 1218)
+++ cmmlwiki/trunk/cmmlwiki-admin 2005-04-08 08:46:25 UTC (rev 1219)
@@ -0,0 +1,161 @@
+#!/usr/bin/env python
+
+# CMMLWiki admin tool
+# Conrad Parker <conrad at annodex.net>, Wed Apr 6 2005
+
+import sys
+import os
+import sqlite
+
+version = "0.1"
+
+db = "/var/local/lib/cmmlwiki/cmmlwiki.db"
+
+
+def usage():
+ print """cmmlwiki-admin - The CMMLWiki administration console %s
+
+ init Initialise CMMLWiki database
+""" % (version)
+
+def init():
+ if (os.path.exists (db)):
+ print "CMMLWiki database already exists"
+ return
+
+ print "Initialising CMMLWiki database ..."
+
+ con = sqlite.connect(db, autocommit=1)
+ cur = con.cursor()
+
+ # projects
+ sql = """CREATE TABLE projects (
+ ixp INTEGER PRIMARY KEY,
+ name VARCHAR(80)
+ )"""
+ cur.execute(sql)
+
+ # sources
+ sql = """CREATE TABLE sources (
+ ixs INTEGER PRIMARY KEY,
+ path VARCHAR(256)
+ )"""
+ cur.execute(sql)
+
+ # projects -> sources
+ sql = """CREATE TABLE project_sources (
+ ixp INTEGER,
+ ixs INTEGER
+ )"""
+ cur.execute(sql)
+
+ # heads
+ sql = """CREATE TABLE heads (
+ ixh INTEGER PRIMARY KEY,
+ id VARCHAR(20),
+ title VARCHAR(80)
+ )"""
+ cur.execute(sql)
+
+ # clips
+ sql = """CREATE TABLE clips (
+ ixc INTEGER PRIMARY KEY,
+ start_time INTEGER,
+ id VARCHAR(20),
+ a_href VARCHAR(80),
+ img_src VARCHAR(80),
+ desc VARCHAR(256)
+ )"""
+ cur.execute(sql)
+
+def clear():
+ print "Clearing CMMLWiki database"
+
+ con = sqlite.connect(db, autocommit=1)
+ cur = con.cursor()
+ cur.execute("DELETE FROM clips")
+
+def dump():
+ print "Dumping CMMLWiki database"
+
+ con = sqlite.connect(db)
+ cur = con.cursor()
+ cur.execute('SELECT * FROM clips')
+ for row in cur.fetchall():
+ print row
+
+def list():
+ con = sqlite.connect(db)
+ cur = con.cursor()
+ sql = 'SELECT (name) FROM projects'
+ cur.execute(sql)
+ for row in cur.fetchall():
+ print row
+
+def add(name, path):
+ con = sqlite.connect(db, autocommit=1)
+ cur = con.cursor()
+ sql = 'SELECT count(ixp) FROM projects WHERE name="%s"' % (name)
+ cur.execute(sql)
+ row = cur.next()
+
+ if (row[0] == 0):
+ sql = 'INSERT INTO projects (name) VALUES ("%s")' % (name)
+ cur.execute(sql)
+
+ sql = 'SELECT ixp FROM projects WHERE name="%s"' % (name)
+ cur.execute(sql)
+ row = cur.next()
+ ixp = row['ixp']
+
+ cur.execute ('INSERT INTO sources (ixs, path) VALUES (NULL, "%s")' % (path))
+ cur.execute ('SELECT (ixs) FROM sources WHERE path="%s"' % (path))
+ row = cur.next()
+ ixs = row[0]
+
+ sql = 'INSERT INTO project_sources (ixp, ixs) VALUES ("%d", "%d")' % (ixp, ixs)
+ cur.execute (sql)
+
+def insert(id, a_href, desc):
+ print 'Inserting <clip id="%s"><a href="%s"/><desc>%s</desc>' % (id, a_href, desc)
+
+ con = sqlite.connect(db, autocommit=1)
+ cur = con.cursor()
+ cur.execute("""INSERT INTO clips (o_id, id, a_href, desc)
+ VALUES(NULL, "%s", "%s", "%s")""" % (id, a_href, desc))
+
+if __name__ == '__main__':
+ try:
+ cmd = sys.argv[1]
+ except IndexError:
+ cmd = "help"
+
+ if (cmd == "help"):
+ usage()
+ elif (cmd == "init"):
+ init()
+ elif (cmd == "clear"):
+ clear()
+ elif (cmd == "list"):
+ list()
+ elif (cmd == "add"):
+ try:
+ name = sys.argv[2]
+ path = sys.argv[3]
+ add (name, path)
+ except IndexError:
+ print 'Usage: cmmlwiki-admin add name path'
+
+ elif (cmd == "dump"):
+ dump()
+ elif (cmd == "insert"):
+ try:
+ id = sys.argv[2]
+ a_href = sys.argv[3]
+ desc = sys.argv[4]
+ insert (id, a_href, desc)
+ except IndexError:
+ print 'Usage: cmmlwiki-admin insert id a_href desc'
+ else:
+ print "Error: unknown command %s" % cmd
+ usage()
Property changes on: cmmlwiki/trunk/cmmlwiki-admin
___________________________________________________________________
Name: svn:executable
+
Added: cmmlwiki/trunk/edit.cgi
===================================================================
--- cmmlwiki/trunk/edit.cgi 2005-04-07 08:56:39 UTC (rev 1218)
+++ cmmlwiki/trunk/edit.cgi 2005-04-08 08:46:25 UTC (rev 1219)
@@ -0,0 +1,262 @@
+#!/usr/bin/env python
+#
+# CMMLWiki editing CGI
+# Copyright (C) 2005 CSIRO Australia
+#
+# Conrad Parker <conrad at annodex.net>, Wed Apr 6 2005
+
+import sys
+import cgi
+import sqlite
+
+version = "0.1"
+
+db = "/var/local/lib/cmmlwiki/cmmlwiki.db"
+
+def content_type (ct):
+ print "Content-Type: %s\n" % ct
+ sys.stdout.flush()
+
+def location (loc):
+ print "Location: %s\n" % loc
+ sys.stdout.flush()
+
+def error(msg):
+ content_type ("text/plain")
+ print """Error: %s""" % msg
+
+def html_head(title):
+ print """<html>
+<head>
+<title>%s - CMML Wiki</title>
+<link rel="stylesheet" href="/cmmlwiki.css"/>
+</head>
+<body>
+<div id="globalWrapper">
+<h1>%s</h1>
+""" % (title, title)
+
+def html_foot():
+ print """
+</div>
+</body>
+</html>
+"""
+
+def select():
+ content_type ("text/html")
+
+ html_head ("Choose a project")
+
+ con = sqlite.connect (db)
+ cur = con.cursor()
+ sql = 'SELECT * FROM projects'
+ cur.execute (sql)
+ for row in cur.fetchall():
+ print '<p><a href="?action=toc&ixp=%(ixp)d">%(name)s</a></p>' % row
+
+ html_foot()
+
+def edit_form(dict):
+ content_type ("text/html")
+
+ html_head ("CMML Wiki")
+
+ print """
+<form method="post" action="/cgi-bin/cmmlwiki/edit.cgi">
+<input type="hidden" name="action" value="store"/>
+<input type="hidden" name="ixp" value="%(ixp)s"/>
+<input type="hidden" name="ixc" value="%(ixc)s"/>
+
+<div id="%(id)s" class="clip">
+<img src="%(img_src)s" align="left"/>
+<h3>%(id)s</h3>
+<table>
+<tr>
+ <th>Start:</th>
+ <td colspan="3"><input type="text" size="80" name="start_time" value="%(start_time)s"/><td>
+</tr>
+<tr>
+ <th>id:</th>
+ <td colspan="3"><input type="text" size="80" name="id" value="%(id)s"/><td>
+</tr>
+<tr>
+ <th>Image:</th>
+ <td colspan="3"><input type="text" size="80" name="img_src" value="%(img_src)s"/><td>
+</tr>
+<tr>
+ <th>Link:</th>
+ <td colspan="3"><input type="text" size="80" name="a_href" value="%(a_href)s"/><td>
+</tr>
+<tr>
+ <th>Desc:</th>
+ <td colspan="3"><textarea rows="8" cols="80" name="desc">%(desc)s</textarea></td>
+</tr>
+</table>
+</div>
+<div class="buttons">
+ <input type="reset" value="Reset"/>
+ <input type="submit" name="store" value="Save"/>
+ <input type="submit" name="store" value="Preview TOC"/>
+ <input type="submit" name="store" value="Preview Video"/>
+ <input type="submit" name="store" value="Cancel"/>
+</div>
+</form>
+""" % dict
+
+ html_foot()
+
+def edit(form):
+ try:
+ ixc = form['ixc'].value
+ except KeyError:
+ ixc = -1
+
+ if (ixc == -1):
+ dict = {}
+ dict['ixc'] = -1
+ dict['ixp'] = form['ixp'].value
+ dict['start_time'] = 0
+ dict['id'] = ""
+ dict['img_src'] = ""
+ dict['a_href'] = ""
+ dict['desc'] = ""
+ edit_form(dict)
+ else:
+ con = sqlite.connect(db)
+ cur = con.cursor()
+ sql = 'SELECT * FROM clips WHERE ixc="%s"' % ixc
+ cur.execute(sql)
+ try:
+ row = cur.next()
+ edit_form(row)
+ except StopIteration:
+ error ("No such id %s" % ixc)
+
+def toc(ixp):
+ content_type ("text/html")
+
+ html_head ("TOC")
+
+ print """
+<h2>The Random File</h2>
+<p>[<a href="?action=edit&ixp=%s">Insert clip</a>]
+[<a href="view.cgi">View video</a>]
+</p>
+<p/>
+""" % (ixp)
+
+ con = sqlite.connect(db)
+ cur = con.cursor()
+ cur.execute("""SELECT * FROM clips ORDER BY start_time""")
+ for row in cur.fetchall():
+ print '<div id="%(id)s" class="clip">' % row
+
+ if (row['img_src'] == None):
+ print '[no image]'
+ else:
+ print '<img src="%(img_src)s" align="left"/>' % row
+
+ print """
+<h3>%(start_time)s: %(id)s</h3>
+<table>
+<tr>
+ <th>Link:</th>
+ <td colspan="3"><p><a href="%(a_href)s">%(a_href)s</a></p><td>
+</tr>
+<tr>
+ <th>Desc:</th>
+ <td colspan="3"><p>%(desc)s</p></td>
+</tr>
+</table>
+<p align="right">
+[<a href="view.cgi?id=%(id)s">view</a>]
+""" % row
+
+ print """[<a href="?action=edit&ixp=%s&ixc=%s">edit</a>]""" % (ixp, row['ixc'])
+
+ print """[<a href="?action=delete&ixp=%(ixp)s&ixc=%(ixc)s">delete</a>]</p>
+</div>
+""" % row
+
+ html_foot()
+
+def store(form):
+ values = {}
+ values['ixc'] = form['ixc'].value
+ values['start_time'] = form['start_time'].value
+ values['id'] = form['id'].value
+ values['img_src'] = form['img_src'].value
+ values['a_href'] = form['a_href'].value
+ values['desc'] = form['desc'].value
+
+ con = sqlite.connect(db, autocommit=1)
+ cur = con.cursor()
+ sql = 'SELECT * FROM clips WHERE ixc="%(ixc)s"' % values
+ try:
+ cur.execute(sql)
+ except sqlite.DatabaseError:
+ error ('Database not initialized')
+
+ sql = """UPDATE clips
+ SET start_time="%(start_time)s",id="%(id)s",img_src="%(img_src)s",a_href="%(a_href)s",desc="%(desc)s"
+ WHERE ixc="%(ixc)s"; """ % values
+ try:
+ row = cur.next()
+ except StopIteration:
+ sql = """INSERT INTO clips (start_time, id, img_src, a_href, desc)
+ VALUES ("%(start_time)s","%(id)s","%(img_src)s","%(a_href)s","%(desc)s") """ % values
+
+ cur.execute(sql)
+
+ try:
+ store = form["store"].value
+ except KeyError:
+ store = "Preview TOC"
+
+ if (store == "Preview TOC"):
+ toc(form['ixp'].value)
+ elif (store == "Preview Video"):
+ location("view.cgi")
+ else:
+ error()
+
+def delete(form):
+ values = {}
+ values['ixc'] = form['ixc'].value
+
+ con = sqlite.connect(db, autocommit=1)
+ cur = con.cursor()
+ sql = 'DELETE FROM clips WHERE ixc="%(ixc)s"' % values
+ cur.execute(sql)
+
+ toc(form['ixp'].value)
+
+# Define main function.
+def main():
+ form = cgi.FieldStorage()
+
+ try:
+ ixp = form["ixp"].value
+ except:
+ select()
+ exit(0)
+
+ try:
+ action = form["action"].value
+ except:
+ action = ""
+
+ if (action == "toc"):
+ toc(ixp)
+ elif (action == "edit"):
+ edit(form)
+ elif (action == "store"):
+ store(form)
+ elif (action == "delete"):
+ delete(form)
+ else:
+ error(action)
+
+if __name__ == '__main__':
+ main()
Property changes on: cmmlwiki/trunk/edit.cgi
___________________________________________________________________
Name: svn:executable
+
Added: cmmlwiki/trunk/view.cgi
===================================================================
--- cmmlwiki/trunk/view.cgi 2005-04-07 08:56:39 UTC (rev 1218)
+++ cmmlwiki/trunk/view.cgi 2005-04-08 08:46:25 UTC (rev 1219)
@@ -0,0 +1,124 @@
+#!/usr/bin/python
+
+import sys
+import os
+import cgi
+import sqlite
+import annodex
+
+db = "/var/local/lib/cmmlwiki/cmmlwiki.db"
+
+preamble = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+"""
+
+def content_type (ct):
+ print "Content-Type: %s\n" % ct
+ sys.stdout.flush()
+
+# Define function to generate HTML form.
+def generate_form():
+ content_type ("text/html")
+
+ print """
+<html>
+<head>
+<title>Info form</title>
+</head>
+<body bgcolor="white">
+<h3>Please, enter your name and the URL of your favourite site.</h3>
+<form method="get" action="dynamo.py">
+<table border="0">
+<tr><th>Name:</th><td><input type="text" name="name"></td></tr>
+<tr><th>URL:</th><td><input type="text" name="url"></td></tr>
+</table>
+<input type="hidden" name="action" value="display"/>
+<input type="submit" value="Enter"/>
+</form>
+</body>
+</html>
+"""
+
+def anxenc(infile, id="", t=0.0):
+ content_type ("application/x-annodex")
+
+ con = sqlite.connect(db)
+ cur = con.cursor()
+
+ # Work out the named time offset
+ if (id == ""):
+ offset = float(t)
+ else:
+ sql = "SELECT * FROM clips WHERE id='%s'" % id
+ cur.execute(sql)
+ row = cur.next()
+ offset = (row['start_time'])
+
+ # Begin the import
+ annodex.init_importers("*/*")
+ anx = annodex.Anx(1, "w")
+ anx.writer_import(infile, offset=offset)
+
+ # Insert clips
+ cur.execute("""SELECT * FROM clips ORDER BY start_time""")
+ for row in cur.fetchall():
+ clip = annodex.Clip(anchor=annodex.Anchor(text="%(a_href)s" % row,
+ href="%(a_href)s" % row))
+ anx.insert(clip, row['start_time']);
+
+ # Generate Annodex media
+ while 1:
+ x = anx.write(1024)
+ if (x == 0):
+ break
+
+def fake_cmml():
+ content_type ("text/x-cmml")
+
+ print preamble
+
+ print """<cmml>
+<head>
+<title>CMML Wiki</title>
+</head>
+"""
+
+ con = sqlite.connect(db)
+ cur = con.cursor()
+ cur.execute("""SELECT * FROM clips ORDER BY start_time""")
+ for row in cur.fetchall():
+ print """<clip start="%(start_time)s">
+<a href="%(a_href)s">%(a_href)s</a>
+<img src="%(img_src)s"/>
+<desc>%(desc)s</desc>
+</clip>""" % row
+
+ print """
+</cmml>
+"""
+
+# Define main function.
+def main():
+ if (os.environ.has_key("HTTP_ACCEPT")):
+ accept = os.environ["HTTP_ACCEPT"]
+ else:
+ accept = ""
+
+ form = cgi.FieldStorage()
+ try:
+ id = form['id'].value
+ except KeyError:
+ id = ""
+
+ try:
+ t = form['t'].value
+ except KeyError:
+ t = 0.0
+
+ if (accept == "text/x-cmml"):
+ fake_cmml()
+ else:
+ anxenc ('/var/www/m.anx', id, t)
+
+# Call main function.
+main()
+
Property changes on: cmmlwiki/trunk/view.cgi
___________________________________________________________________
Name: svn:executable
+
Added: cmmlwiki/trunk/xml-view.cgi
===================================================================
--- cmmlwiki/trunk/xml-view.cgi 2005-04-07 08:56:39 UTC (rev 1218)
+++ cmmlwiki/trunk/xml-view.cgi 2005-04-08 08:46:25 UTC (rev 1219)
@@ -0,0 +1,129 @@
+#!/usr/bin/env python
+#
+# Copyright (C) 2005 CSIRO Australia
+#
+# Based on sample code from the Python/XML HOWTO:
+# http://pyxml.sourceforge.net/topics/howto/xml-howto.html
+#
+# You may find this script to be a useful example of processing CMML in
+# python. Improvements and bugfixes welcome :-)
+#
+# Conrad Parker <conrad at annodex.net>, Mar 3 2005
+
+import sys
+from time import strptime, strftime
+
+from xml.sax import saxutils
+from xml.sax import make_parser
+from xml.sax.handler import feature_namespaces
+
+def content_type (ct):
+ print "Content-Type: %s\n" % ct
+ sys.stdout.flush()
+
+def clock2timestamp(str):
+ t = strptime(str, "clock:%Y%m%dT%H%M%SZ")
+ return strftime ("%H:%M:%S", t)
+
+class cmmlHandler(saxutils.DefaultHandler):
+ def __init__(self):
+ self.inDesc = False
+
+ def startElement(self, name, attrs):
+ if name == 'clip':
+ self.speaker = ""
+ self.inDesc = False
+ self.vals = {}
+ self.vals['text'] = ""
+ self.vals['imgsrc'] = ""
+ self.vals['a_href'] = ""
+ self.vals['id'] = attrs.get('id')
+ self.vals['start'] = attrs.get('start')
+ self.vals['end'] = attrs.get('end')
+ #self.start_time = clock2timestamp(attrs.get('start', None))
+
+ if name == 'meta':
+ if (attrs.get('name') == 'DC.Contributor'):
+ self.speaker = attrs.get('content')
+
+ if name == 'a':
+ self.vals['a_href'] = attrs.get('href')
+
+ if name == 'img':
+ self.vals['imgsrc'] = attrs.get('src')
+
+ if name == 'desc':
+ self.inDesc = True
+
+ def characters(self, ch):
+ if self.inDesc:
+ self.vals['text'] = self.vals['text'] + ch
+
+ def endElement(self, name):
+ if name == 'clip':
+ print """<div id="%(id)s" class="clip">
+ <img src="%(imgsrc)s" align="left"/>
+ <h3>%(id)s</h3>
+ <table>
+ <tr>
+ <th>Start:</th>
+ <td><input type="text" name="%(id)s:start" value="%(start)s"/></td>
+ <th>End:</th>
+ <td><input type="text" name="%(id)s:end" value="%(end)s"/></td>
+ </tr>
+ <tr>
+ <th>Link:</th>
+ <td colspan="3"><input type="text" size="80" name="%(id)s:href" value="%(a_href)s"/><td>
+ </tr>
+ <tr>
+ <th>Desc:</th>
+ <td colspan="3"><textarea rows="8" cols="80" name="%(id)s:desc">%(text)s</textarea></td>
+ </tr>
+ </table>
+ </div>
+ """ % self.vals
+
+ if name == 'desc':
+ self.inDesc = False
+
+if __name__=='__main__':
+ content_type ("text/html")
+
+ print """
+ <html>
+ <head>
+ <title>CMML Wiki</title>
+ <link rel="stylesheet" href="/cmmlwiki.css"/>
+ </head>
+ <body>
+ <h1>CMML Wiki</h1>
+ <form>
+ """
+
+ # Create a parser
+ parser = make_parser()
+
+ # Tell the parser we are not interested in XML namespaces
+ parser.setFeature(feature_namespaces, 0)
+
+ # Create the handler
+ dh = cmmlHandler()
+
+ # Tell the parser to use the handler
+ parser.setContentHandler(dh)
+
+ # Parse the input
+ parser.parse('file:///var/www/media/AAP-0409/MAIN_VIDEO/index.cmml')
+
+ print """
+ <div class="buttons">
+ <input type="reset" value="Reset"/>
+ <input type="submit" value="Preview"/>
+ <input type="submit" value="Preview TOC"/>
+ </div>
+ </form>
+
+ </body>
+ </html>
+ """
+
Property changes on: cmmlwiki/trunk/xml-view.cgi
___________________________________________________________________
Name: svn:executable
+
--
conrad
More information about the cvs-annodex
mailing list