github
.
gcloud compute ssh
在下面
def upload_file(self, projectname):
var = raw_input("Upload file with name: " + projectname + " will remove all file and directory with same name in the instance. Are you sure? (y/n)")
if var.lower().strip() != "y":
print "Abort uploading."
return
is_zip = False
if projectname.split('.')[1] == "zip":
is_zip = True
fullpath_projectname = __location__ + "/" + projectname
if os.path.isfile(fullpath_projectname):
all_instances = self.search_any('instances', filter="labels.type=" + self.working_group_label)
all_instances_name = [x['name'] for x in all_instances]
i = 0
for instance in all_instances_name:
temp_command = 'gcloud_command_' + str(i)
i += 1
temp_instance = user_name + "@" + instance
temp_file_path = '/home/' + user_name + '/'
command_arr = []
command_arr.append('call gcloud compute ssh ' + temp_instance + ' --zone ' + zone + ' --command "cd ' + temp_file_path + '; sudo rm -rf ' + temp_file_path + projectname.split('.')[0] + '; sudo rm -f ' + temp_file_path + projectname.split('.')[0] + '*"\n')
command_arr.append('call gcloud compute scp "' + fullpath_projectname + '" ' + temp_instance + ':' + temp_file_path + '\n')
if is_zip:
command_arr.append('call gcloud compute ssh ' + temp_instance + ' --zone ' + zone + ' ' + ' --command "cd ' + temp_file_path + '; sudo unzip ' + temp_file_path + projectname + '"' + '\n')
with open(os.path.join(__location__, 'bat/' + temp_command + '.bat'), 'w') as bat:
bat.writelines(command_arr)
subprocess.Popen(os.path.join(__location__, 'bat/' + temp_command + '.bat'), shell=True)
这样地,
我可以手动一个一个地缓存,但对其他人不方便。
我试图通过改变最后一行来回答缓存问题
proc = subprocess.Popen(os.path.join(__location__, 'bat/' + temp_command + '.bat'), shell=True)
proc.communicate(input='y')
这使得所有的上传只是一个接一个