"""distutils.dep_utilUtility functions for simple, timestamp-based dependency of filesand groups of files; also, function based entirely on suchtimestamp dependency analysis."""import osfrom distutils.errors import DistutilsFileErrordef newer (source, target):"""Return true if 'source' exists and is more recently modified than'target', or if 'source' exists and 'target' doesn't. Return false ifboth exist and 'target' is the same age or younger than 'source'.Raise DistutilsFileError if 'source' does not exist."""if not os.path.exists(source):raise DistutilsFileError("file '%s' does not exist" %os.path.abspath(source))if not os.path.exists(target):return 1from stat import ST_MTIMEmtime1 = os.stat(source)[ST_MTIME]mtime2 = os.stat(target)[ST_MTIME]return mtime1 > mtime2# newer ()def newer_pairwise (sources, targets):"""Walk two filename lists in parallel, testing if each source is newerthan its corresponding target. Return a pair of lists (sources,targets) where source is newer than target, according to the semanticsof 'newer()'."""if len(sources) != len(targets):raise ValueError("'sources' and 'targets' must be same length")# build a pair of lists (sources, targets) where source is newern_sources = []n_targets = []for i in range(len(sources)):if newer(sources[i], targets[i]):n_sources.append(sources[i])n_targets.append(targets[i])return (n_sources, n_targets)# newer_pairwise ()def newer_group (sources, target, missing='error'):"""Return true if 'target' is out-of-date with respect to any filelisted in 'sources'. In other words, if 'target' exists and is newerthan every file in 'sources', return false; otherwise return true.'missing' controls what we do when a source file is missing; thedefault ("error") is to blow up with an OSError from inside 'stat()';if it is "ignore", we silently drop any missing source files; if it is"newer", any missing source files make us assume that 'target' isout-of-date (this is handy in "dry-run" mode: it'll make you pretend tocarry out commands that wouldn't work because inputs are missing, butthat doesn't matter because you're not actually going to run thecommands)."""# If the target doesn't even exist, then it's definitely out-of-date.if not os.path.exists(target):return 1# Otherwise we have to find out the hard way: if *any* source file# is more recent than 'target', then 'target' is out-of-date and# we can immediately return true. If we fall through to the end# of the loop, then 'target' is up-to-date and we return false.from stat import ST_MTIMEtarget_mtime = os.stat(target)[ST_MTIME]for source in sources:if not os.path.exists(source):if missing == 'error': # blow up when we stat() the filepasselif missing == 'ignore': # missing source dropped fromcontinue # target's dependency listelif missing == 'newer': # missing source means target isreturn 1 # out-of-datesource_mtime = os.stat(source)[ST_MTIME]if source_mtime > target_mtime:return 1else:return 0# newer_group ()
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。