43 lines
1.2 KiB
Plaintext
43 lines
1.2 KiB
Plaintext
|
|
#!/usr/bin/env python
|
||
|
|
# -*- coding: UTF-8 -*-
|
||
|
|
# created by tanghao
|
||
|
|
from sys import argv
|
||
|
|
import json
|
||
|
|
import os
|
||
|
|
import shutil
|
||
|
|
|
||
|
|
|
||
|
|
def trans_list(data):
|
||
|
|
result=''
|
||
|
|
for i in range(len(data)):
|
||
|
|
if(isinstance(data[i],dict)):
|
||
|
|
result=trans_dic(data[i])
|
||
|
|
return result
|
||
|
|
|
||
|
|
def trans_dic(data):
|
||
|
|
count = len(data) - 1
|
||
|
|
result='[{'
|
||
|
|
for key in data:
|
||
|
|
if (count == 0):
|
||
|
|
if(isinstance(data[key],list)):
|
||
|
|
methodResult=trans_list(data[key])
|
||
|
|
result +='\\\"' + key + '\\\"' + ":" + methodResult
|
||
|
|
elif(isinstance(data[key],dict)):
|
||
|
|
methodResult =trans_dic(data[key])
|
||
|
|
result += '\\\"' + key + '\\\"' + ":" + methodResult
|
||
|
|
else:
|
||
|
|
result += '\\\"' + key + '\\\"' + ":\\\"" + data[key] + "\\\""
|
||
|
|
else:
|
||
|
|
result += '\\\"' + key + '\\\"' + ":\\\"" + data[key] + "\\\","
|
||
|
|
count = count - 1
|
||
|
|
result+='}]'
|
||
|
|
return result
|
||
|
|
|
||
|
|
if __name__ == '__main__':
|
||
|
|
data = json.loads(argv[1])[0]
|
||
|
|
ip=data['ip']
|
||
|
|
jsonStr=trans_dic(data)
|
||
|
|
result=os.system('ssh -o ConnectTimeout=3 '+ip+' \'device_config "'+jsonStr+'"\'')
|
||
|
|
exit(0)
|
||
|
|
|