# Path: filetracker/utils.py
# def split_name(name):
#     """Splits a (possibly versioned) name into unversioned name and version.
# 
#     Returns a tuple ``(unversioned_name, version)``, where ``version`` may
#     be ``None``.
#     """
#     s = name.rsplit('@', 1)
#     if len(s) == 1:
#         return s[0], None
#     else:
#         try:
#             return s[0], int(s[1])
#         except ValueError:
#             raise ValueError(
#                 "Invalid Filetracker filename: version must " "be int, not %r" % (s[1],)
#             )
# 
# def check_name(name, allow_version=True):
#     if not isinstance(name, six.string_types):
#         raise ValueError("Invalid Filetracker filename: not string: %r" % (name,))
#     parts = name.split('/')
#     if not parts:
#         raise ValueError("Invalid Filetracker filename: empty name")
#     if parts[0]:
#         raise ValueError("Invalid Filetracker filename: does not start with /")
#     if '..' in parts:
#         raise ValueError("Invalid Filetracker filename: .. in path")
#     if '@' in ''.join(parts[:-1]):
#         raise ValueError("Invalid Filetracker filename: @ in path")
#     if len(parts[-1].split('@')) > 2:
#         raise ValueError("Invalid Filetracker filename: multiple versions")
#     if '@' in parts[-1] and not allow_version:
#         raise ValueError(
#             "Invalid Filetracker filename: version not allowed " "in this API call"
#         )
# 
# def mkdir(name):
#     try:
#         os.makedirs(name, 0o700)
#     except OSError as e:
#         if e.errno != errno.EEXIST:
#             raise
# 
# def rmdirs(name, root):
#     """Removes empty directories from ``name`` upwards, stops at ``root``."""
#     while name != root:
#         try:
#             os.rmdir(name)
#             name = os.path.dirname(name)
#         except OSError as e:
#             if e.errno in (errno.ENOTEMPTY, errno.ENOENT):
#                 return
#             else:
#                 raise


import fcntl
import os
from filetracker.utils import split_name, check_name, mkdir, rmdirs
        )

    def __del__(self):
        os.close(self.tree_lock_fd)

    def lock_for(self, name):
        check_name(name)
        name, version = split_name(name)
        path = self.dir + name
        return self.FcntlLock(self, path)


class NoOpLockManager(LockManager):
    """A no-op :class:`LockManager`.

    It may be used when no local store is configured, as we probably do not
    need concurrency control.
    """

    class NoOpLock(LockManager.Lock):
        def lock_shared(self):
            pass

        def lock_exclusive(self):
            pass

        def unlock(self):
            pass

    def lock_for(self, name):

# Path: filetracker/utils.py
# def split_name(name):
#     """Splits a (possibly versioned) name into unversioned name and version.
# 
#     Returns a tuple ``(unversioned_name, version)``, where ``version`` may
#     be ``None``.
#     """
#     s = name.rsplit('@', 1)
#     if len(s) == 1:
#         return s[0], None
#     else:
#         try:
#             return s[0], int(s[1])
#         except ValueError:
#             raise ValueError(
#                 "Invalid Filetracker filename: version must " "be int, not %r" % (s[1],)
#             )
# 
# def check_name(name, allow_version=True):
#     if not isinstance(name, six.string_types):
#         raise ValueError("Invalid Filetracker filename: not string: %r" % (name,))
#     parts = name.split('/')
#     if not parts:
#         raise ValueError("Invalid Filetracker filename: empty name")
#     if parts[0]:
#         raise ValueError("Invalid Filetracker filename: does not start with /")
#     if '..' in parts:
#         raise ValueError("Invalid Filetracker filename: .. in path")
#     if '@' in ''.join(parts[:-1]):
#         raise ValueError("Invalid Filetracker filename: @ in path")
#     if len(parts[-1].split('@')) > 2:
#         raise ValueError("Invalid Filetracker filename: multiple versions")
#     if '@' in parts[-1] and not allow_version:
#         raise ValueError(
#             "Invalid Filetracker filename: version not allowed " "in this API call"
#         )
# 
# def mkdir(name):
#     try:
#         os.makedirs(name, 0o700)
#     except OSError as e:
#         if e.errno != errno.EEXIST:
#             raise
# 
# def rmdirs(name, root):
#     """Removes empty directories from ``name`` upwards, stops at ``root``."""
#     while name != root:
#         try:
#             os.rmdir(name)
#             name = os.path.dirname(name)
#         except OSError as e:
#             if e.errno in (errno.ENOTEMPTY, errno.ENOENT):
#                 return
#             else:
#                 raise


# Path: filetracker/client/lock_manager.py
import fcntl
import os
from filetracker.utils import split_name, check_name, mkdir, rmdirs

        )

    def __del__(self):
        os.close(self.tree_lock_fd)

    def lock_for(self, name):
        check_name(name)
        name, version = split_name(name)
        path = self.dir + name
        return self.FcntlLock(self, path)


class NoOpLockManager(LockManager):
    """A no-op :class:`LockManager`.

    It may be used when no local store is configured, as we probably do not
    need concurrency control.
    """

    class NoOpLock(LockManager.Lock):
        def lock_shared(self):
            pass

        def lock_exclusive(self):
            pass

        def unlock(self):
            pass

    def lock_for(self, name):

        check_name(name)