From 22ec112225255700b58b63f701da53b8d8df5a00 Mon Sep 17 00:00:00 2001 From: Jimmy Berry Date: Fri, 28 Apr 2017 10:18:14 -0500 Subject: [PATCH] list & adi: share common stagingapi.ignore_format(). --- osclib/adi_command.py | 6 +++--- osclib/list_command.py | 12 +++--------- osclib/stagingapi.py | 12 ++++++++++++ 3 files changed, 18 insertions(+), 12 deletions(-) diff --git a/osclib/adi_command.py b/osclib/adi_command.py index 48deff66..c19cd732 100644 --- a/osclib/adi_command.py +++ b/osclib/adi_command.py @@ -82,8 +82,9 @@ class AdiCommand: target_package = request.find('./action/target').get('package') line = '- {} {}{:<30}{}'.format(request_id, Fore.CYAN, target_package, Fore.RESET) - if request_id in self.requests_ignored: - print(line + Fore.WHITE + '\n ignored: ' + str(self.requests_ignored[request_id]) + Fore.RESET) + message = self.api.ignore_format(request_id) + if message: + print(line + '\n' + Fore.WHITE + message + Fore.RESET) continue # Auto-superseding request in adi command @@ -110,7 +111,6 @@ class AdiCommand: """ Perform the list command """ - self.requests_ignored = self.api.get_ignored_requests() if len(packages): requests = set() if move: diff --git a/osclib/list_command.py b/osclib/list_command.py index 39b1c635..6386f64e 100644 --- a/osclib/list_command.py +++ b/osclib/list_command.py @@ -1,4 +1,3 @@ -import textwrap from colorama import Fore from osc import oscerr from osclib.request_splitter import RequestSplitter @@ -27,7 +26,6 @@ class ListCommand: requests = self.api.get_open_requests() if not len(requests): return - requests_ignored = self.api.get_ignored_requests() splitter = RequestSplitter(self.api, requests, in_ring=True) splitter.filter_add('./action[@type="change_devel"]') @@ -39,7 +37,6 @@ class ListCommand: splitter.split() is_factory = self.api.project != 'openSUSE:Factory' - ignore_indent = ' ' * (2 + len(requests[0].get('id')) + 1) for group in sorted(splitter.grouped.keys()): print Fore.YELLOW + group @@ -60,12 +57,9 @@ class ListCommand: if action.get('type') == 'delete': line += Fore.RED + ' (delete request)' - if request_id in requests_ignored: - line += '\n' + Fore.WHITE + \ - textwrap.fill(str(requests_ignored[request_id]), - initial_indent=ignore_indent, - subsequent_indent=ignore_indent, - break_long_words=False) + Fore.RESET + message = self.api.ignore_format(request_id) + if message: + line += '\n' + Fore.WHITE + message + Fore.RESET print ' ', line diff --git a/osclib/stagingapi.py b/osclib/stagingapi.py index 9c85dc20..d6e7d97d 100644 --- a/osclib/stagingapi.py +++ b/osclib/stagingapi.py @@ -18,6 +18,7 @@ from cStringIO import StringIO from datetime import datetime import json import logging +import textwrap import urllib2 import time import re @@ -1567,3 +1568,14 @@ class StagingAPI(object): ['build', project, repo, arch, package, filename], {'view': 'fileinfo_ext'}) return ET.parse(http_GET(url)).getroot() + + def ignore_format(self, request_id): + requests_ignored = self.get_ignored_requests() + if request_id in requests_ignored: + ignore_indent = ' ' * (2 + len(str(request_id)) + 1) + return textwrap.fill(str(requests_ignored[request_id]), + initial_indent=ignore_indent, + subsequent_indent=ignore_indent, + break_long_words=False) + + return None