changeset 24:eb15c8321ad8

sort by default
author Jeff Hammel <jhammel@mozilla.com>
date Fri, 02 Mar 2012 12:50:23 -0800
parents ac592b097688
children f1f53fa1e851
files fileserver/web.py
diffstat 1 files changed, 4 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/fileserver/web.py	Wed Feb 29 16:44:32 2012 -0800
+++ b/fileserver/web.py	Fri Mar 02 12:50:23 2012 -0800
@@ -41,10 +41,11 @@
 
 class DirectoryServer(object):
 
-    def __init__(self, directory):
+    def __init__(self, directory, sort=True):
         assert os.path.exists(directory), "'%s' does not exist" % directory
         assert os.path.isdir(directory), "'%s' is not a directory" % directory
         self.directory = self.normpath(directory)
+        self.sort = sort
 
     @staticmethod
     def normpath(path):
@@ -65,6 +66,8 @@
         """
         parts = ['<html><head><title>Simple Index</title></head><body>']
         listings = os.listdir(directory)
+        if self.sort:
+            listings.sort()
         listings = [(os.path.isdir(os.path.join(directory, entry)) and entry + '/' or entry, entry)
                     for entry in listings]
         for link, entry in listings: