def check_timestamps(self, bundle, env, o_modified=None): from bundle import Bundle, is_url if not o_modified: o_modified = os.stat(env.abspath(bundle.output)).st_mtime # Recurse through the bundle hierarchy. Check the timestamp of all # the bundle source files, as well as any additional # dependencies that we are supposed to watch. for iterator, result in ( (lambda e: map(lambda s: s[1], bundle.resolve_contents(e)), True), (bundle.resolve_depends, SKIP_CACHE)): for item in iterator(env): if isinstance(item, Bundle): result = self.check_timestamps(item, env, o_modified) if result: return result elif not is_url(item): try: s_modified = os.stat(item).st_mtime except OSError: # If a file goes missing, always require # a rebuild. return result else: if s_modified > o_modified: return result return False
def resolve_source(self, item): """Given ``item`` from a Bundle's contents, this has to return the final value to use, usually an absolute filesystem path. .. note:: It is also allowed to return urls and bundle instances (or generally anything else the calling :class:`Bundle` instance may be able to handle). Indeed this is the reason why the name of this method does not imply a return type. The incoming item is usually a relative path, but may also be an absolute path, or a url. These you will commonly want to return unmodified. This method is also allowed to resolve ``item`` to multiple values, in which case a list should be returned. This is commonly used if ``item`` includes glob instructions (wildcards). .. note:: Instead of this, subclasses should consider implementing :meth:`search_for_source` instead. """ # Pass through some things unscathed if not isinstance(item, basestring): # Don't stand in the way of custom values. return item if is_url(item) or path.isabs(item): return item return self.search_for_source(item)
def check_timestamps(self, bundle, env, o_modified=None): from bundle import Bundle, is_url if not o_modified: o_modified = os.stat(env.abspath(bundle.output)).st_mtime # Recurse through the bundle hierarchy. Check the timestamp of all # the bundle source files, as well as any additional # dependencies that we are supposed to watch. for iterator, result in ( (lambda e: map(lambda s: s[1], bundle.resolve_contents(e)), True), (bundle.resolve_depends, SKIP_CACHE) ): for item in iterator(env): if isinstance(item, Bundle): result = self.check_timestamps(item, env, o_modified) if result: return result elif not is_url(item): try: s_modified = os.stat(item).st_mtime except OSError: # If a file goes missing, always require # a rebuild. return result else: if s_modified > o_modified: return result return False
def check_timestamps(self, bundle, env, o_modified=None): from bundle import Bundle, is_url from webassets.version import TimestampVersion if not o_modified: try: resolved_output = bundle.resolve_output(env) except BundleError: # This exception will occur when the bundle output has # placeholder, but a version cannot be found. If the # user has defined a manifest, this will just be the first # build. Return True to let it happen. # However, if no manifest is defined, raise an error, # because otherwise, this updater would always return True, # and thus not do its job at all. if env.manifest is None: raise BuildError( ( "%s uses a version placeholder, and you are " 'using "%s" versions. To use automatic ' "building in this configuration, you need to " "define a manifest." % (bundle, env.versions) ) ) return True try: o_modified = TimestampVersion.get_timestamp(resolved_output) except OSError: # If the output file does not exist, we'll have to rebuild return True # Recurse through the bundle hierarchy. Check the timestamp of all # the bundle source files, as well as any additional # dependencies that we are supposed to watch. for iterator, result in ( (lambda e: map(lambda s: s[1], bundle.resolve_contents(e)), True), (bundle.resolve_depends, SKIP_CACHE), ): for item in iterator(env): if isinstance(item, Bundle): nested_result = self.check_timestamps(item, env, o_modified) if nested_result: return nested_result elif not is_url(item): try: s_modified = TimestampVersion.get_timestamp(item) except OSError: # If a file goes missing, always require # a rebuild. return result else: if s_modified > o_modified: return result return False
def check_timestamps(self, bundle, env, o_modified=None): from bundle import Bundle, is_url from webassets.version import TimestampVersion if not o_modified: try: resolved_output = bundle.resolve_output(env) except BundleError: # This exception will occur when the bundle output has # placeholder, but a version cannot be found. If the # user has defined a manifest, this will just be the first # build. Return True to let it happen. # However, if no manifest is defined, raise an error, # because otherwise, this updater would always return True, # and thus not do its job at all. if env.manifest is None: raise BuildError( ('%s uses a version placeholder, and you are ' 'using "%s" versions. To use automatic ' 'building in this configuration, you need to ' 'define a manifest.' % (bundle, env.versions))) return True try: o_modified = TimestampVersion.get_timestamp(resolved_output) except OSError: # If the output file does not exist, we'll have to rebuild return True # Recurse through the bundle hierarchy. Check the timestamp of all # the bundle source files, as well as any additional # dependencies that we are supposed to watch. for iterator, result in ( (lambda e: map(lambda s: s[1], bundle.resolve_contents(e)), True), (bundle.resolve_depends, SKIP_CACHE)): for item in iterator(env): if isinstance(item, Bundle): nested_result = self.check_timestamps( item, env, o_modified) if nested_result: return nested_result elif not is_url(item): try: s_modified = TimestampVersion.get_timestamp(item) except OSError: # If a file goes missing, always require # a rebuild. return result else: if s_modified > o_modified: return result return False
def resolve_source(self, item): """Given ``item`` from a Bundle's contents, return an absolute filesystem path. ``item`` may include glob syntax, in which a list of paths should be returned. .. note:: This is also allowed to return urls and bundles (or in fact anything else the calling :class:`Bundle` instance may be able to handle. """ # Pass through some things unscathed if not isinstance(item, basestring): return item if is_url(item) or path.isabs(item): return item return self.search_for_source(item)