Beispiel #1
0
    def execute(self, pool):
        
        # Test if git local repo exists
        if not os.path.isdir(os.path.join(os.getcwdu(), DevToolsConfigFile.Path)):
            prompt.error(DevToolsMessage.GitRepoNotExist.format(''))
            return

        error = False
        current_path = os.getcwdu()        
        try:
            log.info(u'Running Dev Tools initialization script.')
            if misc.is_os_windows():
                path = shell_utils.climb_dir_tree(shell_utils.ori_path(), OSSpecific.WindowsClimbUpDepth)
                #TODO: replace current workaround for WindowsModuleScript
                current_path = os.getcwdu()
                script_path = os.path.join(path, OSSpecific.WindowsModuleScriptPath)
                log.debug(u'Changing path to {0}.'.format(script_path))
                os.chdir(script_path)

                log.info(u'Running script "{0}".'.format(OSSpecific.WindowsModuleScriptName))
                shell_utils.call([OSSpecific.WindowsModuleScriptName])
                
                log.debug(u'Changing path to {0}.'.format(current_path))
                os.chdir(current_path)
                
                log.info(u'Running script "{0}".'.format(OSSpecific.WindowsRepoScript))
                fullpath = os.path.join(path, OSSpecific.WindowsRepoScript)
                prompt.error(shell_utils.call([fullpath]))
            else:
                path = shell_utils.climb_dir_tree(shell_utils.ori_path(), OSSpecific.LinuxClimbUpDepth)
                log.info(u'Running script "{0}" at {1}.'.format(OSSpecific.LinuxRepoScript,
                                                                path))
                fullpath = os.path.join(path, OSSpecific.LinuxRepoScript)
                prompt.error(shell_utils.call([fullpath]))
            
            location = DevToolsConfigFile.Path + os.path.sep + DevToolsConfigFile.Name        
            config_file.set_access_permission(location, True)

        except subprocess.CalledProcessError as ex:
            # Git returned with an error code
            log.error(u'Dev Tools initialization script report an error, because "{0}".'.format(ex))
            error = True
            prompt.error(DevToolsMessage.InitError.format(ex.message))
        
        except (OSError, IOError) as ex:
            log.error(u'Failed to call Dev Tools initialization script, because "{0}".'.format(ex))
            # Cannot find or run script
            error = True
            if ex.errno == FileErrorConstant.FileNotFoundErrorCode:
                if fullpath:
                    prompt.error(DevToolsMessage.FileMissingError.format(fullpath))
                else:
                    prompt.error(ex)

        finally:
            if error:            
                prompt.error(DevToolsMessage.ExecutionError.format(DevToolsConfigFile.InitHelpUrl))
        
        ret_result = OperationResult(self, None, None, None)
        return ret_result
    def execute(self, pool):

        # Test if git local repo exists
        if not os.path.isdir(os.path.join(os.getcwd(),
                                          DevToolsConfigFile.Path)):
            prompt.error(DevToolsMessage.GitRepoNotExist)
            #            raise EBSCliException()
            return

        try:
            self.run_dev_tools_script()

            location = DevToolsConfigFile.Path + os.path.sep + DevToolsConfigFile.Name
            config_file.set_access_permission(location, True)

        except (OSError, IOError, subprocess.CalledProcessError) as ex:
            log.error(
                "Encountered error when updating AWS Dev Tools settings: {0}.".
                format(ex))
            message = DevToolsMessage.ExecutionError.format(
                DevToolsConfigFile.InitHelpUrl)
            prompt.error(message)


#            raise EBSCliException()

        ret_result = OperationResult(self, None, None, None)
        return ret_result
 def execute(self, parameter_pool):
     create_eb_local_dir()
     
     location = EbLocalDir.Path + os.path.sep + EbConfigFile.Name
     
     config_file.save_eb_config_file(location, parameter_pool, False)
     config_file.set_access_permission(location)
     
     ret_result = OperationResult(self, None, None, None)
     return ret_result
Beispiel #4
0
 def execute(self, parameter_pool):
     create_eb_local_dir()
     
     location = EbLocalDir.Path + os.path.sep + EbConfigFile.Name
     
     config_file.save_eb_config_file(location, parameter_pool, False)
     config_file.set_access_permission(location)
     
     ret_result = OperationResult(self, None, None, None)
     return ret_result
