# Path: bento/core/options.py
# def raw_to_options_kw(raw):
#     d = build_ast_from_raw_dict(raw)
# 
#     kw = {}
#     if not "name" in d:
#         raise ValueError("No name field found")
#     kw["name"] = d["name"]
# 
#     kw["path_options"] = {}
#     path_options = d.get("path_options", {})
#     for name, path in path_options.items():
#         kw["path_options"][name] = PathOption(path["name"],
#                                               path["default"],
#                                               path["description"])
# 
#     kw["flag_options"] = {}
#     flag_options = d.get("flag_options", {})
#     for name, flag in flag_options.items():
#         kw["flag_options"][name] = FlagOption(flag["name"],
#                                               flag["default"],
#                                               flag["description"])
# 
#     return kw
# 
# class PackageOptions(object):
#     @classmethod
#     def __from_data(cls, data):
#         raw = raw_parse(data)
#         kw = raw_to_options_kw(raw)
#         return cls(**kw)
# 
#     @classmethod
#     def from_string(cls, str):
#         """Create a PackageOptions instance from a bento.info content."""
#         return cls.__from_data(str)
# 
#     @classmethod
#     def from_file(cls, filename):
#         """Create a PackageOptions instance from a bento.info file."""
#         fid = open(filename, 'r')
#         try:
#             data = fid.read()
#             return cls.__from_data(data)
#         finally:
#             fid.close()
# 
#     def __init__(self, name, path_options=None, flag_options=None):
#         """Create a PackageOptions instance
# 
#         Parameters
#         ----------
#         name: str
#             name of the package
#         path_options: dict
#             dict of path options
#         flag_options: dict
#             dict of flag options
#         """
#         self.name = name
# 
#         if not path_options:
#             self.path_options = {}
#         else:
#             self.path_options = path_options
# 
#         if not flag_options:
#             self.flag_options = {}
#         else:
#             self.flag_options = flag_options
# 
# Path: bento/utils/utils.py
# def extract_exception():
#     """Extract the last exception.
# 
#     Used to avoid the except ExceptionType as e, which cannot be written the
#     same across supported versions. I.e::
# 
#         try:
#             ...
#         except Exception, e:
#             ...
# 
#     becomes:
# 
#         try:
#             ...
#         except Exception:
#             e = extract_exception()
#     """
#     return sys.exc_info()[1]


import os
import sys
import warnings
import bento.utils.path
import bento.utils.io2
    import cPickle as pickle
    import pickle
from bento.parser.misc \
    import \
        raw_parse
from bento.core.package \
    import \
        raw_to_pkg_kw, PackageDescription
from bento.core.options \
    import \
        raw_to_options_kw, PackageOptions
from bento.utils.utils import extract_exception
    from hashlib import md5
    from md5 import md5
            return self._get_package(bento_info, user_flags)
        except Exception:
            e = extract_exception()
            warnings.warn("Resetting invalid cache (error was %r)" % e)
            self._reset()
            return self._get_package(bento_info, user_flags)

    def _get_package(self, bento_info, user_flags=None):
        if self._first_time:
            self._first_time = False
            return _create_package_nocached(bento_info, user_flags, self.db)
        else:
            if self._has_invalidated_cache():
                return _create_package_nocached(bento_info, user_flags, self.db)
            else:
                r_user_flags = pickle.loads(self.db["user_flags"])
                if user_flags is None:
                    # FIXME: this case is wrong
                    return pickle.loads(self.db["package_description"])
                elif r_user_flags != user_flags:
                    return _create_package_nocached(bento_info, user_flags, self.db)
                else:
                    raw = pickle.loads(self.db["parsed_dict"])
                    pkg, files = _raw_to_pkg(raw, user_flags, bento_info)
                    return pkg

    def get_options(self, bento_info):
        try:
            return self._get_options(bento_info)
        except Exception:

