def main():
saveout = sys.stdout
test=xtrabackup()
sys.out=test.args_list.LOG
for MY_INSTANCE_NAME in test.args_list.MY_INSTANCES.split(','):
print "---- Processing instance: "+MY_INSTANCE_NAME+" ----"
conf_file,credential_file=test.get_instanceinfo(MY_INSTANCE_NAME)
user_args=test.get_user_args(credential_file)
args=test.get_args(conf_file,test.args_list.TMP_FOLDER)
full_stdout,full_stdrr=test.full_backup(args,user_args,test.backup_dir_full,test.date)
owner_stdout,owner_stderr=test.change_owner(test.backup_dir_full,test.date)
compress_stdout,compress_stderr=test.compress(test.PREFIX_BACKUP,test.SCRIPT_PREFIX,test.backup_dir_full,test.date)
sys.stdout=saveout
python类out()的实例源码
def capture(command, *args, **kwargs):
out, sys.stdout = sys.stdout, StringIO()
command(*args, **kwargs)
sys.stdout.seek(0)
yield sys.stdout.read()
sys.stdout = out
def acquire(self, blocking=1):
while not self.lock.acquire(blocking=0):
time.sleep(1)
print >> sys.out, "TRYING"
traceback.print_stack(None, None, out)
print >> sys.out, "TRYING"
print >> sys.out, "ACQUIRED"
traceback.print_stack(None, None, out)
print >> sys.out, "ACQUIRED"
return True
def acquire(self, blocking=1):
while not self.lock.acquire(blocking=0):
time.sleep(1)
print >> sys.out, "TRYING"
traceback.print_stack(None, None, out)
print >> sys.out, "TRYING"
print >> sys.out, "ACQUIRED"
traceback.print_stack(None, None, out)
print >> sys.out, "ACQUIRED"
return True
def post_ph_execution(self, ph):
self.write_start_in(ph)
# Write this file again now that we have weights
# and variable starts
self.write_input2sip(ph)
#sipout = 'sipout_good'
#os.system('rm -rf '+sipout)
#os.system(_ddsip_exe+' < 2sip')
#assert os.path.exists(sipout) and os.path.isdir(sipout)
#assert os.path.exists(os.path.join(sipout,'solution.out'))
#self._load_ddsip_solution(ph, os.path.join(sipout,'solution.out'))
def sort_write_lp(self, ph, ObjObject, ConstraintMap, StageToConstraintMap, remaining_lpfile_rows):
try:
#print("\nWrite the LP file for dd in sorted_LPfile.lp\n")
lp = open("sorted_LPfile.lp", "wt")
except IOError:
print("IO Error so that sorted_LPfile.lp cannot be created.")
sys.out(1)
# keep track of input file names
self.input_file_name_list.append('sorted_LPfile.lp')
# for the matrix.sc file we need to know which constraint is
# in which row:
MatrixEntries_ConstrToRow_Map = {}
lp.write(ObjObject[0]+"\n "+ObjObject[1]+":\n")
self.print_coeff_var_from_map(ObjObject[2], lp)
# assume blank line before and after constraint indicator
lp.write("\ns.t.\n")
FirstStage = StageToConstraintMap['FirstStage']
ConstrNames = set(ConstraintMap.keys())
FirstStageConstrOrder = sorted(ConstrNames.intersection(FirstStage))
SecondStageConstrOrder = sorted(ConstrNames - set(FirstStage))
# so that we know in which rows the constraints with
# stochastic data are (first row has index 0)
count_rows = -1
self._num_first_stage_constraints = 0
self._num_second_stage_constraints = 0
for name in FirstStageConstrOrder:
lp.write("\n"+name+":\n")
count_rows += 1
MatrixEntries_ConstrToRow_Map[name] = count_rows
lp_con = ConstraintMap[name]
self.print_coeff_var_from_map(lp_con[0], lp)
lp.write(lp_con[1]+" "+lp_con[2]+"\n")
self._num_first_stage_constraints += 1
for name in SecondStageConstrOrder:
lp.write("\n"+name+":\n")
count_rows += 1
MatrixEntries_ConstrToRow_Map[name] = count_rows
lp_con = ConstraintMap[name]
self.print_coeff_var_from_map(lp_con[0], lp)
lp.write(lp_con[1]+" "+lp_con[2]+"\n")
self._num_second_stage_constraints += 1
# print the remaining rows of the lp file
for row in range(len(remaining_lpfile_rows)):
lp.write("\n")
for i in range(len(remaining_lpfile_rows[row])):
lp.write(remaining_lpfile_rows[row][i]+" ")
lp.close()
return MatrixEntries_ConstrToRow_Map, SecondStageConstrOrder, self._num_first_stage_constraints, self._num_second_stage_constraints
def sort_write_lp(self, ph, ObjObject, ConstraintMap, StageToConstraintMap, remaining_lpfile_rows):
try:
print("\nWrite the LP file for dd in sorted_LPfile.lp\n")
lp = open("sorted_LPfile.lp", "w")
except IOError:
print("IO Error so that sorted_LPfile.lp cannot be created.")
sys.out(1)
# keep track of input file names
self.input_file_name_list.append('sorted_LPfile.lp')
# for the matrix.sc file we need to know which constraint is
# in which row:
MatrixEntries_ConstrToRow_Map = {}
lp.write(ObjObject[0]+"\n "+ObjObject[1]+":\n")
self.print_coeff_var_from_map(ObjObject[2], lp)
# assume blank line before and after constraint indicator
lp.write("\ns.t.\n")
FirstStage = StageToConstraintMap['FirstStage']
ConstrNames = list(ConstraintMap.keys())
ConstrNames.sort()
RememberSecStageConstr = []
# so that we know in which rows the constraints with
# stochastic data are (first row has index 0)
count_rows = -1
for name in ConstrNames:
# check if constraint is in first stage
if name in FirstStage:
lp.write("\n"+name+":\n")
count_rows += 1
MatrixEntries_ConstrToRow_Map[name] = count_rows
self.print_coeff_var_from_map(ConstraintMap[name][0], lp)
lp.write(ConstraintMap[name][1]+" "+ConstraintMap[name][2]+"\n")
else:
RememberSecStageConstr.append(name)
MatrixEntries_ConstrToRow_Map = \
self._sort_print_second_stage_constr(ph,
RememberSecStageConstr,
lp,
ConstraintMap,
count_rows,
MatrixEntries_ConstrToRow_Map)
# print the remaining rows of the lp file
for row in range(len(remaining_lpfile_rows)):
lp.write("\n")
for i in range(len(remaining_lpfile_rows[row])):
lp.write(remaining_lpfile_rows[row][i]+" ")
lp.close()
#print MatrixEntries_ConstrToRow_Map
return MatrixEntries_ConstrToRow_Map