Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Signed-off-by: Yohanna Lisnichuk <yohanitalisnichuk@gmail.com>
- Loading branch information
Showing
3 changed files
with
33 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import json | ||
from collections import defaultdict, OrderedDict | ||
|
||
import ocdsmerge | ||
|
||
from .base import BaseCommand | ||
|
||
|
||
class Command(BaseCommand): | ||
name = 'versioned' | ||
help = 'reads release packages from standard input, merges the releases by OCID, and prints the versioned releases' | ||
|
||
def handle(self): | ||
releases_by_ocid = defaultdict(list) | ||
|
||
for line in self.buffer(): | ||
release_package = json.loads(line, object_pairs_hook=OrderedDict) | ||
for release in release_package['releases']: | ||
releases_by_ocid[release['ocid']].append(release) | ||
|
||
for releases in releases_by_ocid.values(): | ||
compiled_release = ocdsmerge.merge_versioned(releases) | ||
self.print(compiled_release) |