Beispiel #5
0
def configureLogging(level=None,
                     quiet=False,
                     filename=EbLogFile.Name,
                     spec_dir=os.getcwd() + os.path.sep + EbLocalDir.Path):

    if not spec_dir:
        output_file = _getLogFile(filename)
    else:
        config_file.create_directory(spec_dir)
        output_file = spec_dir + os.path.sep + filename

    ori_path = shell_utils.ori_path()
    log_config_location = os.path.join(ori_path, 'logconfig.json')

    try:
        with codecs.open(log_config_location, 'r',
                         encoding='utf-8') as input_file:
            config_dict = json.loads(input_file.read())

        _set_log_filename(config_dict, output_file)

        if level is None and config_dict['root']['level'].upper() == 'NONE':
            # completely disable log
            config_dict['root']['level'] = 'NOTSET'
            _disable_logging(config_dict)
        else:
            if level is not None:
                config_dict['root']['level'] = level
            _set_log_handlers(config_dict, 'default')

    except (IOError, ValueError, KeyError) as ex:
        #JSON logging config file parsing error
        if not quiet:
            print(('Encountered error when reading logging configuration file from "{0}": {1}.'.\
                  format(log_config_location, ex)))
        _disable_logging()
        return

    try:
        _config.dictConfig(config_dict)

    except IOError:
        if not quiet:
            print('Could not open {0} for logging.  Using stderr instead.'.\
                format(output_file), file=sys.stderr)
        _set_log_handlers(config_dict, 'to_stderr')
        _config.dictConfig(config_dict)

    config_file.set_access_permission(output_file, True)
def configureLogging(level = None, quiet = False, 
                     filename = EbLogFile.Name, 
                     spec_dir = os.getcwdu() + os.path.sep + EbLocalDir.Path):
    
    
    if not spec_dir:
        output_file=_getLogFile(filename)
    else:
        shell_utils.create_directory(spec_dir)
        output_file = spec_dir + os.path.sep + filename
        
    ori_path = shell_utils.ori_path()
    log_config_location = os.path.join(ori_path, u'logconfig.json')
    
    try:
        with codecs.open(log_config_location, 'r', encoding='utf-8') as input_file:        
            config_dict = json.loads(input_file.read())

        _set_log_filename(config_dict, output_file)
        
        if level is None and config_dict[u'root'][u'level'].upper() == u'NONE':
            # completely disable log
            config_dict[u'root'][u'level'] = u'NOTSET'
            _disable_logging(config_dict)
        else:
            if level is not None:
                config_dict[u'root'][u'level'] = level        
            _set_log_handlers(config_dict, u'default')
            
    except (IOError, ValueError, KeyError) as ex:
        #JSON logging config file parsing error
        if not quiet:
            print(u'Encountered error when reading logging configuration file from "{0}": {1}.'.\
                  format(log_config_location, ex))
        _disable_logging()
        return    

    try: 
        _config.dictConfig(config_dict)
                            
    except IOError:
        if not quiet:
            print >> sys.stderr, u'Could not open {0} for logging.  Using stderr instead.'.\
                format(output_file)
        _set_log_handlers(config_dict, u'to_stderr')
        _config.dictConfig(config_dict)

    config_file.set_access_permission(output_file, True)    
    def execute(self, pool):

        # Test if git local repo exists
        if not os.path.isdir(os.path.join(os.getcwd(),
                                          DevToolsConfigFile.Path)):
            prompt.error(
                DevToolsMessage.GitRepoNotExist.format(
                    CommandType.INIT.lower()))
            #            raise EBSCliException()
            return

        region_id = ServiceRegionId[pool.get_value(ParameterName.Region)]
        try:
            self.run_dev_tools_script()

            self._call(DevToolsConfigFile.SetAccessKey,
                       pool.get_value(ParameterName.AwsAccessKeyId))
            self._call(DevToolsConfigFile.SetSecretKey,
                       pool.get_value(ParameterName.AwsSecretAccessKey))
            self._call(DevToolsConfigFile.SetRegion, region_id)
            self._call(DevToolsConfigFile.SetServicePoint,
                       DevToolsConfigFile.Endpoint.format(region_id))
            self._call(DevToolsConfigFile.SetApplicationName,
                       pool.get_value(ParameterName.ApplicationName))
            self._call(DevToolsConfigFile.SetEnvironmentName,
                       pool.get_value(ParameterName.EnvironmentName))

            location = DevToolsConfigFile.Path + os.path.sep + DevToolsConfigFile.Name
            config_file.set_access_permission(location, True)

        except (OSError, IOError, _subprocess.CalledProcessError) as ex:
            log.error(
                "Encountered error when updating AWS Dev Tools settings: {0}.".
                format(ex))
            message = DevToolsMessage.ExecutionError.format(
                DevToolsConfigFile.InitHelpUrl)
            prompt.error(message)


#            raise EBSCliException()

        ret_result = OperationResult(self, None, None, None)
        return ret_result
    def execute(self, pool):
        
        # Test if git local repo exists
        if not os.path.isdir(os.path.join(os.getcwd(), DevToolsConfigFile.Path)):
            prompt.error(DevToolsMessage.GitRepoNotExist)
