PythonSlideShow

Change of walkfs-writemarkup.py

9:5b81e83a114f
walkfs-writemarkup.py
     1.1 --- a/walkfs-writemarkup.py	Thu Aug 26 22:10:08 2010 +0300
     1.2 +++ b/walkfs-writemarkup.py	Thu Sep 02 00:27:59 2010 +0300
     1.3 @@ -2,48 +2,36 @@
     1.4  # -*- coding: utf-8 -*-
     1.5  
     1.6  from os import walk, path, stat
     1.7 -from sha import new
     1.8 +#from sha import new
     1.9  #from time import 
    1.10  
    1.11 -# Bug: Class attributes end up with white space (if filenames have them): this might be a bug or a feature, I suppose.
    1.12 -
    1.13 -# Put template loader from file minimumWorking... mod with %s at slide insertion point.
    1.14 -# Setup a current slideset, current index display (re-add it modified from original).
    1.15 -
    1.16 -def makeSlides(root):
    1.17 -   defaultOrder, slideData = "", ""
    1.18 +def directorySlides(root):
    1.19 +   content = ""
    1.20     for current, directories, files in walk(root):
    1.21 -#      print current, directories, files
    1.22 -      classes = ""
    1.23 -      if directories != []:
    1.24 -         for directory in directories:
    1.25 -            try:
    1.26 -               fullpath = path.join(current, directory)
    1.27 -               uid = new(fullpath).hexdigest()
    1.28 -               metaInfo = stat(fullpath) # see http://wiki.forum.nokia.com/index.php/How_to_handle_file_metadata
    1.29 -               slideData += '\n<!-- directory --><DIV class="slide %s" id="%s">%s</DIV>' % ("defaultOrder", uid, metaInfo)
    1.30 -               defaultOrder += " " + uid
    1.31 -            except:
    1.32 -               pass
    1.33 +      for count in current.split("/"):
    1.34 +         content += '\n<DIV class="directory" id="%s">%s' % (current, current)
    1.35 +         if directories != []:
    1.36 +            for item in directories:
    1.37 +               fullpath = path.join(current, item)
    1.38 +               content += '\n  <DIV class="subdirectory" id="%s">%s</DIV>' % (item, fullpath)
    1.39 +         else:
    1.40 +            print "No directories in %s" % current
    1.41 +#No cnotent is shown for nested slides, and this is a big problem
    1.42 +         if files != []:
    1.43 +            for item in files:
    1.44 +               fullpath = path.join(current, item)
    1.45 +               content += '\n  <DIV class="file" id="%s">%s</DIV>' % (item, fullpath)
    1.46 +         else:
    1.47 +            print "No files in %s" % current
    1.48 +         content += '\n</DIV>'
    1.49  
    1.50 -      if files != []:
    1.51 -         for filename in files:
    1.52 -            #classes stay the same for file slides as for directory slides for each path given.
    1.53 -            try:
    1.54 -               fullpath = path.join(current, filename) 
    1.55 -               uid = new(fullpath).hexdigest()
    1.56 -               metaInfo = stat(fullpath)
    1.57 -               slideData += '\n<!-- filename --><DIV class="slide %s" id="%s">%s</DIV>' % ("defaultOrder", uid, metaInfo)
    1.58 -               defaultOrder += " " + uid
    1.59 -            except:
    1.60 -               pass
    1.61 -   slideOrder = '\n<!-- default order --><DIV class="%s">\n%s\n</DIV>' % ("sequencing defaultOrder", defaultOrder)
    1.62 -   slideData += slideOrder   
    1.63 +   return content
    1.64  
    1.65 -   return slideData
    1.66 -
    1.67 -s = makeSlides('.')
    1.68 -template = file("./template_H5p10n.html", "r").read()
    1.69 -r = template.split("%s")
    1.70 -t = r[0] + s + r[1]
    1.71 -file("./generated_slides", "w").write(t)
    1.72 +def main():
    1.73 +   s = directorySlides("./")
    1.74 +   template = file("./template_H5p10n.html", "r").read()
    1.75 +   r = template.split("%s")
    1.76 +   t = r[0] + s + r[1]
    1.77 +   file("./generated_slides", "w").write(t)
    1.78 +   
    1.79 +activation = main()