# Path: scuba/dockerutil.py
# def make_vol_opt(hostdir, contdir, options=None):
#     '''Generate a docker volume option'''
#     vol = '--volume={}:{}'.format(hostdir, contdir)
#     if options != None:
#         if isinstance(options, str):
#             options = (options,)
#         vol += ':' + ','.join(options)
#     return vol


import collections
import os
import yaml
import re
import shlex
from .constants import *
from .utils import *
from .dockerutil import make_vol_opt

        # Simple form:
        # volumes:
        #   /foo: /host/foo
        if isinstance(node, str):
            return cls(
                container_path = cpath,
                host_path = _expand_path(node),
                )

        # Complex form
        # volumes:
        #   /foo:
        #     hostpath: /host/foo
        #     options: ro,z
        if isinstance(node, dict):
            hpath = node.get('hostpath')
            if hpath is None:
                raise ConfigError("Volume {} must have a 'hostpath' subkey".format(cpath))
            return cls(
                container_path = cpath,
                host_path = _expand_path(hpath),
                options = _get_delimited_str_list(node, 'options', ','),
                )

        raise ConfigError("{}: must be string or dict".format(cpath))

    def get_vol_opt(self):
        if not self.host_path:
            raise NotImplementedError("No anonymous volumes for now")

# Path: scuba/dockerutil.py
# def make_vol_opt(hostdir, contdir, options=None):
#     '''Generate a docker volume option'''
#     vol = '--volume={}:{}'.format(hostdir, contdir)
#     if options != None:
#         if isinstance(options, str):
#             options = (options,)
#         vol += ':' + ','.join(options)
#     return vol


# Path: scuba/config.py
import collections
import os
import yaml
import re
import shlex
from .constants import *
from .utils import *
from .dockerutil import make_vol_opt


        # Simple form:
        # volumes:
        #   /foo: /host/foo
        if isinstance(node, str):
            return cls(
                container_path = cpath,
                host_path = _expand_path(node),
                )

        # Complex form
        # volumes:
        #   /foo:
        #     hostpath: /host/foo
        #     options: ro,z
        if isinstance(node, dict):
            hpath = node.get('hostpath')
            if hpath is None:
                raise ConfigError("Volume {} must have a 'hostpath' subkey".format(cpath))
            return cls(
                container_path = cpath,
                host_path = _expand_path(hpath),
                options = _get_delimited_str_list(node, 'options', ','),
                )

        raise ConfigError("{}: must be string or dict".format(cpath))

    def get_vol_opt(self):
        if not self.host_path:
            raise NotImplementedError("No anonymous volumes for now")

        return make_vol_opt(self.host_path, self.container_path, self.options)