# Path: src/rosrepo/util.py
# def write_atomic(filepath, data, mode=0o644, ignore_fail=False):
#     try:
#         fd, filepath_tmp = mkstemp(prefix=os.path.basename(filepath) + ".tmp.", dir=os.path.dirname(filepath))
#         os.fchmod(fd, mode)
#         with os.fdopen(fd, "wb") as f:
#             f.write(data)
#         os.rename(filepath_tmp, filepath)
#     except (IOError, OSError):
#         if not ignore_fail:
#             raise
# 
# def makedirs(path):
#     if not os.path.isdir(path):
#         os.makedirs(path)
# 
# class NamedTuple(object):
#     __slots__ = ()
# 
#     def __init__(self, *args, **kwargs):
#         slots = self.__slots__
#         for k in slots:
#             setattr(self, k, kwargs.get(k))
#         if args:
#             for k, v in zip(slots, args):
#                 setattr(self, k, v)
# 
#     def __str__(self):
#         clsname = self.__class__.__name__
#         values = ", ".join("%s=%r" % (k, getattr(self, k)) for k in self.__slots__)
#         return "%s(%s)" % (clsname, values)
#     __repr__ = __str__
# 
#     def __getitem__(self, item):
#         return getattr(self, self.__slots__[item])
# 
#     def __setitem__(self, item, value):
#         return setattr(self, self.__slots__[item], value)
# 
#     def __len__(self):
#         return len(self.__slots__)


import os
    import cPickle as pickle
    import pickle
import zlib
from .util import write_atomic, makedirs, NamedTuple
#
# Copyright 2016 Fraunhofer FKIE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
try:
except ImportError:


class CacheFile(NamedTuple):
    __slots__ = ("version", "obj")


class Cache(object):

    def __init__(self, wsdir):
        self.cache_dir = os.path.join(wsdir, ".rosrepo", "cache")
        self.preloaded = {}


# Path: src/rosrepo/util.py
# def write_atomic(filepath, data, mode=0o644, ignore_fail=False):
#     try:
#         fd, filepath_tmp = mkstemp(prefix=os.path.basename(filepath) + ".tmp.", dir=os.path.dirname(filepath))
#         os.fchmod(fd, mode)
#         with os.fdopen(fd, "wb") as f:
#             f.write(data)
#         os.rename(filepath_tmp, filepath)
#     except (IOError, OSError):
#         if not ignore_fail:
#             raise
# 
# def makedirs(path):
#     if not os.path.isdir(path):
#         os.makedirs(path)
# 
# class NamedTuple(object):
#     __slots__ = ()
# 
#     def __init__(self, *args, **kwargs):
#         slots = self.__slots__
#         for k in slots:
#             setattr(self, k, kwargs.get(k))
#         if args:
#             for k, v in zip(slots, args):
#                 setattr(self, k, v)
# 
#     def __str__(self):
#         clsname = self.__class__.__name__
#         values = ", ".join("%s=%r" % (k, getattr(self, k)) for k in self.__slots__)
#         return "%s(%s)" % (clsname, values)
#     __repr__ = __str__
# 
#     def __getitem__(self, item):
#         return getattr(self, self.__slots__[item])
# 
#     def __setitem__(self, item, value):
#         return setattr(self, self.__slots__[item], value)
# 
#     def __len__(self):
#         return len(self.__slots__)


# Path: src/rosrepo/cache.py
import os
    import cPickle as pickle
    import pickle
import zlib
from .util import write_atomic, makedirs, NamedTuple

#
# Copyright 2016 Fraunhofer FKIE
#
# Licensed under the Apache License, Version 2.0 (the "License");
# you may not use this file except in compliance with the License.
# You may obtain a copy of the License at
#
#     http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing, software
# distributed under the License is distributed on an "AS IS" BASIS,
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
#
try:
except ImportError:


class CacheFile(NamedTuple):
    __slots__ = ("version", "obj")


class Cache(object):

    def __init__(self, wsdir):
        self.cache_dir = os.path.join(wsdir, ".rosrepo", "cache")
        self.preloaded = {}


    def get_object(self, name, version, default=None):