本文整理汇总了Python中mediagenerator.utils.find_file函数的典型用法代码示例。如果您正苦于以下问题:Python find_file函数的具体用法?Python find_file怎么用?Python find_file使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了find_file函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: _rebase
def _rebase(self, url):
if "#" in url:
url, hashid = url.rsplit("#", 1)
hashid = "#" + hashid
else:
hashid = ""
if "?" in url:
url, _ = url.rsplit("?", 1)
rebased = None
if url.startswith("."):
rebased = posixpath.join(self.base, url)
rebased = posixpath.normpath(rebased)
else:
rebased = url.strip("/")
path = None
if "/" in self.name: # try find file using relative url in self.name
path = find_file(os.path.join(self.name[: self.name.rindex("/")], rebased))
if path:
rebased = os.path.join(self.name[: self.name.rindex("/")], rebased)
if not path: # try finding file based on GLOBAL_MEDIA_DIRS
path = find_file(rebased)
if not path:
raise Exception(
"Unable to find url `%s` from file %s. File does not exists: %s" % (url, self.name, rebased)
)
# generating data for images doesn't work for scss
if getattr(settings, "GENERATE_DATA_URIS", False) and self.name.endswith(".css"):
if os.path.getsize(path) <= MAX_DATA_URI_FILE_SIZE and not IGNORE_PATTERN.match(rebased):
data = b64encode(open(path, "rb").read())
mime = guess_type(path)[0] or "application/octet-stream"
return "data:%s;base64,%s" % (mime, data)
elif getattr(settings, "GENERATE_DATA_URIS", False) and self.name.endswith(".scss") and False:
if os.path.getsize(path) <= MAX_DATA_URI_FILE_SIZE and not IGNORE_PATTERN.match(rebased):
# data = b64encode(open(path, 'rb').read())
# mime = guess_type(path)[0] or 'application/octet-stream'
return 'inline-image("%s")' % (url)
if appsettings.MEDIA_DEV_MODE:
prefix = appsettings.DEV_MEDIA_URL
version = os.path.getmtime(path)
rebased += "?v=%s" % version
else:
prefix = appsettings.PRODUCTION_MEDIA_URL
with open(path) as sf:
version = sha1(sf.read()).hexdigest()
rebased_prefix, rebased_extention = rebased.rsplit(".", 1)
rebased = "%s.%s" % (rebased_prefix, rebased_extention)
rebased = posixpath.join(prefix, rebased)
return "/" + rebased.strip("/") + hashid
开发者ID:Crop-R,项目名称:django-mediagenerator,代码行数:59,代码来源:urlfix.py
示例2: get_dev_output
def get_dev_output(self, name):
path = find_file(name)
fp = open(path, 'rb')
content = fp.read()
fp.close()
mimetype = guess_type(path)[0]
return content, mimetype
开发者ID:9gix,项目名称:young-generation,代码行数:7,代码来源:copyfiles.py
示例3: fixurls
def fixurls(self, match):
url = match.group(1)
hashid = ''
if '#' in url:
url, hashid = url.split('#', 1)
hashid = '#' + hashid
url_query = None
if '?' in url:
url, url_query = url.split('?', 1)
if ':' not in url and not url.startswith('/'):
rebased_url = posixpath.join(self.base_path, url)
rebased_url = posixpath.normpath(rebased_url)
try:
if GENERATE_DATA_URIS:
path = find_file(rebased_url)
if os.path.getsize(path) <= MAX_DATA_URI_FILE_SIZE and \
not IGNORE_PATTERN.match(rebased_url):
data = b64encode(open(path, 'rb').read())
mime = guess_type(path)[0] or 'application/octet-stream'
return 'url(data:%s;base64,%s)' % (mime, data)
url = media_url(rebased_url)
except:
logging.error('URL not found: %s' % url)
if url_query is None:
url_query = ''
elif '?' in url:
url_query = '&' + url_query
else:
url_query = '?' + url_query
return 'url(%s%s%s)' % (url, url_query, hashid)
开发者ID:9gix,项目名称:young-generation,代码行数:35,代码来源:cssurl.py
示例4: _read_import
def _read_import(self, name):
file_name = find_file(name)
if not file_name:
raise IOError("File not found: '%s'" % name)
with open(file_name, 'r') as f:
return f.read()
开发者ID:Crop-R,项目名称:django-mediagenerator,代码行数:7,代码来源:cssimport.py
示例5: _read_jst_content
def _read_jst_content(self, name):
name = name.strip(' \n\t')
fname = find_file(name)
if not fname:
raise IOError("File not found: '%s'" % name)
with open(fname, 'r') as f:
return smart_unicode(f.read())
开发者ID:Crop-R,项目名称:django-mediagenerator,代码行数:8,代码来源:jstemplate.py
示例6: _regenerate
def _regenerate(self, debug=False):
path = find_file(self.module)
mtime = os.path.getmtime(path)
if mtime == self._mtime:
return
source = read_text_file(path)
self._compiled = self._compile(source, debug=debug)
self._compiled_hash = sha1(smart_str(self._compiled)).hexdigest()
self._mtime = mtime
开发者ID:Crop-R,项目名称:django-mediagenerator,代码行数:9,代码来源:coffeescript.py
示例7: get_dev_output
def get_dev_output(self, name, variation):
assert name == self.name, (
'''File name "%s" doesn't match the one in GENERATE_MEDIA ("%s")'''
% (name, self.name))
path = find_file(name)
assert path, """File name "%s" doesn't exist.""" % name
fp = open(path, 'r')
output = fp.read()
fp.close()
return output
开发者ID:rinunu,项目名称:mabichara,代码行数:10,代码来源:base.py
示例8: _regenerate
def _regenerate(self, debug=False):
path = find_file(self.module)
mtime = os.path.getmtime(path)
if mtime == self._mtime:
return
fp = open(path, 'r')
source = fp.read()
fp.close()
self._compiled = self._compile(source, debug=debug)
self._compiled_hash = sha1(self._compiled).hexdigest()
self._mtime = mtime
开发者ID:flashycud,项目名称:timestack,代码行数:11,代码来源:coffeescript.py
示例9: __init__
def __init__(self, **kwargs):
self.config(kwargs, module=None)
super(CoffeeScript, self).__init__(**kwargs)
assert self.filetype == 'js', (
'CoffeeScript only supports compilation to js. '
'The parent filter expects "%s".' % self.filetype)
self._compiled = None
self._compiled_hash = None
self._mtime = None
if not find_file(self.module):
raise RuntimeError('File not found: %s' % self.module)
开发者ID:Crop-R,项目名称:django-mediagenerator,代码行数:11,代码来源:coffeescript.py
示例10: _find_file
def _find_file(self, name):
if not name.endswith(('.sass', '.scss')):
names = (name + '.sass', name + '.scss')
else:
names = (name,)
parts = name.rsplit('/', 1)
parts[-1] = '_' + parts[-1]
names += ('/'.join(parts),)
for name in names:
path = find_file(name, media_dirs=self.path)
if path:
return path
开发者ID:rinunu,项目名称:mabichara,代码行数:12,代码来源:sass.py
示例11: _find_file
def _find_file(self, name):
parts = name.rsplit("/", 1)
parts[-1] = "_" + parts[-1]
partial = "/".join(parts)
if not name.endswith((".sass", ".scss")):
names = (name + ".sass", name + ".scss", partial + ".sass", partial + ".scss")
else:
names = (name, partial)
for name in names:
path = find_file(name, media_dirs=self.path)
if path:
return path
开发者ID:pombredanne,项目名称:shihewrite,代码行数:12,代码来源:sass.py
示例12: _find_deps
def _find_deps(self, name, lang):
resolver = CommentResolver(lang)
deps = []
for dep in resolver.resolve(name):
dep_file = find_file(dep)
if not dep_file:
continue
deps += self._find_deps(dep_file, lang)
deps.append(dep)
return deps
开发者ID:rhoog,项目名称:django-mediagenerator,代码行数:12,代码来源:collector.py
示例13: get_last_modified
def get_last_modified(self):
content = super(CssImport, self).get_dev_output(self.name, {})
files = []
self.rewrite_re.sub(lambda m: files.append(m.group(1)), content)
lm = 0
for f in files:
fname = find_file(f)
if not fname: return time.time()
fmod = os.path.getmtime(fname)
if fmod > lm: lm = fmod
return lm
开发者ID:bogdanvarlamov,项目名称:django-mediagenerator,代码行数:12,代码来源:cssimport.py
示例14: make_imports
def make_imports(self, match):
fname = find_file(match.group(1))
if not fname:
lineno = match.string.count('\n', 0, match.start())
print "[%s:%d] Can't find file `%s`" % (self.name, lineno, match.group(1))
return ""
try:
with open(fname, 'r') as sf: content = sf.read()
except IOError, e:
lineno = match.string.count('\n', 0, match.start())
info = self.name, lineno, fname, e
print "[%s:%d] Can't import file `%s`: %s" % info
return ""
开发者ID:bogdanvarlamov,项目名称:django-mediagenerator,代码行数:14,代码来源:cssimport.py
示例15: _find_css
def _find_css(self, name):
result = []
for ext in MEDIA_CSS_EXT:
if isinstance(MEDIA_CSS_LOCATION, basestring):
locations = [MEDIA_CSS_LOCATION]
else:
locations = MEDIA_CSS_LOCATION
for location in locations:
entry_name = os.path.join(location, name + "." + ext)
entry_file = find_file(entry_name)
if entry_file:
result += self._find_deps(entry_file, "css")
result.append(entry_name)
break
return result
开发者ID:Crop-R,项目名称:django-mediagenerator,代码行数:17,代码来源:collector.py
示例16: _find_deps
def _find_deps(self, name, lang):
if not MEDIA_DEV_MODE:
if name in self._cache:
return self._cache[name]
resolver = CommentResolver(lang)
deps = []
for dep in resolver.resolve(name):
dep_file = find_file(dep)
if not dep_file:
continue
deps += self._find_deps(dep_file, lang)
deps.append(dep)
if not MEDIA_DEV_MODE:
self._cache[name] = deps
return deps
开发者ID:Crop-R,项目名称:django-mediagenerator,代码行数:19,代码来源:collector.py
示例17: _collect_scss_files
def _collect_scss_files(self):
files = {}
pool = [self.name]
last_modified = 0
while len(pool):
item = pool.pop(0)
try:
content = self._read_import(item)
except IOError:
return None
for quote, include in self.IMPORT.findall(content):
fname = include.strip(' \n\t')
pool.append(fname)
fname = find_file(item)
if not fname:
return None
files[fname] = os.path.getmtime(fname)
return files
开发者ID:Crop-R,项目名称:django-mediagenerator,代码行数:21,代码来源:cssimport.py
示例18: _rebase
def _rebase(self, url):
if "#" in url:
url, hashid = url.rsplit("#", 1)
hashid = "#" + hashid
else:
hashid = ""
if url.startswith("."):
rebased = os.path.join(self.base, url)
rebased = os.path.normpath(rebased)
else:
rebased = url.strip("/")
local_file_path = utils.find_file(rebased)
if not os.path.exists(local_file_path):
print "Check path", os.path.realpath(local_file_path), rebased
raise Exception("Unable to find url `%s` from file %s. File does not exists: %s" % (
url,
self.name,
local_file_path
))
if appsettings.MEDIA_DEV_MODE:
prefix = appsettings.DEV_MEDIA_URL
version = os.path.getmtime(local_file_path)
rebased += "?v=%s" % version
else:
prefix = appsettings.PRODUCTION_MEDIA_URL
with open(local_file_path, "rb") as sf:
version = sha1(sf.read()).hexdigest()
print(version)
rebased_prefix, rebased_extention = rebased.rsplit(".", 1)
rebased = "%s-%s.%s" % (rebased_prefix, version, rebased_extention)
#need to correct the windows path (back slash) to web url (forward slash)
rebased = "\"" + os.path.join(prefix, rebased.replace("\\", "/")) + "\""
return rebased.strip("/") + hashid
开发者ID:bogdanvarlamov,项目名称:django-mediagenerator,代码行数:39,代码来源:urlfix.py
示例19: fixurls
def fixurls(self, match):
url = match.group(1)
hashid = ''
if '#' in url:
url, hashid = url.split('#', 1)
hashid = '#' + hashid
url_query = None
if '?' in url:
url, url_query = url.split('?', 1)
if ':' not in url and not url.startswith('/'):
rebased_url = posixpath.join(self.base_path, url)
rebased_url = posixpath.normpath(rebased_url)
try:
if GENERATE_DATA_URIS:
path = find_file(rebased_url)
if os.path.getsize(path) <= MAX_DATA_URI_FILE_SIZE and \
not IGNORE_PATTERN.match(rebased_url):
data = b64encode(open(path, 'rb').read())
mime = guess_type(path)[0] or 'application/octet-stream'
return 'url(data:%s;base64,%s)' % (mime, data)
url = media_url(rebased_url)
except:
if settings.PRODUCTION:
# Removing this from local dev env so we can have a less
# cluttered console. Will warn us of issues while testing
# on GAE environment.
logging.error('URL not found: %s' % url)
if url_query is None:
url_query = ''
elif '?' in url:
url_query = '&' + url_query
else:
url_query = '?' + url_query
return 'url(%s%s%s)' % (url, url_query, hashid)
开发者ID:ketan21,项目名称:the-courrier,代码行数:39,代码来源:cssurl.py
示例20: get_last_modified
def get_last_modified(self):
pool = [self.name]
last_modified = 0
while len(pool):
item = pool.pop(0)
try:
content = self._read_jst_content(item)
except IOError:
return None
for include in self.include.findall(content):
fname = include.strip(' \n\t')
pool.append(fname)
fname = find_file(item)
if not fname:
return None
lm = os.path.getmtime(fname)
if lm > last_modified:
last_modified = lm
return last_modified
开发者ID:Crop-R,项目名称:django-mediagenerator,代码行数:22,代码来源:jstemplate.py
注:本文中的mediagenerator.utils.find_file函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论