當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。