#!/usr/bin/env python
# encoding: utf-8
#
# Copyright SAS Institute
#
#  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.
#

''' Project Utilities '''

from __future__ import print_function, division, absolute_import, unicode_literals


def expand_path(path):
    '''
    Convert string path to window path components

    Parameters
    ----------
    path : string
        A '.' or '/' delimited string containing a project,
        continuous query, or window path.

    Returns
    -------
    list of list-of-strings or strings or None

    '''
    parts = None

    if path is None:
        return []

    if isinstance(path, (list, tuple)):
        path = '|'.join(path)

    if '.' in path:
        parts = [x.split('|') for x in path.split('.')]
    elif '/' in path:
        parts = [x.split('|') for x in path.split('/')]
    else:
        parts = [path.split('|')]

    for i, part in enumerate(parts):
        if '*' in part:
            parts[i] = None
        elif len(part) == 1:
            parts[i] = part[0]

    return parts
