Created
December 14, 2015 10:52
-
-
Save mapio/0069e9980aa3656e993a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from json import loads, dumps | |
from base64 import b64decode, b64encode | |
def relocate( conf_data, old_path, new_path ): | |
def rdt( dct ): | |
for k, v in dct.items(): | |
if isinstance( v, dict ): | |
rdt( v ) | |
else: | |
if 'Path' in k: | |
dct[ k ] = v.replace( old_path, new_path ) | |
conf = loads( conf_data ) | |
raw_driver = loads( b64decode( conf[ 'RawDriver' ] ) ) | |
rdt( conf ) | |
rdt( raw_driver ) | |
conf[ 'RawDriver' ] = b64encode( dumps( raw_driver ) ) | |
return dumps( conf, sort_keys = True, indent = 4, separators = ( ',', ': ' ) ) | |
if __name__ == '__main__': | |
from sys import argv | |
_, old_conf, new_conf, old_path, new_path = argv | |
with open( old_conf, 'r' ) as inf: | |
conf_data = inf.read() | |
relocated = relocate( conf_data, old_path, new_path ) | |
with open( new_conf, 'w' ) as outf: | |
outf.write( relocated ) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
FYI, in latest Machine versions we've removed the use of
RawDriver
, so editing the JSON directly should work. Let us know if you encounter any issues, thanks.