PythonSlideShow

Annotated walkfs-writemarkup.py

6:c69af778e9a3
2010-08-26 ink changed template_H5p10n.html to use vertical CSS transitions instead of horizontal ones.
ink@2 1
#!/usr/bin/env python
ink@2 2
# -*- coding: utf-8 -*-
ink@2 3
ink@4 4
from os import walk, path, stat
ink@2 5
from sha import new
ink@5 6
#from time import 
ink@2 7
ink@2 8
# Bug: Class attributes end up with white space (if filenames have them): this might be a bug or a feature, I suppose.
ink@2 9
ink@5 10
# Put template loader from file minimumWorking... mod with %s at slide insertion point.
ink@5 11
# Setup a current slideset, current index display (re-add it modified from original).
ink@5 12
ink@2 13
def makeSlides(root):
ink@3 14
   defaultOrder, slideData = "", ""
ink@2 15
   for current, directories, files in walk(root):
ink@5 16
#      print current, directories, files
ink@2 17
      classes = ""
ink@2 18
      if directories != []:
ink@2 19
         for directory in directories:
ink@2 20
            try:
ink@4 21
               fullpath = path.join(current, directory)
ink@4 22
               uid = new(fullpath).hexdigest()
ink@4 23
               metaInfo = stat(fullpath) # see http://wiki.forum.nokia.com/index.php/How_to_handle_file_metadata
ink@5 24
               slideData += '\n<!-- directory --><DIV class="slide %s" id="%s">%s</DIV>' % ("defaultOrder", uid, metaInfo)
ink@3 25
               defaultOrder += " " + uid
ink@2 26
            except:
ink@2 27
               pass
ink@2 28
ink@2 29
      if files != []:
ink@2 30
         for filename in files:
ink@2 31
            #classes stay the same for file slides as for directory slides for each path given.
ink@2 32
            try:
ink@4 33
               fullpath = path.join(current, filename) 
ink@4 34
               uid = new(fullpath).hexdigest()
ink@4 35
               metaInfo = stat(fullpath)
ink@5 36
               slideData += '\n<!-- filename --><DIV class="slide %s" id="%s">%s</DIV>' % ("defaultOrder", uid, metaInfo)
ink@3 37
               defaultOrder += " " + uid
ink@2 38
            except:
ink@2 39
               pass
ink@5 40
   slideOrder = '\n<!-- default order --><DIV class="%s">\n%s\n</DIV>' % ("sequencing defaultOrder", defaultOrder)
ink@3 41
   slideData += slideOrder   
ink@2 42
ink@2 43
   return slideData
ink@2 44
ink@2 45
s = makeSlides('.')
ink@5 46
template = file("./template_H5p10n.html", "r").read()
ink@5 47
r = template.split("%s")
ink@5 48
t = r[0] + s + r[1]
ink@5 49
file("./generated_slides", "w").write(t)