PythonSlideShow

walkfs-writemarkup.py

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