#            raise EBSCliException()
            return
        
        try:
            self.run_dev_tools_script()
            
            location = DevToolsConfigFile.Path + os.path.sep + DevToolsConfigFile.Name        
            config_file.set_access_permission(location, True)
            
        except (OSError, IOError, subprocess.CalledProcessError) as ex:
            log.error("Encountered error when updating AWS Dev Tools settings: {0}.".format(ex))
            message = DevToolsMessage.ExecutionError.format(DevToolsConfigFile.InitHelpUrl)
            prompt.error(message)
#            raise EBSCliException()
        
        ret_result = OperationResult(self, None, None, None)
        return ret_result
    def execute(self, pool):
        
        # Test if git local repo exists
        if not os.path.isdir(os.path.join(os.getcwd(), DevToolsConfigFile.Path)):
            prompt.error(DevToolsMessage.GitRepoNotExist.format(CommandType.INIT.lower()))
#            raise EBSCliException()
            return
        
        region_id = ServiceRegionId[pool.get_value(ParameterName.Region)]
        try:
            self.run_dev_tools_script()
            
            self._call(DevToolsConfigFile.SetAccessKey, 
                       pool.get_value(ParameterName.AwsAccessKeyId))
            self._call(DevToolsConfigFile.SetSecretKey, 
                       pool.get_value(ParameterName.AwsSecretAccessKey))
            self._call(DevToolsConfigFile.SetRegion, 
                       region_id)
            self._call(DevToolsConfigFile.SetServicePoint, 
                       DevToolsConfigFile.Endpoint.format(region_id))
            self._call(DevToolsConfigFile.SetApplicationName, 
                       pool.get_value(ParameterName.ApplicationName))
            self._call(DevToolsConfigFile.SetEnvironmentName, 
                       pool.get_value(ParameterName.EnvironmentName))
            
            location = DevToolsConfigFile.Path + os.path.sep + DevToolsConfigFile.Name        
            config_file.set_access_permission(location, True)
            
        except (OSError, IOError, _subprocess.CalledProcessError) as ex:
            log.error("Encountered error when updating AWS Dev Tools settings: {0}.".format(ex))
            message = DevToolsMessage.ExecutionError.format(DevToolsConfigFile.InitHelpUrl)
            prompt.error(message)
