[cvs-annodex] commit (/annodex): cmmlwiki/trunk/cmmlwiki-admin

conrad nobody at lists.annodex.net
Thu Apr 21 11:30:00 EST 2005


Update of /annodex (new revision 1276)

Modified files:
   cmmlwiki/trunk/cmmlwiki-admin

Log Message:
add 'cmmlwiki-admin publish' function


Modified: cmmlwiki/trunk/cmmlwiki-admin
===================================================================
--- cmmlwiki/trunk/cmmlwiki-admin	2005-04-21 01:22:06 UTC (rev 1275)
+++ cmmlwiki/trunk/cmmlwiki-admin	2005-04-21 01:29:59 UTC (rev 1276)
@@ -5,12 +5,18 @@
 
 import sys
 import os
+import stat
+import shutil
 import sqlite
 
+from xml.sax.saxutils import escape
+
 version = "0.1"
 
 db = "/var/local/lib/cmmlwiki/cmmlwiki.db"
 
+preamble = """<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
+"""
 
 def usage():
     print """cmmlwiki-admin - The CMMLWiki administration console %s
@@ -18,6 +24,8 @@
   add name path                        Add a project
   init                                 Initialise CMMLWiki database
   insert id a_href desc                Insert a clip
+  list                                 List projects
+  publish path                         Publish the wiki as CMML and Ogg files
 """ % (version)
 
 def init():
@@ -103,14 +111,17 @@
     for row in cur.fetchall():
         print row
     
-def list():
+def make_projects_list():
     con = sqlite.connect(db)
     cur = con.cursor()
     sql = 'SELECT (name) FROM projects'
     cur.execute(sql)
-    for row in cur.fetchall():
-        print row
+    return cur.fetchall()
 
+def list_projects():
+    for p in make_projects_list():
+        print p[0]
+
 def add(name, path):
     con = sqlite.connect(db, autocommit=1)
     cur = con.cursor()
@@ -144,6 +155,99 @@
     cur.execute("""INSERT INTO clips (o_id, id, a_href, desc)
                 VALUES(NULL, "%s", "%s", "%s")""" % (id, a_href, desc))
 
+def time2npt (t):
+    it = int(t)
+    ms = (t*1000) - (float(it) * 1000)
+    ss = it % 60
+    mm = ((it-ss)/60) % 60
+    hh = ((it-(mm*60)-ss)/3600) % 60
+    return "npt:%d:%02d:%02d.%03d" % (hh, mm, ss, ms)
+
+def my_escape (str):
+    try:
+        s = escape (str)
+    except AttributeError:
+        s = ''
+    return s
+
+def project_to_cmml(ixp, project_name):
+    def key_isprintable (dict, key):
+        return (dict.has_key(key) and dict[key] != None and dict[key] != '')
+
+    ret = preamble
+
+    ret = ret+"""<cmml>
+<stream>
+  <import src="%s.ogg"/>
+</stream>
+<head>
+<title>%s - CMML Wiki</title>
+</head>
+""" % (project_name, project_name)
+#<link rel="edit" href="%s/%s" />
+#""" % (project_name, edit_base, project_name)
+  
+    con = sqlite.connect(db)
+    cur = con.cursor()
+    #sql = 'SELECT * FROM clips'
+    sql = 'SELECT * FROM clips WHERE ixp="%s" ORDER BY start_time' % ixp
+    cur.execute(sql)
+    for row in cur.fetchall():
+        ret = ret+'<clip'
+        if (key_isprintable (row, 'id')):
+            ret=ret+ ' id="%s"' % row['id']
+        if (key_isprintable (row, 'start_time')):
+            ret=ret+ ' start="%s"' % time2npt (row['start_time'])
+        ret=ret+ '>'
+
+        if (key_isprintable (row, 'a_href')):
+            ret=ret+ '<a href="%(a_href)s">%(a_href)s</a>' % row
+
+        if (key_isprintable (row, 'img_src')):
+            ret=ret+ '<img src="%(img_src)s"/>' % row
+
+        if (key_isprintable (row, 'desc')):
+            ret=ret+ '<desc>%s</desc>' % my_escape(row['desc'])
+
+        ret=ret+ '</clip>'
+
+    ret=ret+ """
+</cmml>
+"""
+
+    return ret
+
+def publish(path):
+    try:
+        os.mkdir (path)
+    except OSError:
+        print '%s exists, exiting ...' % path
+        sys.exit(1)
+
+    con = sqlite.connect(db)
+    cur = con.cursor()
+
+    # Print the cmml
+    sql = 'SELECT * FROM projects'
+    cur.execute(sql)
+    projects = cur.fetchall()
+    for row in projects:
+        cmmlfile=path+'/'+row['name']+'.cmml'
+        f = file(cmmlfile, "w")
+        name = row['name']
+        ixp = row['ixp']
+        f.write (project_to_cmml (ixp, name))
+        f.close()
+
+        # Get the source
+        sql = 'SELECT * FROM sources WHERE ixp="%s"' % ixp
+        cur.execute(sql)
+        row = cur.next()
+        source = row['path']
+        dest = path+'/'+name+'.ogg' 
+        
+        shutil.copy (source, dest)
+
 if __name__ == '__main__':
     try:
 	cmd = sys.argv[1]
@@ -157,7 +261,14 @@
     elif (cmd == "clear"):
         clear()
     elif (cmd == "list"):
-        list()
+        list_projects()
+    elif (cmd == "publish"):
+        try:
+            path = sys.argv[2]
+            publish (path)
+        except IndexError:
+            print 'Usage: cmmlwiki-admin publish path'
+
     elif (cmd == "add"):
         try:
             name = sys.argv[2]


-- 
conrad



More information about the cvs-annodex mailing list