示例#1
0
文件: env.py 项目: gnanet/pillen
    def resolve_source(self, ctx, 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, six.string_types):
            # 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(ctx, item)
示例#2
0
文件: env.py 项目: kcikeerf/ordoslaw
    def resolve_source(self, ctx, 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, six.string_types):
            # 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(ctx, item)
示例#3
0
    def check_timestamps(self, bundle, ctx, o_modified=None):
        from .bundle import Bundle
        from webassets.version import TimestampVersion

        if not o_modified:
            try:
                resolved_output = bundle.resolve_output(ctx)
            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 ctx.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, ctx.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.
        from webassets.bundle import wrap
        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(ctx):
                if isinstance(item, Bundle):
                    nested_result = self.check_timestamps(
                        item, wrap(ctx, item), 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
示例#4
0
    def check_timestamps(self, bundle, ctx, o_modified=None):
        from .bundle import Bundle
        from webassets.version import TimestampVersion

        if not o_modified:
            try:
                resolved_output = bundle.resolve_output(ctx)
            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 ctx.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, ctx.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.
        from webassets.bundle import wrap
        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(ctx):
                if isinstance(item, Bundle):
                    nested_result = self.check_timestamps(item, wrap(ctx, item), 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
示例#5
0
 def find_recent_most_timestamp(cls, bundle, ctx):
     from webassets.bundle import get_all_bundle_files
     # 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.
     most_recent = None
     for filename in get_all_bundle_files(bundle, ctx):
         if is_url(filename):
             continue
         timestamp = cls.get_timestamp(filename)
         if most_recent is None or timestamp > most_recent:
             most_recent = timestamp
     return most_recent
示例#6
0
 def find_recent_most_timestamp(cls, bundle, ctx):
     from webassets.bundle import get_all_bundle_files
     # 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.
     most_recent = None
     for filename in get_all_bundle_files(bundle, ctx):
         if is_url(filename):
             continue
         timestamp = cls.get_timestamp(filename)
         if most_recent is None or timestamp > most_recent:
             most_recent = timestamp
     return most_recent