PythonSlideShow

Annotated walkfs-writemarkup.py

3:9e0e4655feee
2010-08-26 ink Changed walkfs-writemarkup.py to now output a default slide order.
ink@2 1
#!/usr/bin/env python
ink@2 2
# -*- coding: utf-8 -*-
ink@2 3
ink@2 4
from os import walk, path
ink@2 5
from sha import new
ink@2 6
ink@2 7
# Bug: Class attributes end up with white space (if filenames have them): this might be a bug or a feature, I suppose.
ink@2 8
ink@2 9
def makeSlides(root):
ink@3 10
   defaultOrder, slideData = "", ""
ink@2 11
   for current, directories, files in walk(root):
ink@3 12
      print current, directories, files
ink@2 13
      classes = ""
ink@2 14
      if directories != []:
ink@2 15
         for directory in directories:
ink@2 16
            try:
ink@2 17
               uid = new(path.join(current, directory)).hexdigest()
ink@2 18
               metaInfo = path.join(current, directory)
ink@2 19
               slideData += '\n<!-- directory --><DIV class="%s" id="%s">%s</DIV>' % (classes, uid, metaInfo)
ink@3 20
               defaultOrder += " " + uid
ink@2 21
            except:
ink@2 22
               pass
ink@2 23
ink@2 24
      if files != []:
ink@2 25
         for filename in files:
ink@2 26
            #classes stay the same for file slides as for directory slides for each path given.
ink@2 27
            try:
ink@2 28
               uid = new(path.join(current, filename)).hexdigest()
ink@2 29
               metaInfo = path.join(current, filename)
ink@2 30
               slideData += '\n<!-- filename --><DIV class="%s" id="%s">%s</DIV>' % (classes, uid, metaInfo)
ink@3 31
               defaultOrder += " " + uid
ink@2 32
            except:
ink@2 33
               pass
ink@3 34
   slideOrder = '\n<!-- default order --><DIV class="%s">The default slide order is this DIV\'s class attribute.</DIV>' % defaultOrder
ink@3 35
   slideData += slideOrder   
ink@2 36
ink@2 37
   return slideData
ink@2 38
ink@2 39
s = makeSlides('.')
ink@2 40
file("./generated_slides", "w").write(s)