本文整理汇总了Python中Resource.Resource.find_all_in_paths方法的典型用法代码示例。如果您正苦于以下问题:Python Resource.find_all_in_paths方法的具体用法?Python Resource.find_all_in_paths怎么用?Python Resource.find_all_in_paths使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Resource.Resource
的用法示例。
在下文中一共展示了Resource.find_all_in_paths方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: run
# 需要导入模块: from Resource import Resource [as 别名]
# 或者: from Resource.Resource import find_all_in_paths [as 别名]
def run(self):
try:
if not os.path.exists(self.output_dir):
os.makedirs(self.output_dir)
if len(self.file_list) == 0:
resources = Resource.find_all_in_paths(self.paths)
else:
resources = []
for file_path in self.file_list:
resources.append(Resource(file_path))
if resources is not None:
for resource in resources:
if resource.requirements is not None:
directory, file_name = os.path.split(resource.path_to_file)
try:
chunks = resource.get_chunks_by_merging_requirements_from_paths(self.paths, previously_merged=[])
except RequirementNotSatisfiedException, rnse:
print "A requirement could not be satisfied for %s\n\n%s\n" % (resource.path_to_file, rnse)
return -1
for chunk in chunks:
analyzers = self.config.get_analyzers_for_resource(chunk.resource)
if analyzers:
for analyzer in analyzers:
print 'Analysis:%s:%s' % (analyzer.__class__, chunk.resource.path_to_file)
analysis = analyzer.analyze(chunk.resource)
print analysis
if not analysis.good:
return -1
merged_content = ''.join([chunk.content for chunk in chunks])
output_file_name = os.path.join(self.output_dir, file_name)
f = open(output_file_name, 'w')
try:
f.write(merged_content)
finally:
f.flush()
f.close()
print "Created %s" % output_file_name
# TODO: Process chunks to prevent reminification
output_resource = Resource(output_file_name)
minifier = self.config.get_minifier_for_file_type(output_resource.file_type)
if minifier and not output_resource.minified:
minification = minifier.minify(output_resource)
if not minification.good:
print minification
return -1
minified_output_file_path = os.path.join(self.output_dir, output_resource.minified_file_name)
f = open(minified_output_file_path, 'w')
try:
f.write(minification.content)
finally:
f.flush()
f.close()
except Exception:
traceback.print_exc(file=sys.stderr)
return -1
return 0