createrepo/utils.py
[email protected] (James Antill) Thu, 16 Feb 2012 16:26:28 +0000 (UTC)
| Newsgroups | gmane.linux.rpm.metadata |
|---|---|
| Message-ID | <[email protected]> |
createrepo/utils.py | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) New commits: commit 96571b42608e3b45ce56b93f1f1851576bed916d Author: James Antill <[email protected]> Date: Thu Feb 16 11:17:12 2012 -0500 For for split problems due to floating point math (Eg. 9 workers and 5 pkgs). diff --git a/createrepo/utils.py b/createrepo/utils.py index 84a43ba..d66b115 100644 --- a/createrepo/utils.py +++ b/createrepo/utils.py @@ -183,12 +183,17 @@ def encodefiletypelist(filetypelist): return result def split_list_into_equal_chunks(seq, num_chunks): + if num_chunks <= 1: + return [seq[:]] avg = len(seq) / float(num_chunks) out = [] last = 0.0 - while last < len(seq): + # Due to floating point math, we do one less than the number of chunks + # and then the rest. Eg. range(1,6), 9 + while len(out) < (num_chunks - 1): out.append(seq[int(last):int(last + avg)]) last += avg + out.append(seq[int(last):]) return out