Esempio n. 1
0
    def get_spec(self, name, package):
        if not package:
            # if there's no package, we can't do any conversion
            return name

        spec = name
        isabspath = os.path.isabs(name)
        colon_in_name = ':' in name
        isabsspec = colon_in_name and (not isabspath)
        isrelspec = (not isabsspec) and (not isabspath)

        # if it's already an absolute spec, we don't need to do anything,
        # but if it's a relative spec or an absolute path, we need to try
        # to convert it to an absolute spec

        if isrelspec:
            # convert relative asset spec to absolute asset spec
            pp = package_path(package)
            spec = os.path.join(pp, spec)
            spec = asset_spec_from_abspath(spec, package)

        elif isabspath:
            # convert absolute path to absolute asset spec
            spec = asset_spec_from_abspath(spec, package)

        return spec
Esempio n. 2
0
    def get_spec(self, name, package):
        if not package:
            # if there's no package, we can't do any conversion
            return name

        spec = name
        isabspath = os.path.isabs(name)
        colon_in_name = ":" in name
        isabsspec = colon_in_name and (not isabspath)
        isrelspec = (not isabsspec) and (not isabspath)

        # if it's already an absolute spec, we don't need to do anything,
        # but if it's a relative spec or an absolute path, we need to try
        # to convert it to an absolute spec

        if isrelspec:
            # convert relative asset spec to absolute asset spec
            pp = package_path(package)
            spec = os.path.join(pp, spec)
            spec = asset_spec_from_abspath(spec, package)

        elif isabspath:
            # convert absolute path to absolute asset spec
            spec = asset_spec_from_abspath(spec, package)

        return spec
Esempio n. 3
0
def path_spec(context, path):
    # we prefer registering asset specifications over absolute
    # paths because these can be overridden by the asset directive.
    if ':' in path and not os.path.isabs(path):
        # it's already an asset specification
        return path
    abspath = context.path(path)
    if hasattr(context, 'package') and context.package:
        return asset_spec_from_abspath(abspath, context.package)
    return abspath
Esempio n. 4
0
def path_spec(context, path):
    # we prefer registering asset specifications over absolute
    # paths because these can be overridden by the asset directive.
    if ':' in path and not os.path.isabs(path):
        # it's already an asset specification
        return path
    abspath = context.path(path)
    if hasattr(context, 'package') and context.package:
        return asset_spec_from_abspath(abspath, context.package)
    return abspath
Esempio n. 5
0
    def get_spec(self, name, package):
        spec = name
        isabs = os.path.isabs(name)

        if (not isabs) and (not ':' in name) and package:
            # relative asset spec
            if not isabs:
                pp = package_path(package)
                spec = os.path.join(pp, spec)
            spec = asset_spec_from_abspath(spec, package)
        return spec
Esempio n. 6
0
    def get_spec(self, name, package):
        spec = name
        isabs = os.path.isabs(name)

        if (not isabs) and (not ':' in name) and package:
            # relative asset spec
            if not isabs:
                pp = package_path(package)
                spec = os.path.join(pp, spec)
            spec = asset_spec_from_abspath(spec, package)
        return spec
 def _callFUT(self, abspath, package):
     from pyramid.asset import asset_spec_from_abspath
     return asset_spec_from_abspath(abspath, package)