Ejemplo n.º 1
0
def grab(args):
    
    valid_switches = ['-c']
    curl_links = {}
    zips = {}

    # check we have args 
    
    if len(args['args']) < 1:
        error_object = []
        error_object.append('No resource specified')
        raise yoda_kill(error_object)
    
    else: # check resources
        check_resources(args['args'])
        
        # get the curl links
        for resource in args['args']:
            curl_links[resource] = resources.return_resource(resource)
        # get name of each zip
        for key, value in curl_links.iteritems():
            zips[key] = os.path.basename(value)
    
    # check if a switch was passed
    if args['switch']:
        # check if switch is valid
        if args['switch'] in valid_switches:
            print 'running code with switch: ' + args['switch']
            curl_resource(curl_links)
            yoda_unzip(zips)
            run_config(args['args'])
        
        else: # invalid switch given
            error_object = []
            error_object.append('Invalid switch specifed: ' + args['switch'])
            raise yoda_kill(error_object)
    # no switch passed
    else:
        print 'running without switch'
        curl_resource(curl_links)
        yoda_unzip(zips)
Ejemplo n.º 2
0
def run_config(args):
    config_script = configs.return_config(args)
    if config_script != False:
        #build path to configs
        path = os.path.dirname(os.path.realpath(__file__))
        path += '/configs/'
        path += config_script
        config_exec = subprocess.Popen(['python', path])
        config_exec.wait()
    else:
        error_object = []
        error_object.append('invalid config:')
        error_object.append(args)
        raise yoda_kill(error_object)
Ejemplo n.º 3
0
def init():
    # format args
    env = { 'args' : [], 'cmd' : False, 'switch' : False}
    sys.argv.pop(0) # we dont need path
    if len(sys.argv) < 1:
        error_object = []
        error_object.append('No arguments provided. See yoda help for cmd format')
        raise yoda_kill(error_object)

    # check if cmd is valid
    if sys.argv[0] in valid_commands:
        env['cmd'] = sys.argv[0]
        
        # check if we have a switch
        if len(sys.argv) > 1:
            if re.match('^-', sys.argv[1]):
                env['switch'] = sys.argv[1]
                # store remaning args if present and return env
                if len(sys.argv) > 2:
                    for i in range(2, len(sys.argv)):
                        env['args'].append(sys.argv[i])
                    return env
                else:
                    return env
            else: # no switch present
                for i in range(1, len(sys.argv)):
                    env['args'].append(sys.argv[i])
                return env
        else: # no switch or args to cmd
            return env
    
    else:
        error_object = []
        error_object.append('Invalid command specified: ' + sys.argv[0])
        error_object.append('Valid commands are: ')
        error_object.append(valid_commands)
        raise yoda_kill(error_object)
Ejemplo n.º 4
0
def check_resources(args):
        invalid_resources = [] 
        valid_resources = 0
        for resource in args:
            valid_resource = resources.return_resource(resource)
            if valid_resource:
                valid_resources += 1
            else:
                invalid_resources.append(resource)
        if valid_resources != len(args):
            error_object = []
            error_object.append('Invalid resources specified:')
            error_object.append(invalid_resources)
            error_object.append('Please see yoda resources for available resources')
            raise yoda_kill(error_object)
        else: # we have valid resources
            return True
Ejemplo n.º 5
0

if os.path.exists(bootstrap_css) and os.path.exists(cakephp_css):
    print 'moving twitter bootstrap css assets to cake css folder'
    dir_contents = os.listdir(bootstrap_css)
    for file in dir_contents:
        shutil.move(bootstrap_css + file, cakephp_css)
    print 'css assets moved'
    successfully_moved += 1
else:
    error_object = []
    error.object.append('Unable to move bootstrap css assets due to missing path')
    error.object.append('Verify the following paths exist in yodapaths.py: ')
    error_object.append(bootstrap_css)
    error_object.append(cakephp_css)
    raise yoda_kill(error_object)

if os.path.exists(bootstrap_js) and os.path.exists(cakephp_js):
    print 'moving twitter bootstrap javascript assets to cake js folder'
    dir_contents = os.listdir(bootstrap_js)
    for file in dir_contents:
        shutil.move(bootstrap_js + file, cakephp_js)
    print 'javascript assets moved'
    successfully_moved += 1
else:
    error_object = []
    error.object.append('Unable to move bootstrap js assets due to missing path')
    error.object.append('Verify the following paths exist in yodapaths.py: ')
    error_object.append(bootstrap_js)
    error_object.append(cakephp_js)
    raise yoda_kill(error_object)