2 from urllib
import unquote
, unquote_plus
3 from urlparse
import urlparse
6 module_name
= '.'.join(['plugins', name
, name
])
7 module
= __import__(module_name
, fromlist
=name
)
8 plugin
= getattr(module
, name
)()
15 def SendFile(self
, handler
, container
, name
):
16 o
= urlparse("http://fake.host" + handler
.path
)
17 path
= unquote_plus(o
.path
)
18 handler
.send_response(200)
20 f
= file(container
['path'] + path
[len(name
)+1:], 'rb')
21 shutil
.copyfileobj(f
, handler
.wfile
)
23 def get_local_path(self
, handler
, query
):
25 subcname
= query
['Container'][0]
26 container
= handler
.server
.containers
[subcname
.split('/')[0]]
28 path
= container
['path']
29 for folder
in subcname
.split('/')[1:]:
32 path
= os
.path
.join(path
, folder
)
35 def get_files(self
, handler
, query
, filterFunction
=None):
36 subcname
= query
['Container'][0]
37 path
= self
.get_local_path(handler
, query
)
39 files
= os
.listdir(path
)
41 files
= filter(filterFunction
, files
)
42 totalFiles
= len(files
)
45 xdir
= os
.path
.isdir(os
.path
.join(path
, x
))
46 ydir
= os
.path
.isdir(os
.path
.join(path
, y
))
49 return name_sort(x
, y
)
55 return name_sort(x
, y
)
58 numbername
= re
.compile(r
'(\d*)(.*)')
59 m
= numbername
.match(x
)
62 m
= numbername
.match(y
)
66 if xNumber
and yNumber
:
67 xNumber
, yNumber
= int(xNumber
), int(yNumber
)
68 if xNumber
== yNumber
:
69 return cmp(xStr
, yStr
)
71 return cmp(xNumber
, yNumber
)
77 return cmp(xStr
, yStr
)
83 if query
.has_key('ItemCount'):
84 count
= int(query
['ItemCount'] [0])
86 if query
.has_key('AnchorItem'):
87 anchor
= unquote(query
['AnchorItem'][0])
88 for i
in range(len(files
)):
89 if os
.path
.isdir(os
.path
.join(path
,files
[i
])):
90 file_url
= '/TiVoConnect?Command=QueryContainer&Container=' + subcname
+ '/' + files
[i
]
92 file_url
= '/' + subcname
+ '/' + files
[i
]
93 if file_url
== anchor
:
101 if query
.has_key('AnchorOffset'):
102 index
= index
+ int(query
['AnchorOffset'][0])
104 if index
< index
+ count
:
105 files
= files
[max(index
, 0):index
+ count
]
106 return files
, totalFiles
, index
108 files
= files
[max(index
+ count
, 0):index
]
109 return files
, totalFiles
, index
+ count