Créer une archive avec bzip2
Bonjour,
Je rencontre un soucis qui me dépasse avec bzip2 dans mon script python ...
Actuellement je fais comme ceci :
Code:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15
|
from shutil import copy
from subprocess import call
path_def = expanduser('~')
path_grb = join(path_def, 'NoaaDownloader', 'grib')
path_www = join('/data', 'apache', 'www', 'html', 'MY.PERSO.space', 'grib')
fullgrb = join(path_grb, 'GFS1_' + cpo_tz(c_h)[0] + '_' + cpo_tz(c_h)[1] + '_full.grb')
# Compress full.grb to full.grb.bz2
call(['bzip2', fullgrb])
# Copy full.grb.bz2 to www
copy(fullgrb + '.bz2', path_www) |
Ça ça fonctionne, j'ai voulu concaténer ces 2 commandes
Sur le terminal j'arrive à faire comme ceci
Code:
1 2
|
bzip2 -ck ~/NoaaDownloader/grib/GFS1_20200905_06_full.grb > /data/apache/www/html/MY.PERSO.space/grib/GFS1_20200905_06_full.grb.bz2 |
Aucun problème ça fonctionne parfaitement, j'ai donc voulu le mettre en place dans le script en utilisant subprocess.call
Code:
1 2 3 4 5 6 7 8 9 10 11 12
|
from subprocess import call
path_def = expanduser('~')
path_grb = join(path_def, 'NoaaDownloader', 'grib')
path_www = join('/data', 'apache', 'www', 'html', 'MY.PERSO.space', 'grib')
fullgrb = join(path_grb, 'GFS1_' + cpo_tz(c_h)[0] + '_' + cpo_tz(c_h)[1] + '_full.grb')
fullgrb_bz2 = join(path_www, 'GFS1_' + cpo_tz(c_h)[0] + '_' + cpo_tz(c_h)[1] + '_full.grb.bz2')
# Compress fullgrb and put it in www
call(['bzip2', '-ck', fullgrb, '>', fullgrb_bz2]) |
Et là il est pas content du tout ...
Code:
1 2 3 4 5
|
bzip2: I won't write compressed data to a terminal.
bzip2: For help, type: `bzip2 --help'.
bzip2: Can't open input file >: No such file or directory.
bzip2: Can't open input file /data/apache/www/html/MY.PERSO.space/grib/GFS1_20200905_06_full.grb.bz2: No such file or directory. |
Je comprends pas du tout pourquoi ça ne fonctionne pas via le script mais si je le fais dans le terminal là ça fonctionne, quelque chose m'échappe ...
Mon but final est de le faire sans passer par le terminal en utilisant le module python bz2, mais je trouve la doc pas "facile".
Un petit coup de pouce serait le bienvenu
Merci