Add opportunity to import package from directory
Change-Id: I23cdc5c6bfbf46fc0ca1149caeaf0bc43b2f7829 Closes-bug: #1620984
This commit is contained in:
parent
3ff7576c4d
commit
5b677b2abc
|
@ -227,6 +227,16 @@ class File(object):
|
||||||
else:
|
else:
|
||||||
if os.path.isfile(self.name):
|
if os.path.isfile(self.name):
|
||||||
return open(self.name, mode)
|
return open(self.name, mode)
|
||||||
|
if os.path.isdir(self.name):
|
||||||
|
tmp = tempfile.NamedTemporaryFile()
|
||||||
|
archive = zipfile.ZipFile(tmp, 'w', zipfile.ZIP_DEFLATED)
|
||||||
|
for root, dirs, files in os.walk(self.name):
|
||||||
|
for _file in files:
|
||||||
|
destination = os.path.relpath(
|
||||||
|
os.path.join(root, _file), os.path.join(self.name))
|
||||||
|
archive.write(os.path.join(root, _file), destination)
|
||||||
|
tmp.flush()
|
||||||
|
return open(tmp.name, mode)
|
||||||
url = urllib.parse.urlparse(self.name)
|
url = urllib.parse.urlparse(self.name)
|
||||||
if url.scheme in ('http', 'https'):
|
if url.scheme in ('http', 'https'):
|
||||||
resp = requests.get(self.name, stream=True)
|
resp = requests.get(self.name, stream=True)
|
||||||
|
|
|
@ -0,0 +1,18 @@
|
||||||
|
# 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.
|
||||||
|
|
||||||
|
Format: 1.3
|
||||||
|
Type: Application
|
||||||
|
FullName: empty
|
||||||
|
Name: empty
|
||||||
|
Description: empty description
|
||||||
|
Author: 'Mirantis, Inc'
|
|
@ -115,6 +115,14 @@ class PackageTest(testtools.TestCase):
|
||||||
path=path,
|
path=path,
|
||||||
).manifest['FullName'])
|
).manifest['FullName'])
|
||||||
|
|
||||||
|
def test_package_from_directory(self):
|
||||||
|
path = os.path.join(os.path.dirname(os.path.realpath(__file__)),
|
||||||
|
"fixture_data/empty-app")
|
||||||
|
pkg = utils.Package(utils.File(path))
|
||||||
|
self.assertEqual('empty', pkg.manifest['FullName'])
|
||||||
|
pkg = utils.Package.from_location('', path=path)
|
||||||
|
self.assertEqual('empty', pkg.manifest['FullName'])
|
||||||
|
|
||||||
@requests_mock.mock()
|
@requests_mock.mock()
|
||||||
def test_from_location_url(self, m):
|
def test_from_location_url(self, m):
|
||||||
"""Test that url overrides name specification."""
|
"""Test that url overrides name specification."""
|
||||||
|
|
|
@ -671,7 +671,8 @@ def _handle_package_exists(mc, data, package, exists_action):
|
||||||
|
|
||||||
@utils.arg('filename', metavar='<FILE>',
|
@utils.arg('filename', metavar='<FILE>',
|
||||||
nargs='+',
|
nargs='+',
|
||||||
help='URL of the murano zip package, FQPN, or path to zip package.')
|
help='URL of the murano zip package, FQPN, path to zip package'
|
||||||
|
' or path to directory with package.')
|
||||||
@utils.arg('-c', '--categories', metavar='<CATEGORY>', nargs='*',
|
@utils.arg('-c', '--categories', metavar='<CATEGORY>', nargs='*',
|
||||||
help='Category list to attach.')
|
help='Category list to attach.')
|
||||||
@utils.arg('--is-public', action='store_true', default=False,
|
@utils.arg('--is-public', action='store_true', default=False,
|
||||||
|
@ -708,7 +709,7 @@ def do_package_import(mc, args):
|
||||||
total_reqs = collections.OrderedDict()
|
total_reqs = collections.OrderedDict()
|
||||||
main_packages_names = []
|
main_packages_names = []
|
||||||
for filename in args.filename:
|
for filename in args.filename:
|
||||||
if os.path.isfile(filename):
|
if os.path.isfile(filename) or os.path.isdir(filename):
|
||||||
_file = filename
|
_file = filename
|
||||||
else:
|
else:
|
||||||
print("Package file '{0}' does not exist, attempting to download"
|
print("Package file '{0}' does not exist, attempting to download"
|
||||||
|
|
|
@ -0,0 +1,5 @@
|
||||||
|
---
|
||||||
|
features:
|
||||||
|
- Ability to load package from directory was added. If specified
|
||||||
|
directory contains all the needed files then package will be
|
||||||
|
imported as usual.
|
Loading…
Reference in New Issue