<commit_before>#!/usr/bin/env python

import argparse
import atexit
import logging
from pprint import pformat

DEFAULT_DOCKER_BASE_URL = 'unix://var/run/docker.sock'
HELP_DOCKER_BASE_URL =  ('Refers to the protocol+hostname+port where the '
    'Docker server is hosted. Defaults to %s') % DEFAULT_DOCKER_BASE_URL
DEFAULT_DOCKER_API_VERSION = 'auto'
HELP_DOCKER_API_VERSION =  ('The version of the API the client will use. '
    'Defaults to use the API version provided by the server')
DEFAULT_DOCKER_HTTP_TIMEOUT = 5
HELP_DOCKER_HTTP_TIMEOUT =  ('The HTTP request timeout, in seconds. '
    'Defaults to %d secs') % DEFAULT_DOCKER_HTTP_TIMEOUT
DEFAULT_IMAGES_TO_KEEP = 2
HELP_IMAGES_TO_KEEP =  ('How many docker images to keep. '
    'Defaults to %d images') % DEFAULT_IMAGES_TO_KEEP

def _exit():
    logging.shutdown()

def debug_var(name, var):
    logging.debug('Var %s has: %s' % (name, pformat(var)))

def setup_parser(parser):
    parser.add_argument('--debug', help='debug mode', action='store_true')
    parser.add_argument('--base-url', help=HELP_DOCKER_BASE_URL, default=DEFAULT_DOCKER_BASE_URL)
    parser.add_argument('--api-version', help=HELP_DOCKER_API_VERSION, default=DEFAULT_DOCKER_API_VERSION)
    parser.add_argument('--http-timeout', help=HELP_DOCKER_HTTP_TIMEOUT, default=DEFAULT_DOCKER_HTTP_TIMEOUT, type=int)
    parser.add_argument('--images-to-keep', help=HELP_IMAGES_TO_KEEP, default=DEFAULT_IMAGES_TO_KEEP, type=int)
    return parser

def validate_args(args):
    if args.http_timeout < 0:
        raise ValueError('HTTP timeout should be 0 or bigger')
    if args.images_to_keep < 0:
        raise ValueError('Images to keep should be 0 or bigger')

def main():
    atexit.register(func=_exit)
    parser = setup_parser(argparse.ArgumentParser(description='Clean old docker images'))
    args = parser.parse_args()
    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    debug_var(name='args', var=args)
    validate_args(args)

if __name__ == '__main__':
    main()<commit_msg>Dont raise error when getting invalid parameter<commit_after>#!/usr/bin/env python

import argparse
import atexit
import logging
import sys
from pprint import pformat

DEFAULT_DOCKER_BASE_URL = 'unix://var/run/docker.sock'
HELP_DOCKER_BASE_URL =  ('Refers to the protocol+hostname+port where the '
    'Docker server is hosted. Defaults to %s') % DEFAULT_DOCKER_BASE_URL
DEFAULT_DOCKER_API_VERSION = 'auto'
HELP_DOCKER_API_VERSION =  ('The version of the API the client will use. '
    'Defaults to use the API version provided by the server')
DEFAULT_DOCKER_HTTP_TIMEOUT = 5
HELP_DOCKER_HTTP_TIMEOUT =  ('The HTTP request timeout, in seconds. '
    'Defaults to %d secs') % DEFAULT_DOCKER_HTTP_TIMEOUT
DEFAULT_IMAGES_TO_KEEP = 2
HELP_IMAGES_TO_KEEP =  ('How many docker images to keep. '
    'Defaults to %d images') % DEFAULT_IMAGES_TO_KEEP

def _exit():
    logging.shutdown()

def debug_var(name, var):
    logging.debug('Var %s has: %s' % (name, pformat(var)))

def setup_parser(parser):
    parser.add_argument('--debug', help='debug mode', action='store_true')
    parser.add_argument('--base-url', help=HELP_DOCKER_BASE_URL, default=DEFAULT_DOCKER_BASE_URL)
    parser.add_argument('--api-version', help=HELP_DOCKER_API_VERSION, default=DEFAULT_DOCKER_API_VERSION)
    parser.add_argument('--http-timeout', help=HELP_DOCKER_HTTP_TIMEOUT, default=DEFAULT_DOCKER_HTTP_TIMEOUT, type=int)
    parser.add_argument('--images-to-keep', help=HELP_IMAGES_TO_KEEP, default=DEFAULT_IMAGES_TO_KEEP, type=int)
    return parser

def validate_args(args):
    if args.http_timeout < 0:
        sys.stderr.write('HTTP timeout should be 0 or bigger\n')
    if args.images_to_keep < 0:
        sys.stderr.write('Images to keep should be 0 or bigger\n')
    sys.exit(1)

def main():
    atexit.register(func=_exit)
    parser = setup_parser(argparse.ArgumentParser(description='Clean old docker images'))
    args = parser.parse_args()
    if args.debug:
        logging.basicConfig(level=logging.DEBUG)
    debug_var(name='args', var=args)
    validate_args(args)

if __name__ == '__main__':
    main()
{'fraction_non_alphanumeric': 0.10803593105122603, 'fraction_numerical': 0.0031561058509346927, 'mean_word_length': 4.894134477825465, 'pattern_counts': {'":': 0, '<': 7, '<?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': '291801', 'n_tokens_mistral': 1419, 'n_tokens_neox': 1404, 'n_words': 322}