Exemple #1
0
def getPathSeparator():
    if osys() in ['Linux']:
        return "/"
    elif osys() in ['Windows']:
        return "\\"
    else:
        return "\\"
Exemple #2
0
    def printProc(self,
                  process,
                  total,
                  step=1,
                  widgetType="count",
                  begin=0,
                  end=100,
                  widgetFromat="(%d/%d)"):
        if osys() not in ['Linux']:
            return process
        try:
            if widgetType in ["count"]:
                s = widgetFromat % (process, total)
            elif widgetType in ["percent"]:
                if end < begin or begin < 0 or end > 100:
                    return process

                needPercent = end - begin
                s = "(%0.2f%%)" % (
                    (float(process) / float(total)) * needPercent + begin)

            else:
                s = widgetFromat % (process, total)
            s += "\b" * len(s)
            sys.stdout.write(s)
            sys.stdout.flush()
            return process + step
        except Exception as err:
            return process
Exemple #3
0
def getColor(s, color='white', need=True):
    if osys() in ['Linux'] and need:
        color_code = color.lower() == 'red' and 91 or \
            color.lower() == 'yellow' and 93 or \
            color.lower() == 'blue' and 94 or \
            color.lower() == 'green' and 92 or \
            color.lower() == 'purple' and 95 or \
            color.lower() == 'gray' and 90 or \
            97

        return '\033[0m\033[' + str(color_code) + 'm' + s + '\033[0m'
    else:
        return s
Exemple #4
0
    def outputLogRet(self, condition, data, res, path, fileList, autoOpen = True):
        """ 输出文件到指定路径时的错误处理
            参数列表:
                condition:条件
                data:条件值
                res:成功输出文件个数
                path:文件路径
                fileList: 输出的文件列表
            返回值:分析器运行结果 结果值,错误信息 bool,str
            异常:无
        """
        if res is 0:
            s = "没有找到日志" if data.lower() in ["all"] else "不存在%s为'%s'的日志" % (condition, data)
            PRINT(s)
            return False
        else:
            s = "输出完成,%d个日志在路径:\n'%s':" % (res, path)
            PRINT(s)
            for i, f in enumerate(fileList):
                if i < 10:
                    s = " %s" % f
                    PRINT(s)
                else:
                    s = "......"
                    PRINT(s)
                    break

        if autoOpen:
            if osys() in ['Windows']:
                if res == 1:
                    # 打开那个文件
                    os.startfile(os.path.join(path, fileList[0] if fileList else ""))
                elif res > 1:
                    # 打开那个路径
                    os.startfile(path)

        return True