本文整理汇总了Python中Configuration.Configuration.get_analyzers_for_resource方法的典型用法代码示例。如果您正苦于以下问题:Python Configuration.get_analyzers_for_resource方法的具体用法?Python Configuration.get_analyzers_for_resource怎么用?Python Configuration.get_analyzers_for_resource使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Configuration.Configuration
的用法示例。
在下文中一共展示了Configuration.get_analyzers_for_resource方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: Application
# 需要导入模块: from Configuration import Configuration [as 别名]
# 或者: from Configuration.Configuration import get_analyzers_for_resource [as 别名]
class Application():
DEFAULT_OUTPUT_DIR = os.path.join(os.getcwd(), 'output')
DEFAULT_PATH_LIST = []
DEFAULT_INCLUDE_CWD = True
DEFAULT_FILE_LIST = []
DEFAULT_CONFIG_FILE_PATH = os.path.join(os.getcwd(), '.blend', 'config.json')
def __init__(self, path_list=DEFAULT_PATH_LIST, include_cwd=DEFAULT_INCLUDE_CWD,
file_list=DEFAULT_FILE_LIST, output_dir=DEFAULT_OUTPUT_DIR, config_file_path=DEFAULT_CONFIG_FILE_PATH):
self.paths = Paths(*path_list, include_cwd=include_cwd)
self.include_cwd = include_cwd
self.file_list = file_list
self.output_dir = output_dir
if os.path.exists(config_file_path):
print config_file_path
self.config = Configuration(config_file_path)
else:
self.config = self._create_default_configuration()
def _create_default_configuration(self):
config = Configuration()
# By default, skip analysis for any file in a 'lib' folder no matter how deeply
# nested in the project.
config.add_analyzer_for_file_type(JSLintAnalyzer(), 'javascript', [
os.path.join('lib', '*'),
os.path.join('*', 'lib', '*')
])
config.set_minifier_for_file_type(YUICompressorMinifier(), 'javascript')
config.set_minifier_for_file_type(YUICompressorMinifier(), 'css')
return config
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
@staticmethod
def main():
parser = optparse.OptionParser("""usage %prog [options] [file1 [file2 [fileN]]]
#.........这里部分代码省略.........