#!/usr/bin/env python
#
# Data Quality Checker also known as DQC
#
# Read the README.md for more detailed information
#
#       Barcelona Supercomputing Center - Centro Nacional de Supercomputacion
#       Earth Sciences Department - Computational Earth Sciences
#
#     Authors:
#       Joan Sala Calero (joan.sala@bsc.es)
#

import os
import glob
import zipfile

'''
Script to add re-processed html or pdf to zip
'''
# Folder with results
res_folder = '/shared/QAR_dqc/results'
cdir = os.getcwd()
os.chdir(res_folder)

for ini_file in glob.glob('*.ini'):

    # ZIP file name
    zip_file = ini_file.replace('.ini', '.zip')
    zip = zipfile.ZipFile(zip_file, 'w')
    files2zip = glob.glob(ini_file.replace('.ini', '-*')) + (glob.glob(ini_file.replace('.ini', '.*')))

    for ff in files2zip:
        if not(ff.endswith('.zip')):
            print('+++ {}'.format(ff))
            zip.write(ff)

    print('ZIP {}'.format(zip_file))
    print('-------------')
    zip.close()

# Back to last directory
os.chdir(cdir)