From 4aa0dfec172c45478992cc68dee4fbd79a195d8c Mon Sep 17 00:00:00 2001 From: Zhixiong Chi Date: Fri, 24 Sep 2021 19:17:20 +0800 Subject: [PATCH] stx tool: repomgr: Add the support of repomgr module Implement the stx repomgr module so that the developer could manage the repo on the host with the 'stx repomgr xxx' command. Now support the action: [ list|download|sync|mirror|clean|remove_repo|upload_pkgs ] Please refer to the more help information with the command 'stx repomgr --help' Story: 2008862 Task: 43121 Signed-off-by: Zhixiong Chi Change-Id: I27b649cfe941fa2275cee63a753ff08b239fcc4e --- stx/lib/stx/stx_main.py | 11 ++++++++++ stx/lib/stx/stx_repomgr.py | 44 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) create mode 100644 stx/lib/stx/stx_repomgr.py diff --git a/stx/lib/stx/stx_main.py b/stx/lib/stx/stx_main.py index d02d6191..1a108610 100644 --- a/stx/lib/stx/stx_main.py +++ b/stx/lib/stx/stx_main.py @@ -18,6 +18,7 @@ import logging from stx import command # pylint: disable=E0611 from stx import stx_configparser # pylint: disable=E0611 from stx import stx_control # pylint: disable=E0611 +from stx import stx_repomgr # pylint: disable=E0611 from stx import utils # pylint: disable=E0611 logger = logging.getLogger('STX') @@ -88,6 +89,16 @@ settings.\t\teg: [ --show|--get|--add|--unset|--remove-section ]') required=False) config_subparser.set_defaults(handle=self.handleconfig.handleConfig) + repo_subparser = subparsers.add_parser('repomgr', + help='Manage source|binary \ +packages.\t\teg: [ list|download|sync|mirror|clean|remove_repo|upload_pkg|\ +delete_pkg ]') + repo_subparser.add_argument('repomgr_task', + help='[ list|download|sync|mirror|clean|\ + remove_repo|upload_pkg|delete_pkg ]: \ + Execute the management task.\n\n') + repo_subparser.set_defaults(handle=stx_repomgr.handleRepomgr) + parser.add_argument('-d', '--debug', help='Enable debug output\n\n', action='store_const', const=logging.DEBUG, diff --git a/stx/lib/stx/stx_repomgr.py b/stx/lib/stx/stx_repomgr.py new file mode 100644 index 00000000..15f32b72 --- /dev/null +++ b/stx/lib/stx/stx_repomgr.py @@ -0,0 +1,44 @@ +# Copyright (c) 2021 Wind River Systems, Inc. +# +# 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. + +import logging +from stx import command # pylint: disable=E0611 +from stx import utils # pylint: disable=E0611 +import subprocess + + +logger = logging.getLogger('STX-Repomgr') +utils.set_logger(logger) + + +def handleRepomgr(args): + '''Sync the repo ''' + + logger.setLevel(args.loglevel) + logger.debug('Execute the repomgr command: [%s]', args.repomgr_task) + + podname = command.get_pod_name('builder') + if not podname: + logger.error('The builder container does not exist, so please \ + consider to use the control module') + + prefix_cmd = command.generatePrefixCommand(podname, '', 1) + cmd = prefix_cmd + '"repo_manage.py ' + args.repomgr_task + '"\'' + logger.debug('Manage the repo with the command [%s]', cmd) + + try: + subprocess.check_call(cmd, shell=True) + except subprocess.CalledProcessError as exc: + raise Exception('Failed to manage the repo with the command [%s].\n \ +Returncode: %s' % (cmd, exc.returncode))