#!/usr/bin/env python
# encoding: utf-8

'''
File: MongoSplitter.py
Author: NYU ITP Team
Description: Will calculate splits for a given collection/database
and store/return them in MongoSplit objects
'''


def calculate_splits(config):
    """reads config to find out what type of split to perform"""
    pass

def calculate_unsharded_splits(config, etc):
    """@todo: Docstring for calculate_unsharded_splits

    :returns: @todo
    """
    pass

def _split(config, etc):
    """@todo: Docstring for _split

    :returns: an actual MongoSplit object
    """
    pass

def calculate_single_split(config):
    pass

def calculate_sharded_splits(config, etc):
    """Worry about this after unsharded splits are doen

    :returns: @todo
    """
    pass

def fetch_splits_from_shards(config):
    """@todo: Docstring for fetch_splits_from_shards

    :returns: @todo
    """
    pass



def fetch_splits_via_chunks(config):
    """@todo: Docstring for fetch_splits_via_chunks

    :returns: @todo
    """
    pass

def get_new_URI(original_URI, etc):
    """@todo: Docstring for get_new_URI

    :original_URI: @todo
    :etc: @todo
    :returns: a new Mongo_URI
    """

    pass




@@ -197,17 +197,74 @@
 cts%0A'''%0A
+from pymongo import Connection, uri_parser%0Aimport logging
 %0A
-
 %0Adef cal
@@ -347,37 +347,1704 @@
  perform%22%22%22%0A    
+#
 pass%0A
+%09uri = %22mongodb://localhost/test.in%22 #config.getInputURI()%0A%09uri_info = uri_parser.parse_uri(uri)%0A%09%0A%09host = uri_info%5B'nodelist'%5D%5B0%5D%5B0%5D%0A%09port = uri_info%5B'nodelist'%5D%5B0%5D%5B1%5D%0A%09database_name = uri_info%5B'database'%5D%0A%09collection_name = uri_info%5B'collection'%5D%0A%09%0A%09connection = Connection(uri)%0A%09db = connection%5BdatabaseName%5D%0A%09stats = db.command(%22collstats%22, collection_name)%0A%09%0A%09isSharded = False if %22sharded%22 not in stats else stats%5B%22sharded%22%5D%0A%09useShards = False #config.canReadSplitsFromShards()%0A%09useChunks = False #config.isShardChunkedSplittingEnabled()%0A%09laveOk = True #config.canReadSplitsFromSecondary()%0A%09%0A%09logging.info(%22 Calculate Splits Code ... Use Shards? %22 + useShards + %22, Use Chunks? %22 + useChunks + %22; Collection Sharded? %22 + isSharded);%0A%09%0A%09if config.createInputSplits():%0A%09%09logging.info( %22Creation of Input Splits is enabled.%22 )%0A%09%09if isSharded and (useShards or useChunks):%0A%09%09%09if useShards and useChunks:%0A%09%09%09%09logging.warn( %22Combining 'use chunks' and 'read from shards directly' can have unexpected & erratic behavior in a live system due to chunk migrations. %22 );%0A%09%09%09%0A%09%09%09logging.info( %22Sharding mode calculation entering.%22 );%0A%09%09%09return calculate_sharded_splits( config, useShards, useChunks, slaveOk, uri, mongo );%0A%09%09%09%0A%09%09%09else: # perfectly ok for sharded setups to run with a normally calculated split. May even be more efficient for some cases%0A%09%09%09%09logging.info( %22Using Unsharded Split mode (Calculating multiple splits though)%22 );%0A%09%09%09%09return calculate_unsharded_splits( config, slaveOk, uri, coll );%0A%09           %0A%09else:%0A%09%09logging.info( %22Creation of Input Splits is disabled; Non-Split mode calculation entering.%22 );%0A%09%09return calculate_single_split( config );%0A%09%09%0A%09%09
 %0Adef calculate_u

add skelton code for splitter