1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
|
# SPDX-License-Identifier: GPL-2.0+
#
# Copyright 2020 Google LLC
#
"""Handles the main control logic of patman
This module provides various functions called by the main program to implement
the features of patman.
"""
import re
import traceback
try:
from importlib import resources
except ImportError:
# for Python 3.6
import importlib_resources as resources
from u_boot_pylib import gitutil
from u_boot_pylib import terminal
from u_boot_pylib import tools
from u_boot_pylib import tout
from patman import cseries
from patman import cser_helper
from patman import patchstream
from patman.patchwork import Patchwork
from patman import send
from patman import settings
def setup():
"""Do required setup before doing anything"""
gitutil.setup()
alias_fname = gitutil.get_alias_file()
if alias_fname:
settings.ReadGitAliases(alias_fname)
def do_send(args):
"""Create, check and send patches by email
Args:
args (argparse.Namespace): Arguments to patman
"""
setup()
send.send(args)
def patchwork_status(branch, count, start, end, dest_branch, force,
show_comments, url, single_thread=False):
"""Check the status of patches in patchwork
This finds the series in patchwork using the Series-link tag, checks for new
comments and review tags, displays then and creates a new branch with the
review tags.
Args:
branch (str): Branch to create patches from (None = current)
count (int): Number of patches to produce, or -1 to produce patches for
the current branch back to the upstream commit
start (int): Start partch to use (0=first / top of branch)
end (int): End patch to use (0=last one in series, 1=one before that,
etc.)
dest_branch (str): Name of new branch to create with the updated tags
(None to not create a branch)
force (bool): With dest_branch, force overwriting an existing branch
show_comments (bool): True to display snippets from the comments
provided by reviewers
url (str): URL of patchwork server, e.g. 'https://patchwork.ozlabs.org'.
This is ignored if the series provides a Series-patchwork-url tag.
Raises:
ValueError: if the branch has no Series-link value
"""
if not branch:
branch = gitutil.get_branch()
if count == -1:
# Work out how many patches to send if we can
count = gitutil.count_commits_to_branch(branch) - start
series = patchstream.get_metadata(branch, start, count - end)
warnings = 0
for cmt in series.commits:
if cmt.warn:
print('%d warnings for %s:' % (len(cmt.warn), cmt.hash))
for warn in cmt.warn:
print('\t', warn)
warnings += 1
print
if warnings:
raise ValueError('Please fix warnings before running status')
links = series.get('links')
if not links:
raise ValueError("Branch has no Series-links value")
_, version = cser_helper.split_name_version(branch)
link = series.get_link_for_version(version, links)
if not link:
raise ValueError('Series-links has no link for v{version}')
tout.debug(f"Link '{link}")
# Allow the series to override the URL
if 'patchwork_url' in series:
url = series.patchwork_url
pwork = Patchwork(url, single_thread=single_thread)
# Import this here to avoid failing on other commands if the dependencies
# are not present
from patman import status
pwork = Patchwork(url)
status.check_and_show_status(series, link, branch, dest_branch, force,
show_comments, False, pwork)
def do_patman(args):
"""Process a patman command
Args:
args (Namespace): Arguments to process
"""
if args.full_help:
with resources.path('patman', 'README.rst') as readme:
tools.print_full_help(str(readme))
return 0
if args.cmd == 'send':
# Called from git with a patch filename as argument
# Printout a list of additional CC recipients for this patch
if args.cc_cmd:
re_line = re.compile(r'(\S*) (.*)')
with open(args.cc_cmd, 'r', encoding='utf-8') as inf:
for line in inf.readlines():
match = re_line.match(line)
if match and match.group(1) == args.patchfiles[0]:
for cca in match.group(2).split('\0'):
cca = cca.strip()
if cca:
print(cca)
else:
# If we are not processing tags, no need to warning about bad ones
if not args.process_tags:
args.ignore_bad_tags = True
do_send(args)
return 0
ret_code = 0
try:
# Check status of patches in patchwork
if args.cmd == 'status':
patchwork_status(args.branch, args.count, args.start, args.end,
args.dest_branch, args.force, args.show_comments,
args.patchwork_url)
except Exception as exc:
terminal.tprint(f'patman: {type(exc).__name__}: {exc}',
colour=terminal.Color.RED)
if args.debug:
print()
traceback.print_exc()
ret_code = 1
return ret_code
|