def __init__(self,
                 allow_suffixs=('exe', ),
                 dir_black_list=('C:\\WINDOWS*', ),
                 async_index=True):
        if self.__is_init: return

        self._allow_suffixs = [
            '.' + i if i[0] != '.' else i for i in allow_suffixs
        ]
        self._dir_black_list = dir_black_list

        self._paths = os.environ['Path'].split(';')
        self._all_files = []
        self._all_dirs = []

        self._match_dict = {}  #带后缀的与绝对路径匹配的字典
        self._bname_dict = {}  #不带后缀的与带后缀的匹配的字典(仅文件名)

        self._scan_path()

        self._indexing_down = False  #标志索引是否结束,未结束的时候会使用慢速匹配
        inject_get_set(self)

        if async_index:
            T = threading.Thread(target=self._gen_match_dict)
            T.start()
        else:
            self._gen_match_dict()

        self.__is_init = True
Beispiel #2
0
    def __init__(self, cmdline, cwd, sp=' ', input_codec='utf-8'):
        '''传入命令和分隔符'''
        self.platform = 'win32'
        self._input_codec = input_codec
        self._cmdline = [i.strip() for i in cmdline.split(sp)]
        self._cwd = cwd
        while '' in self._cmdline:
            self._cmdline.remove('')
        try:
            self._subp = subprocess.Popen(self._cmdline,
                                          bufsize=0,
                                          stdout=subprocess.PIPE,
                                          stdin=subprocess.PIPE,
                                          stderr=subprocess.PIPE,
                                          cwd=self._cwd)
        except Exception as ex:
            raise Exception('create process error -> ' + str(ex))

        self._rtcode = None

        self._cache_result = Queue()
        self._cache_error = Queue()
        self._raw_result = bytearray()
        self._raw_error = bytearray()
        self._last_get_result_index = 0
        self._last_get_error_index = 0
        self._results = []
        self._errors = []
        self._input_queue = Queue()
        self._end = False
        self._busy = True
        inject_get_set(self, var=('_busy'))
        self._start_loop()
Beispiel #3
0
    def __init__(self):
        if self.__is_init: return
        self._ncard = {}  #n:[up,down]

        self._up_speed = 0
        self._down_speed = 0

        n, s = self._find_ncard()
        self._default_card = n[0]
        self._ncard = self._ncard.fromkeys(n)
        for n in self._ncard.keys():
            self._ncard[n] = [0, 0, s[n][0], s[n][1]]

        self._end = False

        inject_get_set(self)

        self._loop = threading.Thread(target=self._monitor_loop)
        self._loop.start()
        self.__is_init = True
    def __init__(self,
                 allow_suffixs=('*', ),
                 dir_black_list=tuple(),
                 async_scan=True,
                 async_index=True):
        if self.__is_init: return

        self._allow_suffixs = [
            '.' + i if i[0] != '.' else i for i in allow_suffixs
        ]
        #self._allow_suffixs=allow_suffixs
        self._dir_black_list = dir_black_list

        #self._env_path=[]

        self._all_files = []
        self._all_dirs = []

        self._match_dict = {}  #带后缀的与绝对路径匹配的字典
        self._bname_dict = {}  #不带后缀的与带后缀的匹配的字典(仅文件名)
        self._lbname_dict = {}  #不区分大小写与不带后缀的匹配字典

        self._scan_down = False  #标志扫描文件夹是否结束
        self._indexing_down = False  #标志索引是否结束,未结束的时候会使用慢速匹配
        self._indexed_name = set()  #已索引结束的name

        inject_get_set(self)
        if async_scan:
            S = threading.Thread(target=self._scan_path)
            S.start()
        else:
            self._scan_path()
        if async_index:
            G = threading.Thread(target=self._gen_match_dict)
            G.start()
        else:
            self._gen_match_dict()

        self.__is_init = True
Beispiel #5
0
    def __init__(self, ip):
        self._ip = ip

        self._thread_state = 'end'
        self._thread_info = []

        self._last_update_time = 0  #上次延时的更新时刻
        self._last_delay = 0  #上次更新的延时(ms)
        self._history_record = []  #历史记录(时刻:延时)

        self._ping_process = None  #subprocess.Popen ping子进程
        self._m_thread = None

        fd = inject_get_set(self)  #注入线程安全的属性访问方法
        if fd == False:
            raise Exception('inject method fail')
Beispiel #6
0
    def __init__(self,
                 speed=15,
                 info_speed=1,
                 bar_len='Auto',
                 info_len='Auto',
                 bar_fill='#',
                 bar_moving='<=-=>',
                 move_mode='lr',
                 show_percent_num=False,
                 smooth=True,
                 allow_skip_frame=True,
                 vsync=True,
                 auto_off=True):
        '''smooth即平滑模式,设定一个进度向另一个进度切换时是否平滑,allow_skip_frame标志是否允许跳过平滑帧'''
        self._fps = speed
        self._info_fps = info_speed  #info的fps
        self._bar_len = bar_len
        self._info_len = info_len
        self._bar_fill = bar_fill
        self._bar_moving = bar_moving
        self._move_mode = move_mode
        self._show_percent_num = show_percent_num

        self._smooth = smooth
        self._allow_skip_frame = allow_skip_frame
        self._vsync = vsync

        self._terminal_size = os.get_terminal_size()

        self._auto_off = auto_off

        self._log = []

        if not self._check_init_arg():
            self.show_log()
            raise Exception('[!]error:初始化参数非法')

        self._events = Queue(
        )  #事件(tuple类型,第一个是'c','r'(rate),'i'(info),'a'(all(info&rate)),对应控制,渲染请求,r的参数可控(进度条值(0-100),info内容))
        self._user_render_events = Queue()  #表示用户设定的帧,不可跳过

        self._bar_position = -len(self._bar_moving)
        self._info_position = 0
        self._bar_next_direction = 0  #表示下一帧移动方向(0不动,1向右,-1向左)
        self._info_next_direction = 0
        self._init_direction()

        self._now_move_info_interval = 0  # 当它等于int(self._fps/self._info_fps)时应该移动info#2fps(多少frame移动一次)

        self._bar_template = None  #进度条模板
        self._set_show_template()

        self._now_fill_num = 0  #进度条值(0-self._bar_len)
        self._now_str_info = ''  #显示的信息
        self._tmp_frame = ''  #缓存帧
        self._now_rate = 0  #当前百分比

        self._last_event_time = 0  #上次处理event用时
        self._last_render_cache_time = 0  #上次计算(刷新到缓存)用时
        self._last_to_screen_time = 0  #上次输出到屏幕用时
        self._frame_sleep = 1 / self._fps  #每帧间隔

        self._event_thread = threading.Thread(target=self._event_loop)
        self._is_start = False

        self._hidden = False  #是否隐藏进度条的显示(print以及控制操作依然可用)
        self._pause = False  #是否暂停事件循环

        fd = inject_get_set(self)  #注入线程安全的属性访问方法
        if fd == False:
            raise Exception('inject method fail')
        value_snapshot(self)