#!/usr/bin/python
# -*- coding: utf-8 -*-

import argparse
import re

from knapsack.utils import read_file
from knapsack.utils import remove_version_or_discard


if __name__ == '__main__':
    parser = argparse.ArgumentParser(description='Group files in directories and add the size.')
    parser.add_argument('file', help='File to remove the version name')

    args = parser.parse_args()

    items = read_file(args.file, laplacian=False)

    items_group = {}
    for value, path in items:
        path = remove_version_or_discard(path)
        if path:
            old_value = items_group.get(path, 0)
            items_group[path] = old_value + value

    for path, size in items_group.iteritems():
        print size, path
