当前位置: 首页>>代码示例>>Python>>正文


Python Utils.lazy_generator方法代码示例

本文整理汇总了Python中waflib.Utils.lazy_generator方法的典型用法代码示例。如果您正苦于以下问题:Python Utils.lazy_generator方法的具体用法?Python Utils.lazy_generator怎么用?Python Utils.lazy_generator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在waflib.Utils的用法示例。


在下文中一共展示了Utils.lazy_generator方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: ant_glob

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import lazy_generator [as 别名]
	def ant_glob(self, *k, **kw):
		"""
		Finds files across folders:

		* ``**/*`` find all files recursively
		* ``**/*.class`` find all files ending by .class
		* ``..`` find files having two dot characters

		For example::

			def configure(cfg):
				cfg.path.ant_glob('**/*.cpp') # finds all .cpp files
				cfg.root.ant_glob('etc/*.txt') # matching from the filesystem root can be slow
				cfg.path.ant_glob('*.cpp', excl=['*.c'], src=True, dir=False)

		For more information see http://ant.apache.org/manual/dirtasks.html

		The nodes that correspond to files and folders that do not exist are garbage-collected.
		To prevent this behaviour in particular when running over the build directory, pass ``remove=False``

		:param incl: ant patterns or list of patterns to include
		:type incl: string or list of strings
		:param excl: ant patterns or list of patterns to exclude
		:type excl: string or list of strings
		:param dir: return folders too (False by default)
		:type dir: bool
		:param src: return files (True by default)
		:type src: bool
		:param maxdepth: maximum depth of recursion
		:type maxdepth: int
		:param ignorecase: ignore case while matching (False by default)
		:type ignorecase: bool
		:returns: The corresponding Nodes
		:type generator: bool
		:param remove: remove files/folders that do not exist (True by default)
		:type remove: bool
		:param quiet: disable build directory traversal warnings (verbose mode)
		:type quiet: bool
		:returns: Whether to evaluate the Nodes lazily, alters the type of the returned value
		:rtype: by default, list of :py:class:`waflib.Node.Node` instances
		"""
		src = kw.get('src', True)
		dir = kw.get('dir')
		excl = kw.get('excl', exclude_regs)
		incl = k and k[0] or kw.get('incl', '**')
		remove = kw.get('remove', True)
		maxdepth = kw.get('maxdepth', 25)
		ignorecase = kw.get('ignorecase', False)
		quiet = kw.get('quiet', False)
		pats = (ant_matcher(incl, ignorecase), ant_matcher(excl, ignorecase))

		if kw.get('generator'):
			return Utils.lazy_generator(self.ant_iter, (ant_sub_matcher, maxdepth, pats, dir, src, remove, quiet))

		it = self.ant_iter(ant_sub_matcher, maxdepth, pats, dir, src, remove, quiet)
		if kw.get('flat'):
			# returns relative paths as a space-delimited string
			# prefer Node objects whenever possible
			return ' '.join(x.path_from(self) for x in it)
		return list(it)
开发者ID:bugengine,项目名称:BugEngine,代码行数:62,代码来源:Node.py

示例2: ant_glob

# 需要导入模块: from waflib import Utils [as 别名]
# 或者: from waflib.Utils import lazy_generator [as 别名]
	def ant_glob(self, *k, **kw):
		"""
		Finds files across folders and returns Node objects:

		* ``**/*`` find all files recursively
		* ``**/*.class`` find all files ending by .class
		* ``..`` find files having two dot characters

		For example::

			def configure(cfg):
				# find all .cpp files
				cfg.path.ant_glob('**/*.cpp')
				# find particular files from the root filesystem (can be slow)
				cfg.root.ant_glob('etc/*.txt')
				# simple exclusion rule example
				cfg.path.ant_glob('*.c*', excl=['*.c'], src=True, dir=False)

		For more information about the patterns, consult http://ant.apache.org/manual/dirtasks.html
		Please remember that the '..' sequence does not represent the parent directory::

			def configure(cfg):
				cfg.path.ant_glob('../*.h') # incorrect
				cfg.path.parent.ant_glob('*.h') # correct

		The Node structure is itself a filesystem cache, so certain precautions must
		be taken while matching files in the build or installation phases.
		Nodes objects that do have a corresponding file or folder are garbage-collected by default.
		This garbage collection is usually required to prevent returning files that do not
		exist anymore. Yet, this may also remove Node objects of files that are yet-to-be built.

		This typically happens when trying to match files in the build directory,
		but there are also cases when files are created in the source directory.
		Run ``waf -v`` to display any warnings, and try consider passing ``remove=False``
		when matching files in the build directory.

		Since ant_glob can traverse both source and build folders, it is a best practice
		to call this method only from the most specific build node::

			def build(bld):
				# traverses the build directory, may need ``remove=False``:
				bld.path.ant_glob('project/dir/**/*.h')
				# better, no accidental build directory traversal:
				bld.path.find_node('project/dir').ant_glob('**/*.h') # best

		In addition, files and folders are listed immediately. When matching files in the
		build folders, consider passing ``generator=True`` so that the generator object
		returned can defer computation to a later stage. For example::

			def build(bld):
				bld(rule='tar xvf ${SRC}', source='arch.tar')
				bld.add_group()
				gen = bld.bldnode.ant_glob("*.h", generator=True, remove=True)
				# files will be listed only after the arch.tar is unpacked
				bld(rule='ls ${SRC}', source=gen, name='XYZ')


		:param incl: ant patterns or list of patterns to include
		:type incl: string or list of strings
		:param excl: ant patterns or list of patterns to exclude
		:type excl: string or list of strings
		:param dir: return folders too (False by default)
		:type dir: bool
		:param src: return files (True by default)
		:type src: bool
		:param maxdepth: maximum depth of recursion
		:type maxdepth: int
		:param ignorecase: ignore case while matching (False by default)
		:type ignorecase: bool
		:param generator: Whether to evaluate the Nodes lazily
		:type generator: bool
		:param remove: remove files/folders that do not exist (True by default)
		:type remove: bool
		:param quiet: disable build directory traversal warnings (verbose mode)
		:type quiet: bool
		:returns: The corresponding Node objects as a list or as a generator object (generator=True)
		:rtype: by default, list of :py:class:`waflib.Node.Node` instances
		"""
		src = kw.get('src', True)
		dir = kw.get('dir')
		excl = kw.get('excl', exclude_regs)
		incl = k and k[0] or kw.get('incl', '**')
		remove = kw.get('remove', True)
		maxdepth = kw.get('maxdepth', 25)
		ignorecase = kw.get('ignorecase', False)
		quiet = kw.get('quiet', False)
		pats = (ant_matcher(incl, ignorecase), ant_matcher(excl, ignorecase))

		if kw.get('generator'):
			return Utils.lazy_generator(self.ant_iter, (ant_sub_matcher, maxdepth, pats, dir, src, remove, quiet))

		it = self.ant_iter(ant_sub_matcher, maxdepth, pats, dir, src, remove, quiet)
		if kw.get('flat'):
			# returns relative paths as a space-delimited string
			# prefer Node objects whenever possible
			return ' '.join(x.path_from(self) for x in it)
		return list(it)
开发者ID:blablack,项目名称:ams-lv2,代码行数:99,代码来源:Node.py


注:本文中的waflib.Utils.lazy_generator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。