Skip to content

Commit c990b71

Browse files
authored
Merge pull request openSUSE#1724 from dmach/show_project_sourceinfo-chunks
Change show_project_sourceinfo() to split a huge request into many and join the results to workaround GET limitations
2 parents 02edc1a + 7a31684 commit c990b71

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

osc/core.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
# Copyright (C) 2006 Novell Inc. All rights reserved.
2-
# This program is free software; it may be used, copied, modified
31
# and distributed under the terms of the GNU General Public Licence,
42
# either version 2, or version 3 (at your option).
53

@@ -1794,13 +1792,41 @@ def show_upstream_xsrcmd5(
17941792
return li.xsrcmd5
17951793

17961794

1797-
def show_project_sourceinfo(apiurl: str, project: str, nofilename: bool, *packages):
1795+
def show_project_sourceinfo(apiurl: str, project: str, nofilename: bool, *packages) -> bytes:
17981796
query = {}
17991797
query["view"] = "info"
1800-
query["package"] = packages
18011798
query["nofilename"] = nofilename
1802-
f = http_GET(makeurl(apiurl, ['source', project], query=query))
1803-
return f.read()
1799+
1800+
def to_chunks(lst, size):
1801+
import itertools
1802+
1803+
pos = 0
1804+
while True:
1805+
chunk = list(itertools.islice(lst, pos, pos + size))
1806+
if not chunk:
1807+
break
1808+
yield chunk
1809+
pos += size
1810+
1811+
# sometimes the number of packages exceeds reasonable size of a GET query
1812+
# that's why we make multiple requests and join the results
1813+
max_packages = 100
1814+
1815+
if packages:
1816+
packages_chunks = to_chunks(packages, max_packages)
1817+
else:
1818+
packages_chunks = [None]
1819+
1820+
sourceinfolist = ET.Element("sourceinfolist")
1821+
for packages_chunk in packages_chunks:
1822+
query["package"] = packages_chunk
1823+
url = makeurl(apiurl, ['source', project], query=query)
1824+
f = http_GET(url)
1825+
root = xml_parse(f).getroot()
1826+
assert root.tag == "sourceinfolist"
1827+
assert root.attrib == {}
1828+
sourceinfolist.extend(root[:])
1829+
return ET.tostring(sourceinfolist)
18041830

18051831

18061832
def get_project_sourceinfo(apiurl: str, project: str, nofilename: bool, *packages):

0 commit comments

Comments
 (0)