|
1 | | -# Copyright (C) 2006 Novell Inc. All rights reserved. |
2 | | -# This program is free software; it may be used, copied, modified |
3 | 1 | # and distributed under the terms of the GNU General Public Licence, |
4 | 2 | # either version 2, or version 3 (at your option). |
5 | 3 |
|
@@ -1794,13 +1792,41 @@ def show_upstream_xsrcmd5( |
1794 | 1792 | return li.xsrcmd5 |
1795 | 1793 |
|
1796 | 1794 |
|
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: |
1798 | 1796 | query = {} |
1799 | 1797 | query["view"] = "info" |
1800 | | - query["package"] = packages |
1801 | 1798 | 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) |
1804 | 1830 |
|
1805 | 1831 |
|
1806 | 1832 | def get_project_sourceinfo(apiurl: str, project: str, nofilename: bool, *packages): |
|
0 commit comments