Changeset f81af4dc1c0580cb43338e46aeb2cedfb88827c3
- Timestamp:
- 11/25/06 04:07:28
(2 years ago)
- Author:
- Jason Michalski <armooo@armooo.net>
- git-committer:
- Jason Michalski <armooo@armooo.net> 1164449248 +0000
- git-parent:
[f73eb991e35c522085b02fbaea125347f26e41b6]
- git-author:
- Jason Michalski <armooo@armooo.net> 1164449248 +0000
- Message:
pyTivo
- BAD HACK to get subprocess to work without a console
- pyTivoService.py now works
-
Files:
-
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
| rf73eb99 |
rf81af4d |
|
| 3 | 3 | import win32service |
|---|
| 4 | 4 | import win32event |
|---|
| 5 | | import select |
|---|
| | 5 | import select, sys |
|---|
| 6 | 6 | |
|---|
| 7 | 7 | class PyTivoService(win32serviceutil.ServiceFramework): |
|---|
| … | … | |
| 18 | 18 | |
|---|
| 19 | 19 | p = os.path.dirname(__file__) |
|---|
| 20 | | open(os.path.join(p, 'pyTivo.conf')) |
|---|
| 21 | | |
|---|
| | 20 | |
|---|
| | 21 | f = open(os.path.join(p, 'log.txt'), 'w') |
|---|
| | 22 | sys.stdout = f |
|---|
| | 23 | sys.stderr = f |
|---|
| | 24 | print 'test' |
|---|
| | 25 | |
|---|
| 22 | 26 | config = ConfigParser.ConfigParser() |
|---|
| 23 | 27 | config.read( os.path.join(p, 'pyTivo.conf') ) |
|---|
| … | … | |
| 36 | 40 | |
|---|
| 37 | 41 | while 1: |
|---|
| | 42 | sys.stdout.flush() |
|---|
| 38 | 43 | (rx, tx, er) = select.select((httpd,), (), (), 5) |
|---|
| 39 | 44 | for sck in rx: |
|---|
| rf838e68 |
rf81af4d |
|
| 1 | | import subprocess, shutil, os, re |
|---|
| | 1 | import subprocess, shutil, os, re, sys |
|---|
| 2 | 2 | |
|---|
| 3 | 3 | SCRIPTDIR = os.path.dirname(__file__) |
|---|
| 4 | 4 | |
|---|
| | 5 | # subprocess is broken for me on windows so super hack |
|---|
| | 6 | def patchSubprocess(): |
|---|
| | 7 | o = subprocess.Popen._make_inheritable |
|---|
| | 8 | |
|---|
| | 9 | def _make_inheritable(self, handle): |
|---|
| | 10 | print 'MY _make_inheritable' |
|---|
| | 11 | if not handle: return subprocess.GetCurrentProcess() |
|---|
| | 12 | return o(self, handle) |
|---|
| | 13 | |
|---|
| | 14 | subprocess.Popen._make_inheritable = _make_inheritable |
|---|
| | 15 | |
|---|
| | 16 | mswindows = (sys.platform == "win32") |
|---|
| | 17 | |
|---|
| | 18 | if mswindows: |
|---|
| | 19 | patchSubprocess() |
|---|
| | 20 | |
|---|
| 5 | 21 | def output_video(inFile, outFile): |
|---|
| 6 | 22 | if tivo_compatable(inFile): |
|---|
| 7 | 23 | f = file(inFile, 'rb') |
|---|
| 8 | 24 | shutil.copyfileobj(f, outFile) |
|---|
| 9 | | f.close() |
|---|
| | 25 | f.close() |
|---|
| 10 | 26 | else: |
|---|
| 11 | 27 | transcode(inFile, outFile) |
|---|
| … | … | |
| 14 | 30 | |
|---|
| 15 | 31 | cmd = SCRIPTDIR + "\\ffmpeg_mp2.exe -i \"%s\" -vcodec mpeg2video -r 29.97 -b 4096 %s -ac 2 -ab 192 -f vob -" % (inFile, select_aspect(inFile)) |
|---|
| | 32 | # subprocess is busted in my python 2.5 when run without a console. Setting all to PIPE fixes it. |
|---|
| | 33 | # but now we get this nice select loop to dump the stderr data |
|---|
| 16 | 34 | ffmpeg = subprocess.Popen(cmd, stdout=subprocess.PIPE) |
|---|
| 17 | 35 | try: |
|---|
| … | … | |
| 68 | 86 | def video_info(inFile): |
|---|
| 69 | 87 | cmd = SCRIPTDIR + "\\ffmpeg_mp2.exe -i \"%s\"" % inFile |
|---|
| 70 | | ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE) |
|---|
| | 88 | ffmpeg = subprocess.Popen(cmd, stderr=subprocess.PIPE, stdout=subprocess.PIPE, stdin=subprocess.PIPE) |
|---|
| 71 | 89 | output = ffmpeg.stderr.read() |
|---|
| 72 | 90 | |
|---|