#NEWLINE# def migrate_pagecounters( dry_run = True ) : #NEWLINE# #INDENT# collection = db [ 'pagecounters' ] #NEWLINE# for counter in collection . find ( ) : #NEWLINE# #INDENT# _id = counter [ '_id' ] #NEWLINE# match = re . search ( 'node:(\\w{5})$' , _id ) #NEWLINE# if match : #NEWLINE# #INDENT# nid = match . groups ( ) [ 0 ] #NEWLINE# if ( nid == nid . lower ( ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# new_id = 'node:{}' . format ( nid . lower ( ) ) #NEWLINE# logging . debug ( 'Changing _id {} to {}' . format ( _id , new_id ) ) #NEWLINE# counter [ '_id' ] = new_id #NEWLINE# if ( not dry_run ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# collection . update ( { #NEWLINE# #INDENT# '_id' : new_id , #NEWLINE# #UNINDENT# } , counter , upsert = True ) #NEWLINE# #UNINDENT# except DuplicateKeyError : #NEWLINE# #INDENT# logging . debug ( 'Key exists' ) #NEWLINE# #UNINDENT# #UNINDENT# #UNINDENT# match = re . search ( 'download:(\\w{5}):(.*)' , _id ) #NEWLINE# if match : #NEWLINE# #INDENT# ( nid , etc ) = match . groups ( ) #NEWLINE# if ( nid == nid . lower ( ) ) : #NEWLINE# #INDENT# continue #NEWLINE# #UNINDENT# new_id = 'download:{}:{}' . format ( nid . lower ( ) , etc ) #NEWLINE# logging . debug ( 'Changing _id {} to {}' . format ( _id , new_id ) ) #NEWLINE# counter [ '_id' ] = new_id #NEWLINE# if ( not dry_run ) : #NEWLINE# #INDENT# try : #NEWLINE# #INDENT# collection . update ( { #NEWLINE# #INDENT# '_id' : new_id , #NEWLINE# #UNINDENT# } , counter , upsert = True ) #NEWLINE# #UNINDENT# except DuplicateKeyError : #NEWLINE# #INDENT# logging . debug ( 'Key exists' )