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


Python CssCompressor.compile方法代码示例

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


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

示例1: handle

# 需要导入模块: from compressor import CssCompressor [as 别名]
# 或者: from compressor.CssCompressor import compile [as 别名]
    def handle(self, *args, **options):
        # Passing -1 to chown leaves the ownership unchanged, hence the default
        uid = -1
        gid = -1
        chown = options.get("chown", None)
        chgrp = options.get("chgrp", None)
        verbosity = int(options.get("verbosity", 1))
        if chown or chgrp:
            # pwd is only available on POSIX-compliant systems
            try:
                import pwd
            except ImportError:
                raise OptionError("Ownership changes are not supported by your operating system.", "--chown")
            try:
                if chown:
                    uid = pwd.getpwnam(chown).pw_uid
                if chgrp:
                    gid = pwd.getpwnam(chgrp).pw_gid
            except (KeyError, TypeError):
                raise OptionError('The specified username "%s" does not exist or is invalid.' % chown, "--chown")
        if not hasattr(os, "chmod"):
            raise NotImplementedError("Permission changes are not supported by your operating system")
        if not hasattr(settings, "COMPILER_FORMATS") or not settings.COMPILER_FORMATS:
            raise ImproperlyConfigured("COMPILER_FORMATS not specified in settings.")

        if verbosity:
            print "Looking for slateable CSS files in %s" % settings.MEDIA_ROOT

        # Find all files in MEDIA_ROOT that have a COMPILER_FORMATS-supported
        # extension, and return them as a list of (full path to file without
        # extension, extension) tuples.
        files_to_compile = []
        for root, dirs, files in os.walk(settings.MEDIA_ROOT):
            for _dir in dirs:
                for _file in files:
                    name, ext = os.path.splitext(_file)
                    if ext in settings.COMPILER_FORMATS:
                        files_to_compile.append((os.path.join(root, name), ext))

        if verbosity:
            print "Found %s files to be slated..." % len(files_to_compile)

        for filename, extension in files_to_compile:
            if verbosity > 1:
                print "Compiling %s%s" % (filename, extension)
            CssCompressor.compile(filename, settings.COMPILER_FORMATS[extension])
            css_file = "%s.css" % filename
            if chown or chgrp:
                # Change file ownership to specified group and/or user
                os.chown(css_file, uid, gid)
                # Make sure owner can write and everyone can read
                os.chmod(css_file, 0644)
            else:
                # Allow everyone to read and write
                os.chmod(css_file, 0666)

        if verbosity:
            print "Finished slating."
开发者ID:schinckel,项目名称:django-css,代码行数:60,代码来源:css_slate.py


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