# Path: django_test_tools/file_utils.py
# def add_date(filename, **kwargs):
#     """
#     Adds to a filename the current date and time in '%Y%m%d_%H%M' format.
#     For a filename /my/path/myexcel.xlsx the function would return /my/path/myexcel_20170101_1305.xlsx.
#     If the file already exists the function will add seconds to the date to attempt to get a unique name.
# 
#     The function will detect if another file exists with the same name if it exist it will append seconds to the
#     filename. For example if file /my/path/myexcel_20170101_1305.xlsx alread exist thte function will return
#     /my/path/myexcel_20170101_130521.xlsx.
# 
#     :param filename: string with fullpath to file or just the filename
#     :param kwargs: dictionary. date_position: suffix or preffix, extension: string to replace extension
#     :return: string with full path string including the date and time
#     """
#     current_datetime = timezone.localtime(timezone.now()).strftime('%Y%m%d_%H%M%S')
#     new_filename_data = dict()
#     suffix_template = '{path}{separator}{filename_with_out_extension}_{datetime}.{extension}'
#     prefix_template = '{path}{separator}{datetime}_{filename_with_out_extension}.{extension}'
#     if '/' in filename and '\\' in filename:
#         raise ValueError('Filename %s contains both / and \\ separators' % filename)
#     if '\\' in filename:
#         path_parts = filename.split('\\')
#         file = path_parts[-1]
#         path = '\\'.join(path_parts[:-1])
#         separator = '\\'
#     elif '/' in filename:
#         path_parts = filename.split('/')
#         file = path_parts[-1]
#         path = '/'.join(path_parts[:-1])
#         separator = '/'
#     else:
#         file = filename
#         path = ''
#         separator = ''
# 
#     new_filename_data['path'] = path
#     parts = file.split('.')
#     if kwargs.get('extension', None) is not None:
#         new_filename_data['extension'] = kwargs['extension']
#     else:
#         if len(parts) > 1:
#             new_filename_data['extension'] = parts[-1]
#         else:
#             new_filename_data['extension'] = ''
# 
#     new_filename_data['separator'] = separator
#     if new_filename_data['extension'] == '':
#         new_filename_data['filename_with_out_extension'] = parts[0]
#     else:
#         new_filename_data['filename_with_out_extension'] = '.'.join(parts[:-1])
#     new_filename_data['datetime'] = current_datetime[:-2]  # Seconds are stripped
# 
#     date_position = kwargs.get('date_position', 'suffix')
#     if date_position == 'suffix':
#         new_filename = suffix_template.format(**new_filename_data)
#         if os.path.exists(new_filename):
#             new_filename_data['datetime'] = current_datetime
#             new_filename = suffix_template.format(**new_filename_data)
#         if new_filename_data['extension'] == '':
#             new_filename = new_filename[:-1]
#     else:
#         new_filename = prefix_template.format(**new_filename_data)
#         if os.path.exists(new_filename):
#             new_filename_data['datetime'] = current_datetime
#             new_filename = prefix_template.format(**new_filename_data)
#         if new_filename_data['extension'] == '':
#             new_filename = new_filename[:-1]
# 
#     return new_filename


import os
from django.core.management import BaseCommand
from ...file_utils import add_date
from ...flake8.parsers import Flake8Parser, RadonParser
        #                     )
        # parser.add_argument("-a", "--assign",
        #                     action='store_true',
        #                     dest="assign",
        #                     help="Create unit assignments",
        #                     )
        #
        # parser.add_argument("--office",
        #                     dest="office",
        #                     help="Organizational unit short name",
        #                     default=None,
        #                     )
        # parser.add_argument("--start-date",
        #                     dest="start_date",
        #                     help="Start date for the assignment",
        #                     default=None,
        #                     )
        # parser.add_argument("--fiscal-year",
        #                     dest="fiscal_year",
        #                     help="Fiscal year for assignments",
        #                     default=None,
        #                     )
        # parser.add_argument("-u", "--username",
        #                 dest="usernames",
        #                 help="LDAP usernames for employees",
        #                 nargs='+',
        #                 )

    def handle(self, *args, **options):
        if not options.get('output_file'):

