def update(self):
        # type: () -> Set[ConfigHandler]
        """
		Parse all `.info` files to build list of handlers.

		:returns: Set of all handlers.
		"""
        self._handlers.clear()
        self._multifiles.clear()
        self._subfiles.clear()

        handlers = set()  # type: Set[ConfigHandler]
        for info in directory_files(INFO_DIR):
            if not info.endswith('.info'):
                continue
            for section in parseRfc822(open(info, 'r').read()):
                handler = self.get_handler(section)
                if handler:
                    handlers.add(handler)
        for handler in handlers:
            for variable in handler.variables:
                v2h = self._handlers.setdefault(variable, set())
                v2h.add(handler)

        self._save_cache()
        return handlers
Exemplo n.º 2
0
 def commit(self, ucr, filelist=list()):
     """Call handlers to (re-)generate files."""
     _filelist = []
     for fname in filelist:
         fname = os.path.expanduser(fname)
         fname = os.path.expandvars(fname)
         fname = os.path.abspath(fname)
         _filelist.append(fname)
     # find handlers
     pending_handlers = set()
     for fname in directory_files(INFO_DIR):
         if not fname.endswith('.info'):
             continue
         for section in parseRfc822(open(fname, 'r').read()):
             if not section.get('Type'):
                 continue
             handler = None
             if _filelist:
                 files = section.get('File') or section.get(
                     'Multifile') or ()
                 for filename in files:
                     if not os.path.isabs(filename):
                         filename = '/%s' % filename
                     if filename in _filelist:
                         handler = self.get_handler(section)
                         break
                 else:
                     continue
             else:
                 handler = self.get_handler(section)
             if handler:
                 pending_handlers.add(handler)
     # call handlers
     for handler in pending_handlers:
         self.call_handler(ucr, handler)
Exemplo n.º 3
0
	def commit(self, ucr, filelist=list()):
		"""Call handlers to (re-)generate files."""
		_filelist = []
		for fname in filelist:
			fname = os.path.expanduser(fname)
			fname = os.path.expandvars(fname)
			fname = os.path.abspath(fname)
			_filelist.append(fname)
		# find handlers
		pending_handlers = set()
		for fname in directory_files(INFO_DIR):
			if not fname.endswith('.info'):
				continue
			for section in parseRfc822(open(fname, 'r').read()):
				if not section.get('Type'):
					continue
				handler = None
				if _filelist:
					files = section.get('File') or \
							section.get('Multifile') or ()
					for filename in files:
						if not os.path.isabs(filename):
							filename = '/%s' % filename
						if filename in _filelist:
							handler = self.get_handler(section)
							break
					else:
						continue
				else:
					handler = self.get_handler(section)
				if handler:
					pending_handlers.add(handler)
		# call handlers
		for handler in pending_handlers:
			self.call_handler(ucr, handler)
def test_directory_files(tmpdir):
    base = tmpdir.mkdir("test")
    files = [
        base.ensure("file"),
        base.mkdir("sub").ensure("file"),
    ]
    broken = base.ensure("broken")
    base.join("link").mksymlinkto(broken),
    broken.remove()
    assert set(ucrm.directory_files(
        str(base))) == {str(path)
                        for path in files}
Exemplo n.º 5
0
    def commit(self, ucr, filelist=list()):
        # type: (_UCR, Iterable[str]) -> None
        """
		Call handlers to (re-)generate files.

		:param ucr: UCR instance.
		:param filelist: List of files to re-generate. By default *all* files will be re-generated and all modules and scripts will we re-invoked!
		"""
        _filelist = []
        for fname in filelist:
            fname = os.path.expanduser(fname)
            fname = os.path.expandvars(fname)
            fname = os.path.abspath(fname)
            _filelist.append(fname)

        # find handlers
        pending_handlers = set()
        for fname in directory_files(INFO_DIR):
            if not fname.endswith('.info'):
                continue
            for section in parseRfc822(
                    open(fname, 'r', encoding='utf-8').read()):
                if not section.get('Type'):
                    continue
                handler = None
                if _filelist:
                    files = section.get('File') or section.get(
                        'Multifile') or ()
                    for filename in files:
                        if not os.path.isabs(filename):
                            filename = '/%s' % filename
                        if filename in _filelist:
                            handler = self.get_handler(section)
                            break
                    else:
                        continue
                else:
                    handler = self.get_handler(section)

                if handler:
                    pending_handlers.add(handler)

        # call handlers
        for handler in pending_handlers:
            self.call_handler(ucr, handler)
Exemplo n.º 6
0
	def update(self):
		"""Parse all .info files to build list of handlers."""
		self._handlers.clear()
		self._multifiles.clear()
		self._subfiles.clear()

		handlers = set()
		for info in directory_files(INFO_DIR):
			if not info.endswith('.info'):
				continue
			for section in parseRfc822(open(info, 'r').read()):
				handler = self.get_handler(section)
				if handler:
					handlers.add(handler)
		for handler in handlers:
			for variable in handler.variables:
				v2h = self._handlers.setdefault(variable, set())
				v2h.add(handler)

		self._save_cache()
		return handlers