PythonSlideShow

walkfs-writemarkup.py

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