"""
Runner to extract all .gz zipped files in a directory
"""

from __future__ import print_function
from util import Util
import sys

""" Command line args:
    parent_dir - .gz zipped files src directory
    dest_dir   - directory for decompressed files
"""
if __name__ == '__main__':

    if len(sys.argv) == 3:
        parent_dir = sys.argv[1]      # parent dir contain .gz zipped files
        dest_dir = sys.argv[2]        # destination dir where extracted files will be stored

        file_util = Util()                              # file utility class
        zipped_files = file_util.get_files(parent_dir)  # get files from parent dir param
        for f in zipped_files:                          # unzip each file to dest_dir
            status_flag = file_util.unzip_gz(f, dest_dir)

            print('\nStatus...')
            if status_flag == Util.SUCCESS:
                print('Successfully unzipped ' + '\n' + f + '\n' + ' to ' + parent_dir)
            else:
                print('Failed to unzip ' + '\n' + f)

    else:
        print('Incorrect number of arguments. Arguments: [parent_dir] [dest_dir]')
