#!/usr/bin/env python
# -*- coding: utf8 -*-

import sys
import argparse
import pprint
from deepharvest.deepharvest_nuxeo import DeepHarvestNuxeo
import s3stash.s3tools
import json

PER_PAGE = 100

def main(argv=None):

    parser = argparse.ArgumentParser(
        description='list objects for a given collection.')
    parser.add_argument('registry_id', help='UCLDC Registry ID')
    parser.add_argument(
        '--pynuxrc',
        default='~/.pynuxrc-basic',
        help="rcfile for use with pynux utils")
    if argv is None:
        argv = parser.parse_args()

    registry_id = argv.registry_id

    # get nuxeo path
    nxpath = s3stash.s3tools.get_nuxeo_path(registry_id)
    if nxpath is None:
        print "No record found for registry_id: {}".format(registry_id)
        sys.exit()

    dh = DeepHarvestNuxeo(nxpath, '', pynuxrc=argv.pynuxrc)
    print "about to fetch objects for path {}".format(dh.path)
    objects = dh.fetch_objects()
    object_count = len(objects)
    print "finished fetching objects. {} found".format(object_count)

    print "about to iterate through objects and get components"
    component_count = 0
    for obj in objects:
        components = dh.fetch_components(obj)
        component_count = component_count + len(components)
    print "finished fetching components. {} found".format(component_count)

    objects.extend(components)
    total_obj = len(objects)
    print "Grand Total: {}".format(total_obj)

    # https://stackoverflow.com/questions/312443/how-do-you-split-a-list-into-evenly-sized-chunks
    chunks = [objects[i:i + PER_PAGE] for i in xrange(0, len(objects), PER_PAGE)]

    count = 0
    for c in chunks:
        count = count + 1        
        filepath = 'chunks/{}_{}.txt'.format(registry_id, count)
        with open(filepath, 'w') as f:
            json.dump(c, f, indent=4)

    ##pp = pprint.PrettyPrinter(indent=4)
    ##pp.pprint(chunks)


if __name__ == "__main__":
    sys.exit(main())

@@ -1130,32 +1130,56 @@
 onent_count = 0%0A
+    all_components = %5B%5D%0A
     for obj in o
@@ -1231,16 +1231,17 @@
 nts(obj)
+ 
 %0A       
@@ -1233,32 +1233,36 @@
 s(obj) %0A        
+all_
 component_count 
@@ -1258,35 +1258,73 @@
 nent
-_count = component_count + 
+s.extend(components)%0A        print %22%7B%7D components for %7B%7D%22.format(
 len(
@@ -1330,24 +1330,37 @@
 (components)
+, obj%5B'uid'%5D)
 %0A    print %22
@@ -1406,16 +1406,24 @@
 .format(
+len(all_
 componen
@@ -1423,22 +1423,18 @@
 omponent
-_count
+s)
 )%0A%0A    o
@@ -1850,16 +1850,66 @@
  count)%0A
+        print %22Writing file: %7B%7D%22.format(filepath)%0A
         

Fix logic error