5252 }
5353}
5454
55+
5556def get_dist ():
5657 return platform .linux_distribution ()[0 ]
5758
@@ -111,10 +112,11 @@ def set_docker_config(mirror):
111112 f .write (new_line )
112113 f .writelines (options )
113114
115+
114116def set_docker_config_ce (mirror ):
115117 dist = get_dist ()
116118 docker_config = get_config_ce (dist )
117- config_dict = {}
119+ config_dict = {}
118120 if os .path .exists (docker_config ) != True :
119121 # if file not exist, create it first.
120122 os .mknod (docker_config , 0o644 )
@@ -127,6 +129,7 @@ def set_docker_config_ce(mirror):
127129 with open (docker_config , "w" ) as f :
128130 json .dump (config_dict , f )
129131
132+
130133def restart_docker_daemon ():
131134 execute_sys_cmd ("systemctl restart docker" )
132135
@@ -136,7 +139,7 @@ def get_speed(mirror, mirror_url):
136139 set_docker_config_ce (mirror_url )
137140 else :
138141 set_docker_config (mirror_url )
139-
142+
140143 restart_docker_daemon ()
141144
142145 # try to delete busybox image in case.
@@ -155,7 +158,7 @@ def get_speed(mirror, mirror_url):
155158 execute_sys_cmd ("docker rmi registry:2 -f 1> /dev/null 2>&1" )
156159
157160 return cost_time
158- #return 204800 / cost_time
161+
159162
160163if __name__ == "__main__" :
161164 print ("restart docker daemon" )
@@ -179,11 +182,11 @@ def get_speed(mirror, mirror_url):
179182 restart_count += 1
180183 total_time += cost_time
181184 if restart_count >= 2 and total_time < 60 :
182- # to avoid the error of docker daeom: Start request repeated too quickly
183- print ("oh.. docker daemon restart too quickly, have a rest" )
184- restart_count = 0
185- total_time = 0
186- time .sleep (60 - total_time )
185+ # to avoid the error of docker daeom: Start request repeated too quickly
186+ print ("oh.. docker daemon restart too quickly, have a rest" )
187+ restart_count = 0
188+ total_time = 0
189+ time .sleep (60 - total_time )
187190
188191 print ("best mirror is: {mirror}, set docker config and restart docker daemon now." .format (mirror = best_mirror ))
189192 if "ce" in version :
0 commit comments