コード例 #1
0
ファイル: config.py プロジェクト: wezhang/vim-setup
	def set_watcher(self, watcher_type, force=False):
		if watcher_type == self.watcher_type:
			return
		watcher = create_file_watcher(self.pl, watcher_type)
		with self.lock:
			if self.watcher_type == 'deferred':
				self.watcher.transfer_calls(watcher)
			self.watcher = watcher
			self.watcher_type = watcher_type
コード例 #2
0
ファイル: config.py プロジェクト: KinzataDev/dotfiles
	def __init__(self, shutdown_event=None, watcher=None, load=load_json_config):
		super(ConfigLoader, self).__init__()
		self.shutdown_event = shutdown_event or Event()
		self.watcher = watcher or create_file_watcher()
		self._load = load

		self.pl = None
		self.interval = None

		self.lock = Lock()

		self.watched = defaultdict(set)
		self.missing = defaultdict(set)
		self.loaded = {}
コード例 #3
0
	def __init__(self, shutdown_event=None, watcher=None, load=load_json_config):
		super(ConfigLoader, self).__init__()
		self.shutdown_event = shutdown_event or Event()
		self.watcher = watcher or create_file_watcher()
		self._load = load

		self.pl = None
		self.interval = None

		self.lock = Lock()

		self.watched = defaultdict(set)
		self.missing = defaultdict(set)
		self.loaded = {}
コード例 #4
0
 def test_file_watcher(self):
     from powerline.lib.file_watcher import create_file_watcher
     w = create_file_watcher(use_stat=False)
     if w.is_stat_based:
         raise SkipTest(
             'This test is not suitable for a stat based file watcher')
     f1, f2, f3 = map(lambda x: os.path.join(INOTIFY_DIR, 'file%d' % x),
                      (1, 2, 3))
     with open(f1, 'wb'):
         with open(f2, 'wb'):
             with open(f3, 'wb'):
                 pass
     ne = os.path.join(INOTIFY_DIR, 'notexists')
     self.assertRaises(OSError, w, ne)
     self.assertTrue(w(f1))
     self.assertTrue(w(f2))
     os.utime(f1, None), os.utime(f2, None)
     self.do_test_for_change(w, f1)
     self.do_test_for_change(w, f2)
     # Repeat once
     os.utime(f1, None), os.utime(f2, None)
     self.do_test_for_change(w, f1)
     self.do_test_for_change(w, f2)
     # Check that no false changes are reported
     self.assertFalse(w(f1), 'Spurious change detected')
     self.assertFalse(w(f2), 'Spurious change detected')
     # Check that open the file with 'w' triggers a change
     with open(f1, 'wb'):
         with open(f2, 'wb'):
             pass
     self.do_test_for_change(w, f1)
     self.do_test_for_change(w, f2)
     # Check that writing to a file with 'a' triggers a change
     with open(f1, 'ab') as f:
         f.write(b'1')
     self.do_test_for_change(w, f1)
     # Check that deleting a file registers as a change
     os.unlink(f1)
     self.do_test_for_change(w, f1)
     # Test that changing the inode of a file does not cause it to stop
     # being watched
     os.rename(f3, f2)
     self.do_test_for_change(w, f2)
     self.assertFalse(w(f2), 'Spurious change detected')
     os.utime(f2, None)
     self.do_test_for_change(w, f2)
コード例 #5
0
ファイル: test_lib.py プロジェクト: IanVaughan/dotfiles
	def test_file_watcher(self):
		from powerline.lib.file_watcher import create_file_watcher
		w = create_file_watcher(use_stat=False)
		if w.is_stat_based:
			raise SkipTest('This test is not suitable for a stat based file watcher')
		f1, f2, f3 = map(lambda x: os.path.join(INOTIFY_DIR, 'file%d' % x), (1, 2, 3))
		with open(f1, 'wb'):
			with open(f2, 'wb'):
				with open(f3, 'wb'):
					pass
		ne = os.path.join(INOTIFY_DIR, 'notexists')
		self.assertRaises(OSError, w, ne)
		self.assertTrue(w(f1))
		self.assertTrue(w(f2))
		os.utime(f1, None), os.utime(f2, None)
		self.do_test_for_change(w, f1)
		self.do_test_for_change(w, f2)
		# Repeat once
		os.utime(f1, None), os.utime(f2, None)
		self.do_test_for_change(w, f1)
		self.do_test_for_change(w, f2)
		# Check that no false changes are reported
		self.assertFalse(w(f1), 'Spurious change detected')
		self.assertFalse(w(f2), 'Spurious change detected')
		# Check that open the file with 'w' triggers a change
		with open(f1, 'wb'):
			with open(f2, 'wb'):
				pass
		self.do_test_for_change(w, f1)
		self.do_test_for_change(w, f2)
		# Check that writing to a file with 'a' triggers a change
		with open(f1, 'ab') as f:
			f.write(b'1')
		self.do_test_for_change(w, f1)
		# Check that deleting a file registers as a change
		os.unlink(f1)
		self.do_test_for_change(w, f1)
		# Test that changing the inode of a file does not cause it to stop
		# being watched
		os.rename(f3, f2)
		self.do_test_for_change(w, f2)
		self.assertFalse(w(f2), 'Spurious change detected')
		os.utime(f2, None)
		self.do_test_for_change(w, f2)
