# Path: pypasta/Util.py
# def parse_date_ymd(ymd):
#     if isinstance(ymd, datetime.date):
#         return datetime.datetime.combine(ymd, datetime.datetime.min.time())
# 
#     try:
#         return datetime.datetime.strptime(ymd, "%Y-%m-%d")
#     except ValueError:
#         raise argparse.ArgumentTypeError("Not a valid date: '%s'" % ymd)
# 
# def load_commit_hashes(filename, ordered=True, must_exist=True):
#     content = file_to_string(filename, must_exist=must_exist)
#     if content is None:
#         content = ''
#     content = content.splitlines()
# 
#     # Filter empty lines
#     content = filter(None, content)
#     # Filter comment lines
#     content = filter(lambda x: not x.startswith('#'), content)
#     # return filtered list or set
#     if ordered:
#         return list(content)
#     else:
#         return set(content)
# 
# def persist_commit_hashes(filename, commit_hashes):
#     with open(filename, 'w') as f:
#         f.write('\n'.join(commit_hashes) + '\n')


import csv
import os
import re
from logging import getLogger
from .Util import parse_date_ymd, load_commit_hashes, persist_commit_hashes
        # Add last group
        if header is not None:
            csv_groups.append((header, content))

        log.info('  ↪ done')

        patch_stack_groups = []
        for group_name, csv_list in csv_groups:
            reader = csv.DictReader(csv_list, dialect='patchstack')
            this_group = []
            for row in reader:
                base = VersionPoint(row['BaseCommit'],
                                    row['BaseVersion'],
                                    row['BaseReleaseDate'])

                stack = VersionPoint(row['Branch'],
                                     row['StackVersion'],
                                     row['StackReleaseDate'])

                stack_hashes_location = os.path.join(config.d_stack_hashes,
                                                     stack.version)

                # check if stack hashes are existent. If not, create them
                if os.path.isfile(stack_hashes_location):
                    commit_hashes = load_commit_hashes(stack_hashes_location)
                else:
                    log.info('Calculating missing stack hashes for %s' %
                             stack.commit)
                    commit_hashes = repo.cherry(base.commit,
                                                stack.commit)

# Path: pypasta/Util.py
# def parse_date_ymd(ymd):
#     if isinstance(ymd, datetime.date):
#         return datetime.datetime.combine(ymd, datetime.datetime.min.time())
# 
#     try:
#         return datetime.datetime.strptime(ymd, "%Y-%m-%d")
#     except ValueError:
#         raise argparse.ArgumentTypeError("Not a valid date: '%s'" % ymd)
# 
# def load_commit_hashes(filename, ordered=True, must_exist=True):
#     content = file_to_string(filename, must_exist=must_exist)
#     if content is None:
#         content = ''
#     content = content.splitlines()
# 
#     # Filter empty lines
#     content = filter(None, content)
#     # Filter comment lines
#     content = filter(lambda x: not x.startswith('#'), content)
#     # return filtered list or set
#     if ordered:
#         return list(content)
#     else:
#         return set(content)
# 
# def persist_commit_hashes(filename, commit_hashes):
#     with open(filename, 'w') as f:
#         f.write('\n'.join(commit_hashes) + '\n')


# Path: pypasta/PatchStack.py
import csv
import os
import re
from logging import getLogger
from .Util import parse_date_ymd, load_commit_hashes, persist_commit_hashes

        # Add last group
        if header is not None:
            csv_groups.append((header, content))

        log.info('  ↪ done')

        patch_stack_groups = []
        for group_name, csv_list in csv_groups:
            reader = csv.DictReader(csv_list, dialect='patchstack')
            this_group = []
            for row in reader:
                base = VersionPoint(row['BaseCommit'],
                                    row['BaseVersion'],
                                    row['BaseReleaseDate'])

                stack = VersionPoint(row['Branch'],
                                     row['StackVersion'],
                                     row['StackReleaseDate'])

                stack_hashes_location = os.path.join(config.d_stack_hashes,
                                                     stack.version)

                # check if stack hashes are existent. If not, create them
                if os.path.isfile(stack_hashes_location):
                    commit_hashes = load_commit_hashes(stack_hashes_location)
                else:
                    log.info('Calculating missing stack hashes for %s' %
                             stack.commit)
                    commit_hashes = repo.cherry(base.commit,
                                                stack.commit)

                    persist_commit_hashes(stack_hashes_location, commit_hashes)