#NEWLINE# @ task #NEWLINE# def migrate( migration , sources = None , kwargs_string = None , dry = True , async = False , group_size = 1000 ) : #NEWLINE# #INDENT# " Task to run a migration.\n\n    :param migration: The migration function to run. This is passed in\n    as a string then interpreted as a function by the invoke task.\n    :type migration: str\n\n    :param kwargs_string: parsed into an optional set of keyword\n    arguments, so that the invoke migrate task can accept a variable\n    number of arguments for each migration.\n    The kwargs_string should be in the following format:\n        'key:value, key2:value2'\n    ...with the keys and values seperated by colons, and each kwarg seperated\n    by commas.\n    :type kwarg_string: str\n\n    An example of usage renaming mit to mit 2 as a real run would be:\n        inv migrate rename -s mit -k 'target:mit2' --no-dry\n    An example of calling renormalize on two sources as an async dry run:\n        inv migrate renormalize -s 'mit,asu' -a\n    " #NEWLINE# kwargs_string = ( kwargs_string or ':' ) #NEWLINE# sources = ( sources or '' ) #NEWLINE# from scrapi import migrations #NEWLINE# from scrapi.tasks import migrate #NEWLINE# kwargs = { #NEWLINE# #INDENT# #NEWLINE# #UNINDENT# } #NEWLINE# for ( key , val ) in map ( ( lambda x : x . split ( ':' ) ) , kwargs_string . split ( ',' ) ) : #NEWLINE# #INDENT# ( key , val ) = ( key . strip ( ) , val . strip ( ) ) #NEWLINE# if ( key not in kwargs . keys ( ) ) : #NEWLINE# #INDENT# kwargs [ key ] = val #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# if isinstance ( kwargs [ key ] , list ) : #NEWLINE# #INDENT# kwargs [ key ] . append ( dry ) #NEWLINE# #UNINDENT# else : #NEWLINE# #INDENT# kwargs [ key ] = [ kwargs [ key ] , val ] #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# kwargs [ 'dry' ] = dry #NEWLINE# kwargs [ 'async' ] = async #NEWLINE# kwargs [ 'group_size' ] = group_size #NEWLINE# kwargs [ 'sources' ] = list ( map ( ( lambda x : x . strip ( ) ) , sources . split ( ',' ) ) ) #NEWLINE# if ( kwargs [ 'sources' ] == [ '' ] ) : #NEWLINE# #INDENT# kwargs . pop ( 'sources' ) #NEWLINE# #UNINDENT# migrate_func = migrations . __dict__ [ migration ] #NEWLINE# migrate ( migrate_func , ** kwargs )