changeset 88:c382bdd01751

directory indicator
author Jeff Hammel <k0scist@gmail.com>
date Sun, 12 Jan 2014 19:20:16 -0800
parents ced29a73c561
children fca150947fb1
files decoupage/cli.py decoupage/formatters.py setup.py
diffstat 3 files changed, 26 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- a/decoupage/cli.py
+++ b/decoupage/cli.py
@@ -8,31 +8,34 @@ serve directory with decoupage, e.g.
 If the directory is not specified, the current working directory is used
 """
 
 import optparse
 import os
 import socket
 import sys
 
-from .formatters import Datestamp, Sort, Up
+from .formatters import Datestamp, Sort, Up, DirectoryIndicator
 from .web import Decoupage
 from wsgiref import simple_server
 
 here = os.path.dirname(os.path.realpath(__file__))
 
 class DecoupageServer(Decoupage):
     """serve locally with decoupage"""
     # TODO: deprecate; move Decoupage to a few classes
     # with more flexible formatters
     def __init__(self, *args, **kwargs):
         Decoupage.__init__(self, **kwargs)
         # default formatters
         # TODO: make configurable
-        self._formatters = [Sort(), Up('..'), Datestamp('modified: %m %d, %Y')]
+        self._formatters = [Sort(),
+                            DirectoryIndicator('/'),
+                            Up('..'),
+                            Datestamp('modified: %m %d, %Y')]
     def get_formatters(self, path):
         return self._formatters
 
 
 def main(args=sys.argv[1:]):
 
     # parse command line options
     usage = '%prog [options]'
--- a/decoupage/formatters.py
+++ b/decoupage/formatters.py
@@ -132,23 +132,38 @@ class Order(object):
             raise NotImplementedError
 
         files = []
         file_hash = dict([(i['name'], i) for i in data['files']])
         for f in self.order:
             files.append(file_hash.get(f, None))
         files = [ i for i in files if i is not None ]
 
+class DirectoryIndicator(FormatterBase):
+    """indicate a directory"""
+    indicator = '/'
+    def __init__(self, indicator):
+        self.indicator = indicator.strip() or self.indicator
+    def __call__(self, request, data):
+        for f in data['files']:
+            if f.get('type') == 'directory':
+                title = f.get('title')
+                if title is not None:
+                    f['title'] = '%s %s' % (title, self.indicator)
+                else:
+                    description = f.get('description') or f['name']
+                    f['description'] = '%s %s' % (description, self.indicator)
 
 class FilenameDescription(FormatterBase):
     """
     obtain the description from the filename
     the file extension (if any) will be dropped and
     spaces will be substituted for underscores
     """
+
     # TODO : deal with CamelCaseFilenames
 
     separators = ['_', '-'] # space substitute separators
     lesser_words = [ 'or', 'a', 'the', 'on', 'of' ] # unimportant words
 
     def __call__(self, request, data):
         for f in data['files']:
             if f['description'] is None:
@@ -233,17 +248,16 @@ class Links(FormatterBase):
     """
     allow list of links per item:
     foo.html = description of foo; [PDF]=foo.pdf; [TXT]=foo.txt
     """
 
     fatal = False
     defaults = {'separator': ';'}
 
-
     def __call__(self, request, data):
         for f in data['files']:
             if f['description'] and self.separator in f['description']:
                 description, links = f['description'].split(self.separator, 1)
                 links = links.rstrip().split(self.separator)
 
                 if not min(['=' in link for link in links]):
                     message = """%s
@@ -309,17 +323,18 @@ class Favicon(object):
 class Include(object):
     """include a file at the top of the body"""
 
     def __init__(self, arg):
         self.include = arg
     def __call__(self, request, data):
         data['include'] = self.include
 
-###
+
+### general purpose functions for formatters
 
 def formatters():
     formatters = {}
     for entry_point in iter_entry_points('decoupage.formatters'):
         try:
             formatter = entry_point.load()
         except:
             continue
--- a/setup.py
+++ b/setup.py
@@ -1,28 +1,28 @@
-from setuptools import setup, find_packages
+from setuptools import setup
 
 # use README as long_description
 try:
     description = file("README.txt").read()
 except IOError:
     description = ''
 
-version = '0.13.0'
+version = '0.13.1'
 
 setup(name='decoupage',
       version=version,
       description="Decoupage is the art of decorating an object by gluing colored paper cutouts onto it in combination with special paint effects ... The software decoupage lets you stitch together index pages from filesystem content",
       long_description=description,
       classifiers=[], # Get strings from http://www.python.org/pypi?%3Aaction=list_classifiers
       author='Jeff Hammel',
       author_email='k0scist@gmail.com',
       url='http://k0s.org/hg/decoupage',
       license="GPL",
-      packages=find_packages(exclude=['ez_setup', 'examples', 'tests']),
+      packages=['decoupage'],
       include_package_data=True,
       zip_safe=False,
       install_requires=[
           # -*- Extra requirements: -*-
           'WebOb',
           'Paste',
           'PasteScript',
           'genshi',
@@ -44,16 +44,17 @@ setup(name='decoupage',
       [decoupage.formats]
       json = decoupage.formats:JSON
       rss = decoupage.formats:RSS
 
       [decoupage.formatters]
       all = decoupage.formatters:All
       css = decoupage.formatters:CSS
       datestamp = decoupage.formatters:Datestamp
+      directory = decoupage.formatters:DirectoryIndicator
       describe = decoupage.formatters:FilenameDescription
       icon = decoupage.formatters:Favicon
       ignore = decoupage.formatters:Ignore
       include = decoupage.formatters:Include
       links = decoupage.formatters:Links
       order = decoupage.formatters:Order
       scripts = decoupage.formatters:JavaScript
       sort = decoupage.formatters:Sort