Merge "Add opportunity to import package from directory"
This commit is contained in:
commit
23ac68eb5f
@ -227,6 +227,16 @@ class File(object):
|
||||
else:
|
||||
if os.path.isfile(self.name):
|
||||
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)
|
||||
if url.scheme in ('http', 'https'):
|
||||
resp = requests.get(self.name, stream=True)
|
||||
|
18
muranoclient/tests/unit/fixture_data/empty-app/manifest.yaml
Normal file
18
muranoclient/tests/unit/fixture_data/empty-app/manifest.yaml
Normal file
@ -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,
|
||||
).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()
|
||||
def test_from_location_url(self, m):
|
||||
"""Test that url overrides name specification."""
|
||||
|
@ -680,7 +680,8 @@ def _handle_package_exists(mc, data, package, exists_action):
|
||||
|
||||
@utils.arg('filename', metavar='<FILE>',
|
||||
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='*',
|
||||
help='Category list to attach.')
|
||||
@utils.arg('--is-public', action='store_true', default=False,
|
||||
@ -717,7 +718,7 @@ def do_package_import(mc, args):
|
||||
total_reqs = collections.OrderedDict()
|
||||
main_packages_names = []
|
||||
for filename in args.filename:
|
||||
if os.path.isfile(filename):
|
||||
if os.path.isfile(filename) or os.path.isdir(filename):
|
||||
_file = filename
|
||||
else:
|
||||
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
Block a user