Github user ran-z commented on a diff in the pull request:

    https://github.com/apache/incubator-ariatosca/pull/97#discussion_r111399347
  
    --- Diff: aria/cli/service_template_utils.py ---
    @@ -0,0 +1,140 @@
    +# Licensed to the Apache Software Foundation (ASF) under one or more
    +# contributor license agreements.  See the NOTICE file distributed with
    +# this work for additional information regarding copyright ownership.
    +# The ASF licenses this file to You 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.
    +
    +import os
    +from urlparse import urlparse
    +
    +from . import csar
    +from . import utils
    +from .exceptions import AriaCliError
    +from .constants import SAMPLE_SERVICE_TEMPLATE_FILENAME
    +from ..utils import archive as archive_utils
    +
    +
    +def get(source, 
service_template_filename=SAMPLE_SERVICE_TEMPLATE_FILENAME):
    +    """Get a source and return a path to the main service template file
    +
    +    The behavior based on then source argument content is:
    +        -
    +        - local archive:
    +            extract it locally and return path service template file
    +        - local yaml file: return the file
    +        - URL:
    +            - return it (download=False)
    +            - download and get service template from downloaded file 
(download=True)
    +        - github repo:
    +            - map it to a URL and return it (download=False)
    +            - download and get service template from downloaded file 
(download=True)
    +
    +    Supported archive types are: csar, zip, tar, tar.gz and tar.bz2
    +
    +    :param source: Path/URL/github repo to archive/service-template file
    +    :type source: str
    +    :param service_template_filename: Path to service template (if source 
is an archive file)
    +    :type service_template_filename: str
    +    :param download: Download service template file if source is 
URL/github repo
    +    :type download: bool
    +    :return: Path to file (if archive/service-template file passed) or url
    +    :rtype: str
    +
    +    """
    +    if urlparse(source).scheme:
    +        downloaded_file = utils.download_file(source)
    +        return _get_service_template_file_from_archive(
    +            downloaded_file, service_template_filename)
    +    elif os.path.isfile(source):
    +        if _is_archive(source):
    +            return _get_service_template_file_from_archive(source, 
service_template_filename)
    +        else:
    +            # Maybe check if yaml.
    +            return source
    +    elif len(source.split('/')) == 2:
    +        url = _map_to_github_url(source)
    +        downloaded_file = utils.download_file(url)
    +        return _get_service_template_file_from_archive(
    +            downloaded_file, service_template_filename)
    +    else:
    +        raise AriaCliError(
    +            'You must provide either a path to a local file, a remote URL '
    +            'or a GitHub `organization/repository[:tag/branch]`')
    +
    +
    +def _get_service_template_file_from_archive(archive, 
service_template_filename):
    +    """Extract archive to temporary location and get path to service 
template file.
    +
    +    :param archive: Path to archive file
    +    :type archive: str
    +    :param service_template_filename: Path to service template file 
relative to archive
    +    :type service_template_filename: str
    +    :return: Absolute path to service template file
    +    :rtype: str
    +
    +    """
    +    if csar.is_csar_archive(archive):
    +        service_template_file = _extract_csar_archive(archive)
    +    else:
    +        extract_directory = archive_utils.extract_archive(archive)(archive)
    --- End diff --
    
    :+1: 


---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at infrastruct...@apache.org or file a JIRA ticket
with INFRA.
---

Reply via email to