コード例 #1
0
class Advanced(object):
    
    def __init__(self, debug=False):
        '''
        initializes the advanced class for awscm
        
        :param debug: enables debug information to be printed
        '''
        
        self.debug = debug
        self.run = Run(debug=debug)
        self.result_dir = {}
        self.final_result = ''
        
    
    def a(self):
        '''
        define the a function
        
        :return: the string based script
        '''
        
        return '#!/bin/bash\n echo "a-Monday$(date)"'
    
    def b(self):
        '''
        define the b function
        
        :return: the string based script
        '''
        
        return '#!/bin/bash\n echo "b-Tuesday($USER)"'
    
    def c(self):
        '''
        define the c function
        
        :return: the string based script
        '''
        
        return '#!/bin/bash\n echo "c-Wednesday($PWD)"'
    
    def d(self):
        '''
        define the d function
        
        :return: the string based script
        '''
        
        return '#!/bin/bash\n echo "d-Thursday(Yu)"'
    
    def function_identifier(self, name):
        '''
        identify the char
        
        :param name: the char of the function we want to run
        :return: the string based script
        '''
        
        if name == 'a':
            return self.a()
        elif name == 'b':
            return self.b()
        elif name == 'c':
            return self.c()
        else:
            return self.d()
    
    
    def parall(self, par):
        ''''
        run the task parallelly
        
        :param par: the scripts
        '''
        
        scripts = ''   
        for i in par:
            scripts+=self.function_identifier(i)+','
        
        sub_result = self.run.run_local_or_remote(scripts[:-1], True)

        for i in range(len(par)):
            temp = sub_result[i].split(':')[2]
            index = temp.index('-')
            self.result_dir.update({temp[index-1]:temp})
        
        
        
    def sequential(self, work):
        '''
        run the sequential tasks
        
        :param work: the tasks
        '''
        
        for i in work:
            if '|' in i:
                par = i.split('|')
                self.parall(par)
            elif '+' in i:
                add = i.split('+')
                self.add(add)
            else:
                self.item(i)
                    
            
    def add(self, add_list):
        '''
        add the reuslts into one
        
        :param add_list: add the results
        '''
        
        for i in add_list:
            
            self.final_result+=self.result_dir[i]
        
    def item(self, job):
        '''
        run one task
        
        :param job: one task
        '''
        
        script=self.function_identifier(job)
        sub_result = self.run.run_local_or_remote(script, True)
        temp = sub_result[0].split(':')[2]
        index = temp.index('-')
        self.result_dir.update({temp[index-1]:temp})
        

    
    def formula(self, string):
        '''
        parse the formulation
        
        :param string: the string formulation
        '''
        
        work = string.split(';')
        self.sequential(work)
        print('Running formula: '+string+', and the result is:')
        print(self.final_result)
            
        
        
        
            
            
        
            
        
        
コード例 #2
0
ファイル: awscm.py プロジェクト: swsachith/cm
def process_arguments(arg):
    """
    Processes all the input arguments and acts relative processes.

    :param arg: input arguments for the awscm.
    """
    debug = arg.get('--debug')
    resource = Resource(debug=debug)
    config = Config(debug=debug)
    run = Run(debug=debug)
    advanced = Advanced(debug=debug)

    config.config()
    utility = Utility(debug=debug)
    regular_file = config.get_config()

    if arg.get('add') & arg.get('resource'):
        resource.add(regular_file, arg.get('<yaml_file>'))

    if arg.get('list') & arg.get('resource'):
        print(yaml.dump(regular_file))

    if arg.get('remove') & arg.get('resource'):
        resource.remove(regular_file, arg.get('<label_name>'))

    if arg.get('view') & arg.get('resource'):
        print(
            yaml.dump(
                resource.review(arg.get('<label_name>'), config.get_cloud(),
                                config.get_cluster(), config.get_default())))

    if arg.get('copy') & arg.get('file'):
        output = utility.copy_file(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<file>'), arg.get('<where>'))
        print(output)

    if arg.get('copy') & arg.get('folder'):
        output = utility.copy_folder(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<folder>'), arg.get('<where>'))
        print(output)

    if arg.get('list') & arg.get('instance'):
        output = utility.dir_list(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<file>'), arg.get('<where>'))
        print(output)

    if arg.get('delete') & arg.get('file'):
        output = utility.delete_file(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<file>'), arg.get('<where>'))
        print(output)

    if arg.get('delete') & arg.get('folder'):
        output = utility.delete_folder(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<folder>'), arg.get('<where>'))
        print(output)

    if arg.get('create') & arg.get('folder'):
        output = utility.create_folder(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<folder>'), arg.get('<where>'))
        print(output)

    if arg.get('read') & arg.get('file'):
        output = utility.read_file(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<file>'), arg.get('<where>'))
        print(output)

    if arg.get('download') & arg.get('file'):
        output = utility.download_file(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<file>'), arg.get('<where>'), arg.get('<local>'))
        print(output)

    if arg.get('download') & arg.get('folder'):
        output = utility.download_folder(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<folder>'), arg.get('<where>'), arg.get('<local>'))
        print(output)

    if arg.get('check') & arg.get('process_name'):
        output = utility.check_process(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<process>'))
        print(output)

    if arg.get('run') & arg.get('instance') & arg.get('local'):
        output = run.run_instance_local(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<scripts>'))
        for i in output:
            print(i)

    elif arg.get('run') & arg.get('local'):
        output = run.run_local_or_remote(arg.get('<scripts>'), True)
        for i in output:
            print(i)

    if arg.get('run') & arg.get('instance') & arg.get('remote'):
        output = run.run_instance_remote(
            resource.review(arg.get('<label_name>'), config.get_cloud(),
                            config.get_cluster(), config.get_default()),
            arg.get('<scripts>'))
        for i in output:
            print(i)

    elif arg.get('run') & arg.get('remote'):
        output = run.run_local_or_remote(arg.get('<scripts>'), False)
        for i in output:
            print(i)

    if arg.get('run') & arg.get('advanced'):
        advanced.formula(arg.get('<string>'))