Changeset e4fd983ab5272a9c6a78640f7734bd0f9b856416
- Timestamp:
- 11/27/06 23:18:11
(2 years ago)
- Author:
- Jason Michalski <armooo@armooo.net>
- git-committer:
- Jason Michalski <armooo@armooo.net> 1164691091 +0000
- git-parent:
[c96c0f8877f7062e6b90a42710f8afa79b8a2d85]
- git-author:
- Jason Michalski <armooo@armooo.net> 1164691091 +0000
- Message:
pyTivo
- Added some custom sorting (still don't sort how the tivo asks)
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rc96c0f8 |
re4fd983 |
|
| 1 | | import time, os, BaseHTTPServer, SocketServer, socket, shutil, os.path |
|---|
| | 1 | import time, os, BaseHTTPServer, SocketServer, socket, re |
|---|
| 2 | 2 | from urllib import unquote_plus, quote, unquote |
|---|
| 3 | 3 | from urlparse import urlparse |
|---|
| … | … | |
| 101 | 101 | totalFiles = len(files) |
|---|
| 102 | 102 | |
|---|
| | 103 | def dir_sort(x, y): |
|---|
| | 104 | xdir = os.path.isdir(os.path.join(path, x)) |
|---|
| | 105 | ydir = os.path.isdir(os.path.join(path, y)) |
|---|
| | 106 | |
|---|
| | 107 | if xdir and ydir: |
|---|
| | 108 | return name_sort(x, y) |
|---|
| | 109 | elif xdir: |
|---|
| | 110 | return -1 |
|---|
| | 111 | elif ydir: |
|---|
| | 112 | return 1 |
|---|
| | 113 | else: |
|---|
| | 114 | return name_sort(x, y) |
|---|
| | 115 | |
|---|
| | 116 | def name_sort(x, y): |
|---|
| | 117 | numbername = re.compile(r'(\d*)(.*)') |
|---|
| | 118 | m = numbername.match(x) |
|---|
| | 119 | xNumber = m.group(1) |
|---|
| | 120 | xStr = m.group(2) |
|---|
| | 121 | m = numbername.match(y) |
|---|
| | 122 | yNumber = m.group(1) |
|---|
| | 123 | yStr = m.group(2) |
|---|
| | 124 | |
|---|
| | 125 | print xNumber, ':', xStr |
|---|
| | 126 | |
|---|
| | 127 | if xNumber and yNumber: |
|---|
| | 128 | xNumber, yNumber = int(xNumber), int(yNumber) |
|---|
| | 129 | if xNumber == yNumber: |
|---|
| | 130 | return cmp(xStr, yStr) |
|---|
| | 131 | else: |
|---|
| | 132 | return cmp(xNumber, yNumber) |
|---|
| | 133 | elif xNumber: |
|---|
| | 134 | return -1 |
|---|
| | 135 | elif yNumber: |
|---|
| | 136 | return 1 |
|---|
| | 137 | else: |
|---|
| | 138 | return cmp(xStr, yStr) |
|---|
| | 139 | |
|---|
| | 140 | files.sort(dir_sort) |
|---|
| | 141 | |
|---|
| 103 | 142 | index = 0 |
|---|
| 104 | 143 | if query.has_key('ItemCount'): |
|---|