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


Python Common.message方法代码示例

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


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

示例1: main

# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import message [as 别名]
def main(argv):
    Common.init("/mnt/config/config.yml", docker_container=argv[1])
    
    Common.message(_('Loading pipeline...'))
    pipeline = Pipeline(path="/mnt/pipeline/pipeline.yml", host_path=argv[0])
    
    if len(argv) > 2 and argv[2] == "test":
        pipeline.run_tests()
        
    elif len(argv) > 2 and argv[2]:
        Common.message(_('Unknown argument')+": "+argv[2])
        
    else:
        Web(pipeline, host='0.0.0.0')
开发者ID:josteinaj,项目名称:docker-pipeline,代码行数:16,代码来源:run.py

示例2: run_tests

# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import message [as 别名]
 def run_tests(self):
     focus = None
     for test_name in self.tests:
         for test_id in self.tests[test_name]:
             if 'focus' in self.tests[test_name][test_id]:
                 focus = test_name
                 Common.message(_('Focusing on test:')+' '+test_name)
                 break
     
     tests_run = 0
     tests_failed = 0
     tests_skipped = 0
     
     for test_name in self.tests:
         if test_name == '*':
             continue
         if focus and test_name != focus:
             continue
         Common.message("\n---\n"+_('Running test:')+' '+test_name+"\n")
         
         test = self.tests[test_name]
         
         temp_path = tempfile.mkdtemp(prefix='test-')
         tests_path = os.path.dirname(self.path)+"/tests"
         
         config_path = None # tests_path+"/"+test_name+"/config"
         input_path = tests_path+"/"+test_name
         output_path = temp_path+"/"+test_name+"/output"
         status_path = temp_path+"/"+test_name+"/status"
         os.makedirs(output_path)
         os.makedirs(status_path)
         
         result = self.run(config_path, input_path, output_path, status_path, test=test_name)
         tests_run += result['tests']['run']
         tests_failed += result['tests']['failed']
         tests_skipped += result['tests']['skipped']
         
         Common.message("")
         Common.message(_('Host system path to pipeline output is:')+' '+Common.host_path(os.path.dirname(output_path)))
     
     Common.message("")
     if focus:
         Common.message(_('Test in focus:')+' '+test_name)
     Common.message("TESTS RUN: "+str(tests_run))
     Common.message("TESTS FAILED: "+str(tests_failed))
开发者ID:josteinaj,项目名称:docker-pipeline,代码行数:47,代码来源:pipeline.py

示例3: run

# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import message [as 别名]
    def run(self, config_path, input_path, output_path, status_path, status="", test=None, step_id='', step_depth=0):
        temp_path = tempfile.mkdtemp(prefix='pipeline-')
        
        tests_run = 0
        tests_failed = 0
        tests_skipped = 0
        
        pipeline_context_name = os.path.basename(input_path)
        padding = (self.location if len(self.steps) == 0 else self.steps[0][list(self.steps[0].keys())[0]]['location']).ljust(20+step_depth*2)
        Common.message(padding+'-- Context is: '+pipeline_context_name)
        
        current_input_path = None
        current_output_path = None
        current_status_path = None
        current_status = ''
        
        exit = False
        position = 0
        step_count = len([ step_object for step_object in self.steps if (list(step_object.keys())[0] != 'test' and list(step_object.keys())[0] != 'assert') ])
        if step_count == 0:
            current_status = status
            current_input_path = input_path
            current_output_path = output_path
            current_status_path = status_path
            if status != None:
                Common.write_file(current_status_path+'/status.txt', status)
            if os.path.isdir(current_input_path):
                for item in os.listdir(current_input_path):
                    item_fullpath = os.path.join(current_input_path, item)
                    if os.path.isdir(item_fullpath):
                        shutil.copytree(item_fullpath, current_output_path+'/'+os.path.basename(item_fullpath))
                    else:
                        shutil.copy2(item_fullpath, current_output_path+'/'+os.path.basename(item_fullpath))
            else:
                shutil.copy2(current_input_path, current_output_path+'/'+os.path.basename(current_input_path))
            
        for step_object in self.steps:
            step_type = list(step_object.keys())[0]
            step = step_object[step_type]
            padding = step['location'].ljust(20+step_depth*2)
            
            if exit or step_type == 'exit':
                if step_type == 'exit':
                    Common.message(padding+'-- Exiting')
                exit = True
                break
            
            current_status = status if not current_status_path else Common.first_line(current_status_path)
            
            if step_type != 'test' and step_type != 'assert':
                current_step_id = step_id+'/'+str(position)
                Common.message(padding+'-- Running '+step_type+': '+(step_type if not 'name' in step else step['name']))
                
                if position > 0:
                    current_input_path = current_output_path
                else:
                    current_input_path = input_path
                
                if position < step_count - 1:
                    current_output_path = temp_path+"/"+str(position)+"/output"
                    current_status_path = temp_path+"/"+str(position)+"/status"
                    os.makedirs(current_output_path)
                    os.makedirs(current_status_path)
                else:
                    current_output_path = output_path
                    current_status_path = status_path
                
                if step_type == 'image':
                    volumes = {}
                    if config_path:
                        volumes[config_path] = { 'bind': '/mnt/config', 'mode': 'ro' }
                    volumes[current_input_path] = { 'bind': '/mnt/input'+('/'+pipeline_context_name if not os.path.isdir(current_input_path) else ''), 'mode': 'ro' }
                    volumes[current_output_path] = { 'bind': '/mnt/output', 'mode': 'rw' }
                    volumes[current_status_path] = { 'bind': '/mnt/status', 'mode': 'rw' }
                    
                    command = None if not 'command' in step else step['command']
                    
                    Common.docker_run(step['id'], volumes, command=command)
                
                elif step_type == 'choose':
                    for when in step['choices']:
                        when_key = list(when.keys())[0]
                        if (not 'test' in when[when_key]) or when[when_key]['test'] == current_status:
                            result = when[when_key]['pipeline'].run(config_path, file_or_dir, current_output_path, current_status_path, status=current_status, test=test, step_id=current_step_id, step_depth=step_depth+1)
                            exit = exit or result['exit']
                            tests_skipped += result['tests']['skipped']
                            tests_run += result['tests']['run']
                            tests_failed += result['tests']['failed']
                            break
                
                elif step_type == 'foreach':
                    for file_or_dir in Common.list_files(current_input_path):
                        result = step['pipeline'].run(config_path, file_or_dir, current_output_path+'/'+os.path.basename(file_or_dir), current_status_path, status=current_status, test=test, step_id=current_step_id, step_depth=step_depth+1)
                        exit = exit or result['exit']
                        tests_skipped += result['tests']['skipped']
                        tests_run += result['tests']['run']
                        tests_failed += result['tests']['failed']
                
                elif step_type == 'unfold':
                    prev_paths = []