コード例 #6
0
ファイル: test_lib.py プロジェクト: freeder/punto
    def test_file_watcher(self):
        from powerline.lib.file_watcher import create_file_watcher

        w = create_file_watcher(use_stat=False)
        if w.is_stat_based:
            raise SkipTest("This test is not suitable for a stat based file watcher")
        f1, f2 = os.path.join(INOTIFY_DIR, "file1"), os.path.join(INOTIFY_DIR, "file2")
        with open(f1, "wb"):
            with open(f2, "wb"):
                pass
        ne = os.path.join(INOTIFY_DIR, "notexists")
        self.assertRaises(OSError, w, ne)
        self.assertTrue(w(f1))
        self.assertTrue(w(f2))
        os.utime(f1, None), os.utime(f2, None)
        self.do_test_for_change(w, f1)
        self.do_test_for_change(w, f2)
        # Repeat once
        os.utime(f1, None), os.utime(f2, None)
        self.do_test_for_change(w, f1)
        self.do_test_for_change(w, f2)
        # Check that no false changes are reported
        self.assertFalse(w(f1), "Spurious change detected")
        self.assertFalse(w(f2), "Spurious change detected")
        # Check that open the file with 'w' triggers a change
        with open(f1, "wb"):
            with open(f2, "wb"):
                pass
        self.do_test_for_change(w, f1)
        self.do_test_for_change(w, f2)
        # Check that writing to a file with 'a' triggers a change
        with open(f1, "ab") as f:
            f.write(b"1")
        self.do_test_for_change(w, f1)
        # Check that deleting a file registers as a change
        os.unlink(f1)
        self.do_test_for_change(w, f1)
コード例 #7
0
ファイル: __init__.py プロジェクト: zundr/powerline
def file_watcher():
    global _file_watcher
    if _file_watcher is None:
        from powerline.lib.file_watcher import create_file_watcher
        _file_watcher = create_file_watcher()
    return _file_watcher
コード例 #8
0
ファイル: __init__.py プロジェクト: zhaocai/powerline
def file_watcher():
	global _file_watcher
	if _file_watcher is None:
		from powerline.lib.file_watcher import create_file_watcher
		_file_watcher = create_file_watcher()
	return _file_watcher
コード例 #9
0
ファイル: __init__.py プロジェクト: BenTobias/vim-bash-files
	def __init__(self):
		global watcher
		self.subscribers.add(self)
		if not watcher:
			watcher = create_file_watcher()
コード例 #10
0
ファイル: __init__.py プロジェクト: Aitem/VIM
def branch_watcher():
	global _branch_watcher
	if _branch_watcher is None:
		from powerline.lib.file_watcher import create_file_watcher
		_branch_watcher = create_file_watcher()
	return _branch_watcher
コード例 #11
0
def branch_watcher():
    global _branch_watcher
    if _branch_watcher is None:
        from powerline.lib.file_watcher import create_file_watcher
        _branch_watcher = create_file_watcher()
    return _branch_watcher
コード例 #12
0
ファイル: segment.py プロジェクト: wezhang/vim-setup
	def get(segment, side):
		segment_type = segment.get('type', 'function')
		try:
			get_segment_info = segment_getters[segment_type]
		except KeyError:
			raise TypeError('Unknown segment type: {0}'.format(segment_type))

		try:
			contents, _contents_func, module = get_segment_info(data, segment)
		except Exception as e:
			pl.exception('Failed to generate segment from {0!r}: {1}', segment, str(e), prefix='segment_generator')
			return None

		if segment_type == 'function':
			highlight_group = [module + '.' + segment['name'], segment['name']]
		else:
			highlight_group = segment.get('highlight_group') or segment.get('name')

		if segment_type == 'function':
			args = dict(((str(k), v) for k, v in get_key(segment, module, 'args', {}).items()))
			startup_func = get_attr_func(_contents_func, 'startup', args)
			shutdown_func = get_attr_func(_contents_func, 'shutdown', None)

			if hasattr(_contents_func, 'powerline_requires_filesystem_watcher'):
				create_watcher = lambda: create_file_watcher(pl, common_config['watcher'])
				args[str('create_watcher')] = create_watcher

			if hasattr(_contents_func, 'powerline_requires_segment_info'):
				contents_func = lambda pl, segment_info: _contents_func(pl=pl, segment_info=segment_info, **args)
			else:
				contents_func = lambda pl, segment_info: _contents_func(pl=pl, **args)
		else:
			startup_func = None
			shutdown_func = None
			contents_func = None

		return {
			'name': segment.get('name'),
			'type': segment_type,
			'highlight_group': highlight_group,
			'divider_highlight_group': None,
			'before': get_key(segment, module, 'before', ''),
			'after': get_key(segment, module, 'after', ''),
			'contents_func': contents_func,
			'contents': contents,
			'args': args if segment_type == 'function' else {},
			'priority': segment.get('priority', None),
			'draw_hard_divider': segment.get('draw_hard_divider', True),
			'draw_soft_divider': segment.get('draw_soft_divider', True),
			'draw_inner_divider': segment.get('draw_inner_divider', False),
			'side': side,
			'exclude_modes': segment.get('exclude_modes', []),
			'include_modes': segment.get('include_modes', []),
			'width': segment.get('width'),
			'align': segment.get('align', 'l'),
			'startup': startup_func,
			'shutdown': shutdown_func,
			'_rendered_raw': '',
			'_rendered_hl': '',
			'_len': 0,
			'_space_left': 0,
			'_space_right': 0,
		}