#            raise EBSCliException()
        
        ret_result = OperationResult(self, None, None, None)
        return ret_result
    def execute(self, parameter_pool):
        current_branch, _ = shell_utils.get_working_branch(False)
        parameter_pool.put(Parameter(ParameterName.CurrentBranch,
                                     current_branch,
                                     ParameterSource.ConfigFile))
        if current_branch:
            log.info(u'Current working branch is "{0}".'.format(current_branch))
            branch_pool = _copy.deepcopy(parameter_pool)
            
            # Fill branch environment parameter values
            branches = parameter_pool.get_value(ParameterName.Branches)
            for key in EbConfigFile.BranchSectionKeys | EbConfigFile.BranchSectionHiddenKeys:
                if branches and current_branch in branches.keys() \
                    and key in branches[current_branch].keys():
                    # Copy parameter if current branch has corresponding setting
                    branch_pool.put(Parameter(key,
                                                 branches[current_branch][key],
                                                 ParameterSource.ConfigFile))
                else:
                    # TODO: we will leave following parameter if not presents in branch, since
                    # we are not asking for them for now but they are required in terminal
                    if not key in (ParameterName.ApplicationName,
                                   ParameterName.Region,
                                   ParameterName.ServiceEndpoint,
                                   ParameterName.DevToolsEndpoint):  
                        branch_pool.remove(key)
            branch_pool.put(Parameter(ParameterName.DefaultEnvironmentName,
                                      parameter_pool.get_value(ParameterName.EnvironmentName, False),
                                      ParameterSource.ConfigFile))

            
            # Call terminal
            copy = BeanstalkTerminal.ask_branch(branch_pool)
            
            # Create mapping and branch-environment section
            if branches is None:
                parameter_pool.put(Parameter(ParameterName.Branches,
                                             dict(),
                                             ParameterSource.Terminal))
            branches = parameter_pool.get_value(ParameterName.Branches, False)
            branches[current_branch] = dict()
            source = ParameterSource.ConfigFile
            for key in EbConfigFile.BranchSectionKeys | EbConfigFile.BranchSectionHiddenKeys:
                if branch_pool.has(key):
                    branches[current_branch][key] = branch_pool.get_value(key, False)
                    if ParameterSource.is_ahead(branch_pool.get_source(key), source):
                        source = branch_pool.get_source(key)
                else:
                    # Copy parameter if not exists in branch
                    if parameter_pool.has(key): 
                        branches[current_branch][key] = parameter_pool.get_value(key, False)
            parameter_pool.update(ParameterName.Branches, source=source)
            
            # Copy over optionsetting file
            if copy:
                default_option_file = parameter_pool.get_value(ParameterName.OptionSettingFile, False)
                branch_option_file = branches[current_branch][ParameterName.OptionSettingFile]
                log.debug(u'Copying optionsettings file from {0} to {1}.'.format(default_option_file,
                                                                         branch_option_file))
                shell_utils.copy_file(default_option_file, branch_option_file, True)
                config_file.set_access_permission(branch_option_file, True)

            # Fill [branch] section
            if parameter_pool.get_value(ParameterName.BranchMapping) is None:
                parameter_pool.put(Parameter(ParameterName.BranchMapping,
                                             dict(),
                                             ParameterSource.Terminal))
            branch_mapping = parameter_pool.get_value(ParameterName.BranchMapping, False)
            branch_mapping[current_branch] = branch_pool.get_value(ParameterName.EnvironmentName, False)
            
        else:
            # local repository does not have branch committed yet.
            msg = TerminalMessage.NoBranchToRegister
            log.error(msg)
            prompt.error(msg)      
    def execute(self, parameter_pool):
        current_branch, _ = shell_utils.get_working_branch(False)
        parameter_pool.put(
            Parameter(ParameterName.CurrentBranch, current_branch,
                      ParameterSource.ConfigFile))
        if current_branch:
            log.info('Current working branch is "{0}".'.format(current_branch))
            branch_pool = _copy.deepcopy(parameter_pool)

            # Fill branch environment parameter values
            branches = parameter_pool.get_value(ParameterName.Branches)\
                if parameter_pool.has(ParameterName.Branches) else None
            for key in EbConfigFile.BranchSectionKeys | EbConfigFile.BranchSectionHiddenKeys:
                if branches and current_branch in list(branches.keys()) \
                    and key in list(branches[current_branch].keys()):
                    # Copy parameter if current branch has corresponding setting
                    branch_pool.put(
                        Parameter(key, branches[current_branch][key],
                                  ParameterSource.ConfigFile))
                else:
                    # TODO: we will leave following parameter if not presents in branch, since
                    # we are not asking for them for now but they are required in terminal
                    if not key in (ParameterName.ApplicationName,
                                   ParameterName.Region,
                                   ParameterName.ServiceEndpoint,
                                   ParameterName.DevToolsEndpoint):
                        branch_pool.remove(key)
            branch_pool.put(
                Parameter(
                    ParameterName.DefaultEnvironmentName,
                    parameter_pool.get_value(ParameterName.EnvironmentName),
                    ParameterSource.ConfigFile))

            # Call terminal
            copy = BeanstalkTerminal.ask_branch(branch_pool)

            # Create mapping and branch-environment section
            if branches is None:
                parameter_pool.put(
                    Parameter(ParameterName.Branches, dict(),
                              ParameterSource.Terminal))
            branches = parameter_pool.get_value(ParameterName.Branches)
            branches[current_branch] = dict()
            source = ParameterSource.ConfigFile
            for key in EbConfigFile.BranchSectionKeys | EbConfigFile.BranchSectionHiddenKeys:
                if branch_pool.has(key):
                    branches[current_branch][key] = branch_pool.get_value(key)
                    if ParameterSource.is_ahead(branch_pool.get_source(key),
                                                source):
                        source = branch_pool.get_source(key)
                else:
                    # Copy parameter if not exists in branch
                    if parameter_pool.has(key):
                        branches[current_branch][
                            key] = parameter_pool.get_value(key)
            parameter_pool.update(ParameterName.Branches, source=source)

            # Copy over optionsetting file
            if copy:
                default_option_file = parameter_pool.get_value(
                    ParameterName.OptionSettingFile)
                branch_option_file = branches[current_branch][
                    ParameterName.OptionSettingFile]
                log.debug('Copying config file from {0} to {1}.'.format(
                    default_option_file, branch_option_file))
                shell_utils.copy_file(default_option_file, branch_option_file,
                                      True)
                config_file.set_access_permission(branch_option_file, True)

            # Fill [branch] section
            if not parameter_pool.has(ParameterName.BranchMapping)\
                or parameter_pool.get_value(ParameterName.BranchMapping) is None:
                parameter_pool.put(
                    Parameter(ParameterName.BranchMapping, dict(),
                              ParameterSource.Terminal))
            branch_mapping = parameter_pool.get_value(
                ParameterName.BranchMapping)
            branch_mapping[current_branch] = branch_pool.get_value(
                ParameterName.EnvironmentName)

        else:
            # local repository does not have branch committed yet.
            msg = TerminalMessage.NoBranchToRegister
            log.error(msg)
            prompt.error(msg)