#.........这里部分代码省略.........
开发者ID:josteinaj,项目名称:docker-pipeline,代码行数:103,代码来源:pipeline.py

示例4: __init__

# 需要导入模块: from common import Common [as 别名]
# 或者: from common.Common import message [as 别名]
 def __init__(self, path, host_path, pipeline=None, start_location=None):
     self.path = path
     self.host_path = host_path
     if pipeline:
         self.pipeline = pipeline
     else:
         Common.message("host_path: "+host_path)
         self.pipeline = Common.load_yaml(path)
     if start_location:
         self.location = start_location
     elif '__location__' in self.pipeline:
         self.location = self.pipeline['__location__']
     else:
         os.path.basename(self.path)+":1"
     self.steps = []
     self.tests = {}
     for step in self.pipeline['pipeline']:
         if isinstance(step, str):
             if step == "exit":
                 self.steps.append({ 'exit': { 'location': self.location.split(':',1)[0] }})
             else:
                 Common.message("WARNING: unknown instruction found: '"+step+"' (skipping!)")
             continue
         
         step_line = [key for key in list(step.keys()) if not key.startswith('_')]
         step_line = None if len(step_line) == 0 else step_line[0]
         
         if 'image' in step:
             image = { 'location': str(step['__location__']), 'name': step['image'], 'id': step['image'] }
             if 'command' in step:
                 image['command'] = step['command']
             self.steps.append({ 'image': image })
         
         elif 'dockerfile' in step:
             image_id = Common.docker_build(os.path.dirname(path)+"/"+step['dockerfile']+"/")
             image = { 'location': str(step['__location__']), 'name': step['dockerfile'], 'id': image_id }
             if 'command' in step:
                 image['command'] = step['command']
             self.steps.append({ 'image': image })
             
         elif 'unfold' in step:
             self.steps.append({'unfold':{'location': str(step['__location__']), 'name':'unfold', 'depth':step['unfold']}})
         
         elif 'test' in step:
             test_input = '*' if not 'input' in step['test'] else step['test']['input']
             test = { 'location': str(step['__location__']), 'name': test_input }
             for key in ['input', 'expect', 'status', 'focus', 'context']:
                 if key in step['test']:
                     test[key] = step['test'][key]
             
             if not test_input in self.tests:
                 self.tests[test_input] = {}
             self.tests[test_input][str(len(self.steps))] = test
             self.steps.append({ 'test': test })
         
         elif 'assert' in step:
             assertion = { 'test': { 'location': str(step['__location__']), 'name': '*', 'input': '*', 'status': step['assert'] if not step['assert'] == None else "" }}
             if not '*' in self.tests:
                 self.tests['*'] = {}
             self.tests['*'][str(len(self.steps))] = assertion['test']
             self.steps.append(assertion)
         
         elif step_line.startswith('if'):
             test = step_line[2:].split(":",1)[0].strip()
             subpipeline_name = 'pipeline' if not 'name' in self.pipeline['pipeline'] else self.pipeline['pipeline']['name']
             subpipeline_if = Pipeline(
                                        self.path,
                                        self.host_path,
                                        pipeline={
                                            'name': subpipeline_name,
                                            'pipeline': step[step_line]
                                        },
                                        start_location=step['__location__']
                                    )
             subpipeline_else = Pipeline(
                                        self.path,
                                        self.host_path,
                                        pipeline={
                                            'name': subpipeline_name,
                                            'pipeline': []
                                        },
                                        start_location=step['__location__']
                                    )
             for test_input in subpipeline_if.tests:
                 if not test_input in self.tests:
                     self.tests[test_input] = {}
                 for subtest_id in subpipeline_if.tests[test_input]:
                     self.tests[test_input][str(len(self.steps))+'.'+subtest_id] = subpipeline_if.tests[test_input][subtest_id]
             self.steps.append({ 'choose':
                                 { 'location': str(step['__location__']),
                                   'choices': [
                                     { 'when': {
                                         'location': str(step['__location__']),
                                         'test': test,
                                         'pipeline': subpipeline_if
                                     }},
                                     { 'otherwise': {
                                         'location': str(step['__location__']),
                                         'pipeline': subpipeline_else
                                     }}
#.........这里部分代码省略.........
开发者ID:josteinaj,项目名称:docker-pipeline,代码行数:103,代码来源:pipeline.py


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