gunzip-sequences.py 640 Bytes
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27

import glob
import os

from subprocess import Popen, PIPE, STDOUT

UPLOADS = '/mnt/upload/uploads/'

for f in glob.glob(UPLOADS + '/*.gz'):

    print "<==", f

    ### Quick check
    cmd = 'gunzip -l "%s"' % f
    p = Popen(cmd, shell=True, stdin=PIPE, stdout=PIPE, stderr=PIPE) #STDOUT, stderr=STDOUT, close_fds=True)
    (stdoutdata, stderrdata) = p.communicate()
    if 'not in gzip format' in stderrdata:
        print stderrdata
        continue

    ### Unzip, then link to original name to fool the DB
    f_base = f.replace('.gz', '')
    cmd = 'gunzip "%s" ; ln -s "%s" "%s"' % (f, f_base, f)
    print cmd
    os.system(cmd)