python类out()的实例源码

mysql_xtrabackup.py 文件源码 项目:nc-backup-py 作者: ChinaNetCloud 项目源码 文件源码 阅读 21 收藏 0 点赞 0 评论 0
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
context.py 文件源码 项目:django-bench-runner 作者: scuml 项目源码 文件源码 阅读 27 收藏 0 点赞 0 评论 0
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
debug.py 文件源码 项目:AmqpCode 作者: SVADemoAPP 项目源码 文件源码 阅读 25 收藏 0 点赞 0 评论 0
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
debug.py 文件源码 项目:qpid-python 作者: apache 项目源码 文件源码 阅读 29 收藏 0 点赞 0 评论 0
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
ddextensionnew.py 文件源码 项目:pyomo 作者: Pyomo 项目源码 文件源码 阅读 24 收藏 0 点赞 0 评论 0
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'))
ddextensionnew.py 文件源码 项目:pyomo 作者: Pyomo 项目源码 文件源码 阅读 22 收藏 0 点赞 0 评论 0
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
ddextensionold.py 文件源码 项目:pyomo 作者: Pyomo 项目源码 文件源码 阅读 17 收藏 0 点赞 0 评论 0
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


问题


面经


文章

微信
公众号

扫码关注公众号