Skip to content

Commit

Permalink
Add versioned option
Browse files Browse the repository at this point in the history
Signed-off-by: Yohanna Lisnichuk <yohanitalisnichuk@gmail.com>
  • Loading branch information
yolile committed Aug 3, 2018
1 parent c7aa013 commit e117419
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
9 changes: 9 additions & 0 deletions README.rst
Expand Up @@ -78,6 +78,15 @@ Reads release packages from standard input, merges the releases by OCID, and pri

cat tests/fixtures/realdata/release-package-1.json | ocdskit compile > out.json

versioned
~~~~~~~

Reads release packages from standard input, merges the releases by OCID, and prints the versioned releases.

::

cat tests/fixtures/realdata/release-package-1.json | ocdskit versioned > out.json

tabulate
~~~~~~~~

Expand Down
1 change: 1 addition & 0 deletions ocdskit/cli/__main__.py
Expand Up @@ -12,6 +12,7 @@
'ocdskit.cli.commands.combine_record_packages',
'ocdskit.cli.commands.combine_release_packages',
'ocdskit.cli.commands.compile',
'ocdskit.cli.commands.versioned',
'ocdskit.cli.commands.indent',
'ocdskit.cli.commands.mapping_sheet',
'ocdskit.cli.commands.measure',
Expand Down
23 changes: 23 additions & 0 deletions ocdskit/cli/commands/versioned.py
@@ -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)

0 comments on commit e117419

Please sign in to comment.