PythonSlideShow

Annotated walkfs-writemarkup.py

4:1ba92b565b21
2010-08-26 ink Changed walkfs-writemarkup.py; added fullpath and metadata.
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@4 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@2 10
def makeSlides(root):
ink@3 11
   defaultOrder, slideData = "", ""
ink@2 12
   for current, directories, files in walk(root):
ink@3 13
      print current, directories, files
ink@2 14
      classes = ""
ink@2 15
      if directories != []:
ink@2 16
         for directory in directories:
ink@2 17
            try:
ink@4 18
               fullpath = path.join(current, directory)
ink@4 19
               uid = new(fullpath).hexdigest()
ink@4 20
               metaInfo = stat(fullpath) # see http://wiki.forum.nokia.com/index.php/How_to_handle_file_metadata
ink@2 21
               slideData += '\n<!-- directory --><DIV class="%s" id="%s">%s</DIV>' % (classes, uid, metaInfo)
ink@3 22
               defaultOrder += " " + uid
ink@2 23
            except:
ink@2 24
               pass
ink@2 25
ink@2 26
      if files != []:
ink@2 27
         for filename in files:
ink@2 28
            #classes stay the same for file slides as for directory slides for each path given.
ink@2 29
            try:
ink@4 30
               fullpath = path.join(current, filename) 
ink@4 31
               uid = new(fullpath).hexdigest()
ink@4 32
               metaInfo = stat(fullpath)
ink@2 33
               slideData += '\n<!-- filename --><DIV class="%s" id="%s">%s</DIV>' % (classes, uid, metaInfo)
ink@3 34
               defaultOrder += " " + uid
ink@2 35
            except:
ink@2 36
               pass
ink@3 37
   slideOrder = '\n<!-- default order --><DIV class="%s">The default slide order is this DIV\'s class attribute.</DIV>' % defaultOrder
ink@3 38
   slideData += slideOrder   
ink@2 39
ink@2 40
   return slideData
ink@2 41
ink@2 42
s = makeSlides('.')
ink@2 43
file("./generated_slides", "w").write(s)