<commit_before>#!/usr/bin/env python
__author__ = 'toly'
"""
    Format log file:
        timestamp1  project_path1   branch1
        timestamp1  project_path2   branch2
        timestamp2  project_path1   branch3
"""

import os
import time
import commands
from collections import defaultdict
from datetime import datetime
from argparse import ArgumentParser, ArgumentTypeError


HOME_DIR = os.path.expanduser('~')
APP_DIR = os.path.join(HOME_DIR, '.wtlog')
CONFIG = os.path.join(APP_DIR, 'projects.conf')
LOG_FORMAT = '{timestamp}\t{project_path}\t{branch}\n'


def valid_date(s):
    try:
        return datetime.strptime(s, "%Y.%m.%d")
    except ValueError:
        msg = "Not a valid date: '{0}'.".format(s)
        raise ArgumentTypeError(msg)


def create_arg_parser():
    parser = ArgumentParser(prog='wtlog')
    parser.add_argument('-i', '--init', action="store_true",
                        help="Init WTLog:\n 1. make dirs\n 2. find projects (.git/)\n 3. update crontab")
    parser.add_argument('-l', '--log', action="store_true",
                        help="Logging state of project dirs")
    parser.add_argument('-r', '--report', action="store_true",
                        help="Output report")
    parser.add_argument('-d', '--date', type=valid_date)
    return parser


def get_projects():
    with open(CONFIG) as f:
        lines = f.readlines()
    lines = map(lambda x: x.strip(), lines)
    lines.sort()
    lines = filter(None, lines)
    return lines

<commit_msg>refactoring - move valid_date to argument parser<commit_after>#!/usr/bin/env python
__author__ = 'toly'
"""
    Format log file:
        timestamp1  project_path1   branch1
        timestamp1  project_path2   branch2
        timestamp2  project_path1   branch3
"""

import os
import time
import commands
from collections import defaultdict
from datetime import datetime
from argparse import ArgumentParser, ArgumentTypeError


HOME_DIR = os.path.expanduser('~')
APP_DIR = os.path.join(HOME_DIR, '.wtlog')
CONFIG = os.path.join(APP_DIR, 'projects.conf')
LOG_FORMAT = '{timestamp}\t{project_path}\t{branch}\n'


def create_arg_parser():

    def valid_date(s):
        try:
            return datetime.strptime(s, "%Y.%m.%d")
        except ValueError:
            msg = "Not a valid date: '{0}'.".format(s)
            raise ArgumentTypeError(msg)

    parser = ArgumentParser(prog='wtlog')
    parser.add_argument('-i', '--init', action="store_true",
                        help="Init WTLog:\n 1. make dirs\n 2. find projects (.git/)\n 3. update crontab")
    parser.add_argument('-l', '--log', action="store_true",
                        help="Logging state of project dirs")
    parser.add_argument('-r', '--report', action="store_true",
                        help="Output report")
    parser.add_argument('-d', '--date', type=valid_date)
    return parser


def get_projects():
    with open(CONFIG) as f:
        lines = f.readlines()
    lines = map(lambda x: x.strip(), lines)
    lines.sort()
    lines = filter(None, lines)
    return lines


{'fraction_non_alphanumeric': 0.13283043620859297, 'fraction_numerical': 0.008527386028205968, 'mean_word_length': 2.8705583756345177, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '148316', 'n_tokens_mistral': 968, 'n_tokens_neox': 935, 'n_words': 239}