PythonSlideShow

Annotated walkfs-writemarkup.py

2:6847b03caa25
2010-08-26 ink Added walkfs-writemarkup.py to keep this part separate until I get it right.
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@2 10
   slideData = ""
ink@2 11
   for current, directories, files in walk(root):
ink@2 12
      print "\n" + 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@2 20
            except:
ink@2 21
               pass
ink@2 22
ink@2 23
      if files != []:
ink@2 24
         for filename in files:
ink@2 25
            #classes stay the same for file slides as for directory slides for each path given.
ink@2 26
            try:
ink@2 27
               uid = new(path.join(current, filename)).hexdigest()
ink@2 28
               metaInfo = path.join(current, filename)
ink@2 29
               slideData += '\n<!-- filename --><DIV class="%s" id="%s">%s</DIV>' % (classes, uid, metaInfo)
ink@2 30
            except:
ink@2 31
               pass
ink@2 32
ink@2 33
ink@2 34
   return slideData
ink@2 35
ink@2 36
s = makeSlides('.')
ink@2 37
file("./generated_slides", "w").write(s)