# Path: src/zinc/defaults.py

# 
# Path: src/zinc/pathfilter.py
# class PathFilter(object):
# 
#     class Rule(object):
#         def __init__(self, pattern, match_action):
#             assert match_action in (Match.ACCEPT, Match.REJECT)
#             self.pattern = pattern
#             self.match_action = match_action
# 
#         def match(self, path):
#             if fnmatch.fnmatch(path, self.pattern):
#                 return self.match_action
#             return Match.UNKNOWN
# 
#     def __init__(self, rules):
#         self._rules = rules
# 
#     def match(self, path):
#         """Tests the path against all rules in this filter"""
#         for rule in self._rules:
#             if rule.match(path) == Match.ACCEPT:
#                 return True
#             elif rule.match(path) == Match.REJECT:
#                 return False
#         return True
# 
#     @staticmethod
#     def from_rule_list(rule_list):
#         """Read from a dict. `version` is ignored"""
#         rules = []
#         for rule_string in rule_list:
#             rule_string = rule_string.strip()
#             rule_comps = rule_string.split()
#             match_action_string = rule_comps[0]
#             if match_action_string == '+':
#                 match_action = Match.ACCEPT
#             elif match_action_string == '-':
#                 match_action = Match.REJECT
#             else:
#                 raise ValueError("unknown match type: %s" %
#                                  (match_action_string))
#             pattern = string.join(rule_comps[1:], ' ')
#             rules.append(PathFilter.Rule(pattern, match_action))
#         return PathFilter(rules)


import json
import UserDict
import jsonschema
from functools import wraps
from pkg_resources import resource_string
from .defaults import defaults
from .pathfilter import PathFilter
        bundle_info = self._bundle_info_by_name.get(bundle_name)
        if bundle_info is None:
            raise Exception("Unknown bundle %s" % (bundle_name))
        for distro_name, distro_version in bundle_info['distributions'].iteritems():
            if distro_version == bundle_version:
                raise Exception("bundle '%s' v%d is referenced by the distribution '%s'"
                                % (bundle_name, bundle_version, distro_name))
        versions = bundle_info['versions']
        if bundle_version in versions:
            versions.remove(bundle_version)
        if len(versions) == 0:  # remove info if no more versions
            del self._bundle_info_by_name[bundle_name]
        else:
            bundle_info['versions'] = versions

    def distributions_for_bundle(self, bundle_name):
        bundle_info = self._bundle_info_by_name.get(bundle_name)
        if bundle_info is None:
            raise ValueError("Unknown bundle %s" % (bundle_name))
        return bundle_info['distributions']

    def distributions_for_bundle_by_version(self, bundle_name):
        distros = self.distributions_for_bundle(bundle_name)
        distros_by_version = dict()
        for distro, version in distros.iteritems():
            if distros_by_version.get(version) is None:
                distros_by_version[version] = list()
            distros_by_version[version].append(distro)
        return distros_by_version


# Path: src/zinc/defaults.py

# 
# Path: src/zinc/pathfilter.py
# class PathFilter(object):
# 
#     class Rule(object):
#         def __init__(self, pattern, match_action):
#             assert match_action in (Match.ACCEPT, Match.REJECT)
#             self.pattern = pattern
#             self.match_action = match_action
# 
#         def match(self, path):
#             if fnmatch.fnmatch(path, self.pattern):
#                 return self.match_action
#             return Match.UNKNOWN
# 
#     def __init__(self, rules):
#         self._rules = rules
# 
#     def match(self, path):
#         """Tests the path against all rules in this filter"""
#         for rule in self._rules:
#             if rule.match(path) == Match.ACCEPT:
#                 return True
#             elif rule.match(path) == Match.REJECT:
#                 return False
#         return True
# 
#     @staticmethod
#     def from_rule_list(rule_list):
#         """Read from a dict. `version` is ignored"""
#         rules = []
#         for rule_string in rule_list:
#             rule_string = rule_string.strip()
#             rule_comps = rule_string.split()
#             match_action_string = rule_comps[0]
#             if match_action_string == '+':
#                 match_action = Match.ACCEPT
#             elif match_action_string == '-':
#                 match_action = Match.REJECT
#             else:
#                 raise ValueError("unknown match type: %s" %
#                                  (match_action_string))
#             pattern = string.join(rule_comps[1:], ' ')
#             rules.append(PathFilter.Rule(pattern, match_action))
#         return PathFilter(rules)


# Path: src/zinc/models.py
import json
import UserDict
import jsonschema
from functools import wraps
from pkg_resources import resource_string
from .defaults import defaults
from .pathfilter import PathFilter

        bundle_info = self._bundle_info_by_name.get(bundle_name)
        if bundle_info is None:
            raise Exception("Unknown bundle %s" % (bundle_name))
        for distro_name, distro_version in bundle_info['distributions'].iteritems():
            if distro_version == bundle_version:
                raise Exception("bundle '%s' v%d is referenced by the distribution '%s'"
                                % (bundle_name, bundle_version, distro_name))
        versions = bundle_info['versions']
        if bundle_version in versions:
            versions.remove(bundle_version)
        if len(versions) == 0:  # remove info if no more versions
            del self._bundle_info_by_name[bundle_name]
        else:
            bundle_info['versions'] = versions

    def distributions_for_bundle(self, bundle_name):
        bundle_info = self._bundle_info_by_name.get(bundle_name)
        if bundle_info is None:
            raise ValueError("Unknown bundle %s" % (bundle_name))
        return bundle_info['distributions']

    def distributions_for_bundle_by_version(self, bundle_name):
        distros = self.distributions_for_bundle(bundle_name)
        distros_by_version = dict()
        for distro, version in distros.iteritems():
            if distros_by_version.get(version) is None:
                distros_by_version[version] = list()
            distros_by_version[version].append(distro)
        return distros_by_version


    def bundle_names(self):