# Path: siptools/utils.py
# def fsencode_path(filename):
#     """
#     Encode Unicode filenames using the file system encoding.
# 
#     :filename: File path to encode
#     :returns: Encoded path
#     :raises: TypeError if wrong type given
#     """
#     if isinstance(filename, six.text_type):
#         return filename.encode(encoding=sys.getfilesystemencoding())
#     if isinstance(filename, six.binary_type):
#         return filename
# 
#     raise TypeError("Value is not a (byte) string")


import sys
import subprocess
import click
from siptools.utils import fsencode_path
"""Command line tool for creating tar file from SIP directory"""
from __future__ import unicode_literals, print_function




click.disable_unicode_literals_warning = True


@click.command()
@click.argument('dir_to_tar', type=click.Path(exists=True))
@click.option(
    '--tar_filename', type=str, default='sip.tar',
    metavar='<TAR FILE>',
    help="Filename for tar. Default is sip.tar")
def main(dir_to_tar, tar_filename):
    """Create tar file from SIP directory.

    DIR_TO_TAR: Directory to be added in the TAR file.
    """
    return compress(dir_to_tar, tar_filename)


def compress(dir_to_tar, tar_filename):
    """
    Create tar file from SIP directory.

    :dir_to_tar: Directory to pack in tar package
    :tar_filename: File name of the tar file
    """

# Path: siptools/utils.py
# def fsencode_path(filename):
#     """
#     Encode Unicode filenames using the file system encoding.
# 
#     :filename: File path to encode
#     :returns: Encoded path
#     :raises: TypeError if wrong type given
#     """
#     if isinstance(filename, six.text_type):
#         return filename.encode(encoding=sys.getfilesystemencoding())
#     if isinstance(filename, six.binary_type):
#         return filename
# 
#     raise TypeError("Value is not a (byte) string")


# Path: siptools/scripts/compress.py
import sys
import subprocess
import click
from siptools.utils import fsencode_path

"""Command line tool for creating tar file from SIP directory"""
from __future__ import unicode_literals, print_function




click.disable_unicode_literals_warning = True


@click.command()
@click.argument('dir_to_tar', type=click.Path(exists=True))
@click.option(
    '--tar_filename', type=str, default='sip.tar',
    metavar='<TAR FILE>',
    help="Filename for tar. Default is sip.tar")
def main(dir_to_tar, tar_filename):
    """Create tar file from SIP directory.

    DIR_TO_TAR: Directory to be added in the TAR file.
    """
    return compress(dir_to_tar, tar_filename)


def compress(dir_to_tar, tar_filename):
    """
    Create tar file from SIP directory.

    :dir_to_tar: Directory to pack in tar package
    :tar_filename: File name of the tar file
    """

    command = ['tar', '-cvvf', fsencode_path(tar_filename), '.']