PythonSlideShow

Annotated walkfs-writemarkup.py

9:5b81e83a114f
2010-09-02 ink changed README
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@9 5
#from sha import new
ink@5 6
#from time import 
ink@2 7
ink@9 8
def directorySlides(root):
ink@9 9
   content = ""
ink@2 10
   for current, directories, files in walk(root):
ink@9 11
      for count in current.split("/"):
ink@9 12
         content += '\n<DIV class="directory" id="%s">%s' % (current, current)
ink@9 13
         if directories != []:
ink@9 14
            for item in directories:
ink@9 15
               fullpath = path.join(current, item)
ink@9 16
               content += '\n  <DIV class="subdirectory" id="%s">%s</DIV>' % (item, fullpath)
ink@9 17
         else:
ink@9 18
            print "No directories in %s" % current
ink@9 19
#No cnotent is shown for nested slides, and this is a big problem
ink@9 20
         if files != []:
ink@9 21
            for item in files:
ink@9 22
               fullpath = path.join(current, item)
ink@9 23
               content += '\n  <DIV class="file" id="%s">%s</DIV>' % (item, fullpath)
ink@9 24
         else:
ink@9 25
            print "No files in %s" % current
ink@9 26
         content += '\n</DIV>'
ink@2 27
ink@9 28
   return content
ink@2 29
ink@9 30
def main():
ink@9 31
   s = directorySlides("./")
ink@9 32
   template = file("./template_H5p10n.html", "r").read()
ink@9 33
   r = template.split("%s")
ink@9 34
   t = r[0] + s + r[1]
ink@9 35
   file("./generated_slides", "w").write(t)
ink@9 36
   
ink@9 37
activation = main()