Added command-line interface for create_repository
Change-Id: I22b39adc9a40be8e9d500a81dfef7cbf49f8b651 Implements: blueprint build-repository
This commit is contained in:
parent
aff85a919e
commit
cacf6b75e3
@ -1,6 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2015 Mirantis, Inc.
|
||||
# Copyright 2016 Mirantis, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
@ -56,16 +56,6 @@ class BaseRepoCommand(command.Command):
|
||||
default="x86_64",
|
||||
help='The target architecture.')
|
||||
|
||||
parser.add_argument(
|
||||
'-r', '--repositories',
|
||||
dest='repositories',
|
||||
type=read_from_file,
|
||||
metavar='FILENAME',
|
||||
required=True,
|
||||
help="The path to file with list of repositories."
|
||||
"See documentation about format."
|
||||
)
|
||||
|
||||
return parser
|
||||
|
||||
def take_action(self, parsed_args):
|
||||
@ -92,6 +82,22 @@ class BaseRepoCommand(command.Command):
|
||||
"""
|
||||
|
||||
|
||||
class RepositoriesMixin(object):
|
||||
def get_parser(self, prog_name):
|
||||
"""Specifies common options."""
|
||||
parser = super(RepositoriesMixin, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'-r', '--repositories',
|
||||
dest='repositories',
|
||||
type=read_from_file,
|
||||
metavar='FILENAME',
|
||||
required=True,
|
||||
help="The path to file with list of repositories."
|
||||
"See documentation about format."
|
||||
)
|
||||
return parser
|
||||
|
||||
|
||||
class PackagesMixin(object):
|
||||
"""Added arguments to declare list of packages."""
|
||||
|
||||
|
@ -18,9 +18,10 @@
|
||||
|
||||
from packetary.cli.commands.base import BaseRepoCommand
|
||||
from packetary.cli.commands.base import PackagesMixin
|
||||
from packetary.cli.commands.base import RepositoriesMixin
|
||||
|
||||
|
||||
class CloneCommand(PackagesMixin, BaseRepoCommand):
|
||||
class CloneCommand(PackagesMixin, RepositoriesMixin, BaseRepoCommand):
|
||||
"""Clones the specified repository to local folder."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
|
61
packetary/cli/commands/create.py
Normal file
61
packetary/cli/commands/create.py
Normal file
@ -0,0 +1,61 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
|
||||
# Copyright 2016 Mirantis, Inc.
|
||||
#
|
||||
# This program is free software; you can redistribute it and/or modify
|
||||
# it under the terms of the GNU General Public License as published by
|
||||
# the Free Software Foundation; either version 2 of the License, or
|
||||
# (at your option) any later version.
|
||||
#
|
||||
# This program is distributed in the hope that it will be useful,
|
||||
# but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
# GNU General Public License for more details.
|
||||
#
|
||||
# You should have received a copy of the GNU General Public License along
|
||||
# with this program; if not, write to the Free Software Foundation, Inc.,
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
|
||||
from packetary.cli.commands.base import BaseRepoCommand
|
||||
from packetary.cli.commands.utils import read_from_file
|
||||
|
||||
|
||||
class CreateCommand(BaseRepoCommand):
|
||||
"""Creates the new repository."""
|
||||
|
||||
def get_parser(self, prog_name):
|
||||
parser = super(CreateCommand, self).get_parser(prog_name)
|
||||
parser.add_argument(
|
||||
'--repository',
|
||||
type=read_from_file,
|
||||
metavar='FILENAME',
|
||||
required=True,
|
||||
help="The path of file that contains description of repository."
|
||||
)
|
||||
parser.add_argument(
|
||||
'--package-files',
|
||||
type=read_from_file,
|
||||
metavar='FILENAME',
|
||||
required=True,
|
||||
help="The path to file that contains list of URLs \
|
||||
of package files."
|
||||
)
|
||||
return parser
|
||||
|
||||
def take_repo_action(self, api, parsed_args):
|
||||
api.create_repository(
|
||||
parsed_args.repository,
|
||||
parsed_args.package_files
|
||||
)
|
||||
self.stdout.write("Successfully completed.")
|
||||
|
||||
|
||||
def debug(argv=None):
|
||||
"""Helper to debug the Create command."""
|
||||
from packetary.cli.app import debug
|
||||
debug("create", CreateCommand, argv)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
debug()
|
@ -18,9 +18,11 @@
|
||||
|
||||
from packetary.cli.commands.base import BaseProduceOutputCommand
|
||||
from packetary.cli.commands.base import PackagesMixin
|
||||
from packetary.cli.commands.base import RepositoriesMixin
|
||||
|
||||
|
||||
class ListOfPackages(PackagesMixin, BaseProduceOutputCommand):
|
||||
class ListOfPackages(
|
||||
PackagesMixin, RepositoriesMixin, BaseProduceOutputCommand):
|
||||
"""Gets the list of packages from repository(es)."""
|
||||
|
||||
columns = (
|
||||
|
@ -17,9 +17,10 @@
|
||||
# 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
||||
|
||||
from packetary.cli.commands.base import BaseProduceOutputCommand
|
||||
from packetary.cli.commands.base import RepositoriesMixin
|
||||
|
||||
|
||||
class ListOfUnresolved(BaseProduceOutputCommand):
|
||||
class ListOfUnresolved(RepositoriesMixin, BaseProduceOutputCommand):
|
||||
"""Gets the list of external dependencies for repository(es)."""
|
||||
|
||||
columns = (
|
||||
|
@ -26,12 +26,14 @@ subprocess.mswindows = False
|
||||
|
||||
from packetary.api import RepositoryApi
|
||||
from packetary.cli.commands import clone
|
||||
from packetary.cli.commands import create
|
||||
from packetary.cli.commands import packages
|
||||
from packetary.cli.commands import unresolved
|
||||
from packetary.objects.statistics import CopyStatistics
|
||||
from packetary.tests import base
|
||||
from packetary.tests.stubs.generator import gen_package
|
||||
from packetary.tests.stubs.generator import gen_relation
|
||||
from packetary.tests.stubs.generator import gen_repository
|
||||
|
||||
|
||||
@mock.patch("packetary.cli.commands.base.BaseRepoCommand.stdout")
|
||||
@ -56,6 +58,11 @@ class TestCliCommands(base.TestCase):
|
||||
"--skip-mandatory"
|
||||
]
|
||||
|
||||
create_argv = [
|
||||
"--repository", "repository.yaml",
|
||||
"--package-files", "package-files.yaml",
|
||||
]
|
||||
|
||||
packages_argv = [
|
||||
"-r", "repositories.yaml",
|
||||
"-t", "deb",
|
||||
@ -145,3 +152,28 @@ class TestCliCommands(base.TestCase):
|
||||
"test; any; -",
|
||||
stdout_mock.write.call_args_list[3][0][0]
|
||||
)
|
||||
|
||||
@mock.patch("packetary.cli.commands.create.read_from_file")
|
||||
def test_create_cmd(self, read_file_in_create_mock, api_mock,
|
||||
read_file_mock, stdout_mock):
|
||||
read_file_in_create_mock.side_effect = [
|
||||
[{"name": "repo"}],
|
||||
["/test1.deb", "/test2.deb", "/test3.deb"],
|
||||
]
|
||||
api_instance = mock.MagicMock(spec=RepositoryApi)
|
||||
api_mock.create.return_value = api_instance
|
||||
api_instance.create_repository.return_value = gen_repository()
|
||||
self.start_cmd(create, self.create_argv)
|
||||
api_mock.create.assert_called_once_with(
|
||||
mock.ANY, "deb", "x86_64"
|
||||
)
|
||||
self.check_common_config(api_mock.create.call_args[0][0])
|
||||
read_file_in_create_mock.assert_any_call("repository.yaml")
|
||||
read_file_in_create_mock.assert_any_call("package-files.yaml")
|
||||
api_instance.create_repository.assert_called_once_with(
|
||||
[{'name': 'repo'}],
|
||||
['/test1.deb', '/test2.deb', '/test3.deb']
|
||||
)
|
||||
stdout_mock.write.assert_called_once_with(
|
||||
"Successfully completed."
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user