#!/usr/bin/env python

# file.py Code
#
# Copyright (c) Jose M. Molero
#
# All rights reserved.
#
# MIT License
#
# Permission is hereby granted, free of charge, to any person obtaining a
# copy of this software and associated documentation files (the "Software"),
# to deal in the Software without restriction, including without limitation
# the rights to use, copy, modify, merge, publish, distribute, sublicense,
# and/or sell copies of the Software, and to permit persons to whom the
# Software is furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED *AS IS*, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
# DEALINGS IN THE SOFTWARE.

"""
Code sample to

Notes:
- Insert notes

TODO list:
- Check if / at the end of --folder
- Add delete option

"""


# stdlib imports
import argparse
import errno
import os
import tarfile
import shutil
import string


# global variables
_SCRIPT_VERSION = '0.0.2'


def make_tarfile(output_filename, source_dir):
    """Create tarfile gz
    Parameters:
        output_filename
        source_dir
    Returns:
        Nothing
    Raises:
        Nothing
    """
    with tarfile.open(output_filename, "w:gz") as tar:
        tar.add(source_dir, arcname=os.path.basename(source_dir))


def main():
    """Main function
    Parameters:
        None
    Returns:
        Nothing
    Raises:
        ValueError for invalid arguments
    """
    # get args
    args = parseargs()

    # check parameters
    if os.path.isdir(args.folder) is not True:
        raise ValueError('Invalid folder directory')
    if os.path.isdir(args.destination) is not True:
        raise ValueError('Invalid destination directory')

    # Eliminate / at the end of the folder path

    # Change to destination folder
    os.chdir(args.destination)
    # Extract folder name
    folder_basename = os.path.basename(args.folder)
    # Create tar.gz
    make_tarfile(folder_basename + ".tar.gz", args.folder)


def parseargs():  # pragma: no cover
    """Sets up command-line arguments and parser
    Parameters:
        Nothing
    Returns:
        Parsed arguments
    Raises:
        Nothing
    """
    parser = argparse.ArgumentParser(description='Compress and move folders')
    parser.add_argument("--folder", required=True, help='specify the folder to compress')
    parser.add_argument("--destination", required=True, help='specify the folder to store the compressed folder')
    parser.add_argument("--delete", help='delete folder at the end')
    parser.add_argument("-v", "--version", help="show program's version number and exit", action='version', version=_SCRIPT_VERSION)
    return parser.parse_args()


if __name__ == '__main__':
    main()


@@ -18,19 +18,30 @@
 thon%0A%0A# 
-fil
+compressandmov
 e.py Cod
@@ -1196,31 +1196,44 @@
 e to
-%0A%0ANotes:%0A- Insert n
+ compress and move folders%0A%0AN
 otes
+:%0A-
 %0A%0ATO
@@ -1245,44 +1245,8 @@
 st:%0A
-- Check if / at the end of --folder%0A
 - Ad
@@ -1305,21 +1305,8 @@
 rse%0A
-import errno%0A
 impo
@@ -1340,16 +1340,33 @@
  shutil%0A
+# import errno%0A# 
 import s
@@ -1415,13 +1415,11 @@
  = '
-0
+1
 .0
-.2
 '%0A%0A%0A
@@ -1794,45 +1794,16 @@
     
-    None%0A    Returns:%0A        Nothing
+Returns:
 %0A   
@@ -1921,24 +1921,26 @@
 rameters%0A   
+ #
  if os.path.
@@ -1967,32 +1967,33 @@
 s not True:%0A    
+#
     raise ValueE
@@ -2144,53 +2144,181 @@
     
-# Eliminate / at the end of the folder path%0A%0A
+if os.path.isdir(args.folder) is True:%0A        # Eliminate / at the end of the folder path%0A        if args.folder%5B-1%5D is %22/%22:%0A            args.folder = args.folder%5B:-1%5D%0A    
     
@@ -2348,16 +2348,20 @@
  folder%0A
+    
     os.c
@@ -2383,16 +2383,20 @@
 nation)%0A
+    
     # Ex
@@ -2416,138 +2416,237 @@
 name
-%0A    folder_basename = os.path.basename(args.folder)%0A    # Create tar.gz%0A    make_tarfile(folder_basename + %22.tar.gz%22, args.folder
+ and create tar.gz%0A        make_tarfile(os.path.basename(args.folder) + %22.tar.gz%22, args.folder)%0A        # delete the folder if flag deleted is true%0A        if args.delete:%0A            shutil.rmtree(args.folder, ignore_errors=True
 )%0A%0A%0A
@@ -2755,85 +2755,28 @@
     
-    Nothing%0A    Returns:%0A        Parsed arguments%0A    Raises:%0A        Nothing
+Returns:%0A    Raises:
 %0A   
@@ -3097,16 +3097,37 @@
 delete%22,
+ action=%22store_true%22,
  help='d
@@ -3140,25 +3140,29 @@
 folder a
-t the end
+fter compress
 ')%0A    p

Change if