]> git.llucax.com Git - software/subdivxget.git/commitdiff
Output errors to standard error
authorLeandro Lucarella <luca@llucax.com.ar>
Sat, 14 Jul 2012 18:08:38 +0000 (20:08 +0200)
committerLeandro Lucarella <luca@llucax.com.ar>
Sat, 14 Jul 2012 18:12:55 +0000 (20:12 +0200)
subdivxget

index 5d467ec1c209476bcb245c5d3de36b3a93bc99d9..e938ac8e3b01c1d2254134922889f98573619c3b 100755 (executable)
@@ -16,6 +16,19 @@ else:
 import zipfile
 import subprocess
 
+
+def output(fo, fmt, *args, **kargs):
+       if not args:
+               args = kargs
+       fo.write((fmt % args) + '\n')
+
+def echo(fmt, *args, **kargs):
+       output(sys.stdout, fmt, *args, **kargs)
+
+def error(fmt, *args, **kargs):
+       output(sys.stderr, fmt, *args, **kargs)
+
+
 class SubDivXQuery:
        def __init__(self, to_search, page_number):
                self.host = "www.subdivx.com"
@@ -215,12 +228,11 @@ def get_subs(query_str, filters):
        subs.sort(key=lambda s: int(s['downloads']), reverse=True)
 
        for sub in subs:
-               print('''\
+               echo('''\
 - %(titulo)s (%(autor)s - %(fecha)s - %(downloads)s - %(comentarios)s)
   %(desc)s
        DOWNLOADING ...
-''' % sub)
-               continue
+''', **sub)
                fname, headers = urlretrieve(sub['url'])
                if 'Content-Type' in headers:
                        if headers['Content-Type'] in zip_exts:
@@ -229,17 +241,18 @@ def get_subs(query_str, filters):
                                for fn in z.namelist():
                                        if fn.endswith(sub_exts):
                                                if '..' in fn or fn.startswith('/'):
-                                                       print('Dangerous file name:', fn)
+                                                       error('Dangerous file name: %s', fn)
                                                        continue
-                                               print('Extracting', fn, '...')
+                                               echo('Extracting %s...', fn)
                                                z.extract(fn)
                        elif headers['Content-Type'] in rar_exts:
                                if subprocess.call(['rar', 'x', fname]) != 0:
-                                       print('Error unraring file %s' % fname)
+                                       error('Error unraring file %s', fname)
                        else:
-                               print('Unrecognized file type:', headers['Content-Type'])
+                               error('Unrecognized file type:',
+                                               headers['Content-Type'])
                else:
-                       print('No Content-Type!')
+                       error('No Content-Type!')
 
 
 get_subs(sys.argv[1], sys.argv[2:])