# Path: lab/utils.py
# def encode_path(path):
#     """Encode paths for use as file names the same way systemd does:
# 
#       "Some unit names reflect paths existing in the file system namespace.
#       Example: a device unit dev-sda.device refers to a device with the
#       device node /dev/sda in the file system namespace. If this applies, a
#       special way to escape the path name is used, so that the result is
#       usable as part of a filename. Basically, given a path, "/" is
#       replaced by "-", and all other characters which are not ASCII
#       alphanumerics are replaced by C-style "\x2d" escapes (except that "_"
#       is never replaced and "." is only replaced when it would be the first
#       character in the escaped path). The root directory "/" is encoded as
#       single dash, while otherwise the initial and ending "/" are removed
#       from all paths during transformation. This escaping is reversible."
#     """
#     # strip any initial/ending '/'
#     name = path.strip('/') if len(path) > 1 else path
#     name = ''.join(map(encode_char, name))
#     if name[0] == '.':
#         name = '\\x{:x}'.format(ord('.')) + name[1:]
#     return name


from builtins import str
from builtins import next
from builtins import object
from lab.utils import encode_path
import pytest
import re
import plumbum
import py
import itertools
            store = self.root.substorage(path)
            self.storage_cache[path] = store
            return store

    def get_storage(self, item):
        storagedir = getattr(item, '_storagedir', None)
        if not storagedir:
            storagedir = '{:03}-{}'.format(next(self.counter),
                                           sanitized_name(item.name))
            item._storagedir = storagedir
        return self.join(storagedir)

    def pytest_runtest_setup(self, item):
        # Make sure the test storage directory is created, even if the
        # test doesn't happen to use it
        self.get_storage(item)

    @pytest.hookimpl
    def pytest_lab_process_logs(self, config, item, logs):
        for ctl, logset in logs.items():
            prefix_path = '@'.join((ctl.name, ctl.hostname))
            prefix_dir = self.get_storage(item).join('logs').join(prefix_path)
            prefix_dir.mkdir()

            for remotefile, contents in logset.items():
                absname = filename = str(remotefile)

                # any plumbum remote path should be encoded as an
                # appropriate file name
                if getattr(remotefile, 'dirname', None):

# Path: lab/utils.py
# def encode_path(path):
#     """Encode paths for use as file names the same way systemd does:
# 
#       "Some unit names reflect paths existing in the file system namespace.
#       Example: a device unit dev-sda.device refers to a device with the
#       device node /dev/sda in the file system namespace. If this applies, a
#       special way to escape the path name is used, so that the result is
#       usable as part of a filename. Basically, given a path, "/" is
#       replaced by "-", and all other characters which are not ASCII
#       alphanumerics are replaced by C-style "\x2d" escapes (except that "_"
#       is never replaced and "." is only replaced when it would be the first
#       character in the escaped path). The root directory "/" is encoded as
#       single dash, while otherwise the initial and ending "/" are removed
#       from all paths during transformation. This escaping is reversible."
#     """
#     # strip any initial/ending '/'
#     name = path.strip('/') if len(path) > 1 else path
#     name = ''.join(map(encode_char, name))
#     if name[0] == '.':
#         name = '\\x{:x}'.format(ord('.')) + name[1:]
#     return name


# Path: pytest_lab/storage.py
from builtins import str
from builtins import next
from builtins import object
from lab.utils import encode_path
import pytest
import re
import plumbum
import py
import itertools

            store = self.root.substorage(path)
            self.storage_cache[path] = store
            return store

    def get_storage(self, item):
        storagedir = getattr(item, '_storagedir', None)
        if not storagedir:
            storagedir = '{:03}-{}'.format(next(self.counter),
                                           sanitized_name(item.name))
            item._storagedir = storagedir
        return self.join(storagedir)

    def pytest_runtest_setup(self, item):
        # Make sure the test storage directory is created, even if the
        # test doesn't happen to use it
        self.get_storage(item)

    @pytest.hookimpl
    def pytest_lab_process_logs(self, config, item, logs):
        for ctl, logset in logs.items():
            prefix_path = '@'.join((ctl.name, ctl.hostname))
            prefix_dir = self.get_storage(item).join('logs').join(prefix_path)
            prefix_dir.mkdir()

            for remotefile, contents in logset.items():
                absname = filename = str(remotefile)

                # any plumbum remote path should be encoded as an
                # appropriate file name
                if getattr(remotefile, 'dirname', None):

                    absname = encode_path(absname)