def main():

  parser = argparse.ArgumentParser(description='Build an aeropsike DB from mysql data.')
  parser.add_argument('token', action="store", help='Token for the project.')
  parser.add_argument('resolution', action="store", type=int)
  
  result = parser.parse_args()

  # as database
  ascfg = { 'hosts': [ ('127.0.0.1', 3000) ] }
  ascli = aerospike.client(ascfg).connect()

  # mysql database
  projdb = ocpcaproj.OCPCAProjectsDB()
  proj = projdb.loadProject ( result.token )

  # Bind the annotation database
  imgDB = ocpcadb.OCPCADB ( proj )

  # Get the source database sizes
  [ximagesz, yimagesz] = proj.datasetcfg.imagesz [ result.resolution ]
  [xcubedim, ycubedim, zcubedim] = cubedim = proj.datasetcfg.cubedim [ result.resolution ]

  # Get the slices
  [ startslice, endslice ] = proj.datasetcfg.slicerange
  slices = endslice - startslice + 1

  # Set the limits for iteration on the number of cubes in each dimension
  # RBTODO These limits may be wrong for even (see channelingest.py)
  xlimit = ximagesz / xcubedim
  ylimit = yimagesz / ycubedim
  #  Round up the zlimit to the next larger
  zlimit = (((slices-1)/zcubedim+1)*zcubedim)/zcubedim 

  cursor = imgDB.conn.cursor()

  for z in range(zlimit):
    for y in range(ylimit):
      for x in range(xlimit):

        mysqlcube = imgDB.cutout ( [ x*xcubedim, y*ycubedim, z*zcubedim ], cubedim, result.resolution )
        zidx = zindex.XYZMorton ( [x,y,z] )

        tmpfile = tempfile.NamedTemporaryFile ()
        h5tocass = h5py.File ( tmpfile.name ) 
        h5tocass.create_dataset ( "cuboid", tuple(mysqlcube.data.shape), mysqlcube.data.dtype,
                                 compression='gzip',  data=mysqlcube.data )
        h5tocass.close()
        tmpfile.seek(0)

        askey = ("ocp",str(result.token)+":"+str(result.resolution),str(zidx))

        print askey
        ascli.put ( askey, { 'cuboid' : tmpfile.read().encode('hex') } )

        try:
          import pdb; pdb.set_trace()
          ascli.get ( askey )
        except:
          print "Except"
dataset/ETHPy150Open neurodata/ndstore/onetime/asingest.py/main/original