# Path: django_test_tools/file_utils.py
# def add_date(filename, **kwargs):
#     """
#     Adds to a filename the current date and time in '%Y%m%d_%H%M' format.
#     For a filename /my/path/myexcel.xlsx the function would return /my/path/myexcel_20170101_1305.xlsx.
#     If the file already exists the function will add seconds to the date to attempt to get a unique name.
# 
#     The function will detect if another file exists with the same name if it exist it will append seconds to the
#     filename. For example if file /my/path/myexcel_20170101_1305.xlsx alread exist thte function will return
#     /my/path/myexcel_20170101_130521.xlsx.
# 
#     :param filename: string with fullpath to file or just the filename
#     :param kwargs: dictionary. date_position: suffix or preffix, extension: string to replace extension
#     :return: string with full path string including the date and time
#     """
#     current_datetime = timezone.localtime(timezone.now()).strftime('%Y%m%d_%H%M%S')
#     new_filename_data = dict()
#     suffix_template = '{path}{separator}{filename_with_out_extension}_{datetime}.{extension}'
#     prefix_template = '{path}{separator}{datetime}_{filename_with_out_extension}.{extension}'
#     if '/' in filename and '\\' in filename:
#         raise ValueError('Filename %s contains both / and \\ separators' % filename)
#     if '\\' in filename:
#         path_parts = filename.split('\\')
#         file = path_parts[-1]
#         path = '\\'.join(path_parts[:-1])
#         separator = '\\'
#     elif '/' in filename:
#         path_parts = filename.split('/')
#         file = path_parts[-1]
#         path = '/'.join(path_parts[:-1])
#         separator = '/'
#     else:
#         file = filename
#         path = ''
#         separator = ''
# 
#     new_filename_data['path'] = path
#     parts = file.split('.')
#     if kwargs.get('extension', None) is not None:
#         new_filename_data['extension'] = kwargs['extension']
#     else:
#         if len(parts) > 1:
#             new_filename_data['extension'] = parts[-1]
#         else:
#             new_filename_data['extension'] = ''
# 
#     new_filename_data['separator'] = separator
#     if new_filename_data['extension'] == '':
#         new_filename_data['filename_with_out_extension'] = parts[0]
#     else:
#         new_filename_data['filename_with_out_extension'] = '.'.join(parts[:-1])
#     new_filename_data['datetime'] = current_datetime[:-2]  # Seconds are stripped
# 
#     date_position = kwargs.get('date_position', 'suffix')
#     if date_position == 'suffix':
#         new_filename = suffix_template.format(**new_filename_data)
#         if os.path.exists(new_filename):
#             new_filename_data['datetime'] = current_datetime
#             new_filename = suffix_template.format(**new_filename_data)
#         if new_filename_data['extension'] == '':
#             new_filename = new_filename[:-1]
#     else:
#         new_filename = prefix_template.format(**new_filename_data)
#         if os.path.exists(new_filename):
#             new_filename_data['datetime'] = current_datetime
#             new_filename = prefix_template.format(**new_filename_data)
#         if new_filename_data['extension'] == '':
#             new_filename = new_filename[:-1]
# 
#     return new_filename


# Path: django_test_tools/management/commands/parse_qc_files.py
import os
from django.core.management import BaseCommand
from ...file_utils import add_date
from ...flake8.parsers import Flake8Parser, RadonParser

        #                     )
        # parser.add_argument("-a", "--assign",
        #                     action='store_true',
        #                     dest="assign",
        #                     help="Create unit assignments",
        #                     )
        #
        # parser.add_argument("--office",
        #                     dest="office",
        #                     help="Organizational unit short name",
        #                     default=None,
        #                     )
        # parser.add_argument("--start-date",
        #                     dest="start_date",
        #                     help="Start date for the assignment",
        #                     default=None,
        #                     )
        # parser.add_argument("--fiscal-year",
        #                     dest="fiscal_year",
        #                     help="Fiscal year for assignments",
        #                     default=None,
        #                     )
        # parser.add_argument("-u", "--username",
        #                 dest="usernames",
        #                 help="LDAP usernames for employees",
        #                 nargs='+',
        #                 )

    def handle(self, *args, **options):
        if not options.get('output_file'):

            output_filename = add_date(options.get('input_file'))