Changeset 8e8d602c906884018d6e745f70dbabb243b50060
- Timestamp:
- 05/09/07 00:03:37
(2 years ago)
- Author:
- Jason Michalski <armooo@armooo.net>
- git-committer:
- Jason Michalski <armooo@armooo.net> 1178687017 +0000
- git-parent:
[43630c5b9c2b2772e5096c34dbce33ae9a33e1ba]
- git-author:
- Jason Michalski <armooo@armooo.net> 1178687017 +0000
- Message:
-pyTivo
- Undoing change set 193 on the trunk
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| r43630c5 |
r8e8d602 |
|
| 38 | 38 | return False |
|---|
| 39 | 39 | |
|---|
| 40 | | def getHack83(): |
|---|
| 41 | | try: |
|---|
| 42 | | debug = config.get('Server', 'hack83') |
|---|
| 43 | | if debug.lower() == 'true': |
|---|
| 44 | | return True |
|---|
| 45 | | else: |
|---|
| 46 | | return False |
|---|
| 47 | | except NoOptionError: |
|---|
| 48 | | return True |
|---|
| 49 | | |
|---|
| 50 | 40 | def get(section, key): |
|---|
| 51 | 41 | return config.get(section, key) |
|---|
| … | … | |
| 60 | 50 | # if two values are equidistant, return the larger |
|---|
| 61 | 51 | def nearest(x, list): |
|---|
| 62 | | return reduce(lambda a, b: closest(x,a,b), list) |
|---|
| 63 | | |
|---|
| 64 | | def closest(x,a, b): |
|---|
| 65 | | if abs(x-a) < abs(x-b) or (abs(x-a) == abs(x-b)and a>b): |
|---|
| 66 | | return a |
|---|
| 67 | | else: |
|---|
| 68 | | return b |
|---|
| 69 | | |
|---|
| | 52 | return reduce(lambda a, b: a if abs(x-a) < abs(x-b) or (abs(x-a) == abs(x-b)and a>b) else b, list) |
|---|
| 70 | 53 | |
|---|
| 71 | 54 | def nearestTivoWidth(width): |
|---|
| r43630c5 |
r8e8d602 |
|
| 5 | 5 | from Cheetah.Template import Template |
|---|
| 6 | 6 | from plugin import GetPlugin |
|---|
| 7 | | import Config |
|---|
| 8 | 7 | |
|---|
| 9 | 8 | SCRIPTDIR = os.path.dirname(__file__) |
|---|
| 10 | | debug = Config.getDebug() |
|---|
| 11 | | hack83 = Config.getHack83() |
|---|
| 12 | | def debug_write(data): |
|---|
| 13 | | if debug: |
|---|
| 14 | | debug_out = [] |
|---|
| 15 | | debug_out.append('httpserver.py - ') |
|---|
| 16 | | for x in data: |
|---|
| 17 | | debug_out.append(str(x)) |
|---|
| 18 | | fdebug = open('debug.txt', 'a') |
|---|
| 19 | | fdebug.write(' '.join(debug_out)) |
|---|
| 20 | | fdebug.close() |
|---|
| 21 | 9 | |
|---|
| 22 | 10 | class TivoHTTPServer(SocketServer.ThreadingMixIn, BaseHTTPServer.HTTPServer): |
|---|
| … | … | |
| 53 | 41 | self.infopage() |
|---|
| 54 | 42 | return |
|---|
| 55 | | |
|---|
| | 43 | |
|---|
| 56 | 44 | o = urlparse("http://fake.host" + self.path) |
|---|
| 57 | 45 | query = parse_qs(o[4]) |
|---|
| … | … | |
| 69 | 57 | if query.has_key('Container'): |
|---|
| 70 | 58 | #Dispatch to the container plugin |
|---|
| 71 | | foundContainer = False |
|---|
| 72 | 59 | for name, container in self.server.containers.items(): |
|---|
| 73 | 60 | if query['Container'][0].startswith(name): |
|---|
| 74 | | foundContainer = True |
|---|
| 75 | 61 | plugin = GetPlugin(container['type']) |
|---|
| 76 | 62 | if hasattr(plugin,command): |
|---|
| … | … | |
| 80 | 66 | self.unsuported(query) |
|---|
| 81 | 67 | break |
|---|
| 82 | | if not foundContainer: |
|---|
| 83 | | self.unsuported(query) |
|---|
| 84 | 68 | else: |
|---|
| 85 | 69 | self.unsuported(query) |
|---|
| … | … | |
| 103 | 87 | |
|---|
| 104 | 88 | def unsuported(self, query): |
|---|
| 105 | | if hack83 and 'Command' in query and 'Filter' in query: |
|---|
| 106 | | debug_write(['Unsupported request, checking to see if it is video.', '\n']) |
|---|
| 107 | | command = query['Command'][0] |
|---|
| 108 | | plugin = plugin = GetPlugin('video') |
|---|
| 109 | | if "".join(query['Filter']).find('video') >= 0 and hasattr(plugin,command): |
|---|
| 110 | | debug_write(['Unsupported request, yup it is video send to video plugin for it to sort out.', '\n']) |
|---|
| 111 | | method = getattr(plugin, command) |
|---|
| 112 | | method(self, query) |
|---|
| 113 | | else: |
|---|
| 114 | | self.send_response(404) |
|---|
| 115 | | self.send_header('Content-type', 'text/html') |
|---|
| 116 | | self.end_headers() |
|---|
| 117 | | t = Template(file=os.path.join(SCRIPTDIR,'templates','unsuported.tmpl')) |
|---|
| 118 | | t.query = query |
|---|
| 119 | | self.wfile.write(t) |
|---|
| 120 | | else: |
|---|
| 121 | | self.send_response(404) |
|---|
| 122 | | self.send_header('Content-type', 'text/html') |
|---|
| 123 | | self.end_headers() |
|---|
| 124 | | t = Template(file=os.path.join(SCRIPTDIR,'templates','unsuported.tmpl')) |
|---|
| 125 | | t.query = query |
|---|
| 126 | | self.wfile.write(t) |
|---|
| 127 | | |
|---|
| | 89 | self.send_response(404) |
|---|
| | 90 | self.send_header('Content-type', 'text/html') |
|---|
| | 91 | self.end_headers() |
|---|
| | 92 | t = Template(file=os.path.join(SCRIPTDIR,'templates','unsuported.tmpl')) |
|---|
| | 93 | t.query = query |
|---|
| | 94 | self.wfile.write(t) |
|---|
| 128 | 95 | |
|---|
| 129 | 96 | if __name__ == '__main__': |
|---|