# Path: bento/core/options.py
# def raw_to_options_kw(raw):
#     d = build_ast_from_raw_dict(raw)
# 
#     kw = {}
#     if not "name" in d:
#         raise ValueError("No name field found")
#     kw["name"] = d["name"]
# 
#     kw["path_options"] = {}
#     path_options = d.get("path_options", {})
#     for name, path in path_options.items():
#         kw["path_options"][name] = PathOption(path["name"],
#                                               path["default"],
#                                               path["description"])
# 
#     kw["flag_options"] = {}
#     flag_options = d.get("flag_options", {})
#     for name, flag in flag_options.items():
#         kw["flag_options"][name] = FlagOption(flag["name"],
#                                               flag["default"],
#                                               flag["description"])
# 
#     return kw
# 
# class PackageOptions(object):
#     @classmethod
#     def __from_data(cls, data):
#         raw = raw_parse(data)
#         kw = raw_to_options_kw(raw)
#         return cls(**kw)
# 
#     @classmethod
#     def from_string(cls, str):
#         """Create a PackageOptions instance from a bento.info content."""
#         return cls.__from_data(str)
# 
#     @classmethod
#     def from_file(cls, filename):
#         """Create a PackageOptions instance from a bento.info file."""
#         fid = open(filename, 'r')
#         try:
#             data = fid.read()
#             return cls.__from_data(data)
#         finally:
#             fid.close()
# 
#     def __init__(self, name, path_options=None, flag_options=None):
#         """Create a PackageOptions instance
# 
#         Parameters
#         ----------
#         name: str
#             name of the package
#         path_options: dict
#             dict of path options
#         flag_options: dict
#             dict of flag options
#         """
#         self.name = name
# 
#         if not path_options:
#             self.path_options = {}
#         else:
#             self.path_options = path_options
# 
#         if not flag_options:
#             self.flag_options = {}
#         else:
#             self.flag_options = flag_options
# 
# Path: bento/utils/utils.py
# def extract_exception():
#     """Extract the last exception.
# 
#     Used to avoid the except ExceptionType as e, which cannot be written the
#     same across supported versions. I.e::
# 
#         try:
#             ...
#         except Exception, e:
#             ...
# 
#     becomes:
# 
#         try:
#             ...
#         except Exception:
#             e = extract_exception()
#     """
#     return sys.exc_info()[1]


# Path: bentomakerlib/package_cache.py
import os
import sys
import warnings
import bento.utils.path
import bento.utils.io2
    import cPickle as pickle
    import pickle
from bento.parser.misc \
    import \
        raw_parse
from bento.core.package \
    import \
        raw_to_pkg_kw, PackageDescription
from bento.core.options \
    import \
        raw_to_options_kw, PackageOptions
from bento.utils.utils import extract_exception
    from hashlib import md5
    from md5 import md5

            return self._get_package(bento_info, user_flags)
        except Exception:
            e = extract_exception()
            warnings.warn("Resetting invalid cache (error was %r)" % e)
            self._reset()
            return self._get_package(bento_info, user_flags)

    def _get_package(self, bento_info, user_flags=None):
        if self._first_time:
            self._first_time = False
            return _create_package_nocached(bento_info, user_flags, self.db)
        else:
            if self._has_invalidated_cache():
                return _create_package_nocached(bento_info, user_flags, self.db)
            else:
                r_user_flags = pickle.loads(self.db["user_flags"])
                if user_flags is None:
                    # FIXME: this case is wrong
                    return pickle.loads(self.db["package_description"])
                elif r_user_flags != user_flags:
                    return _create_package_nocached(bento_info, user_flags, self.db)
                else:
                    raw = pickle.loads(self.db["parsed_dict"])
                    pkg, files = _raw_to_pkg(raw, user_flags, bento_info)
                    return pkg

    def get_options(self, bento_info):
        try:
            return self._get_options(bento_info)
        except Exception:

            e = extract_exception()