class ATSLoggingTestCase(unittest.TestCase):
    '''
        Defined class ATSLoggingTestCase with attribute(s) and method(s).
        Created test cases for checking functionalities of ATSLogger.
        It defines:

            :attributes:
                | LOG_FILE - log file path.
                | tool_name - tool name.
                | log_file - tool log file path.
                | logger_ats - API for ATS logger.
            :methods:
                | setUp - call before test case.
                | tearDown - call after test case.
                | test_debug - test debug log.
                | test_warning - test warning log.
                | test_critical - test critical log.
                | test_error - test error log.
                | test_info - test info log.
    '''

    LOG_FILE = '/log/simple_tool.log'

    def setUp(self):
        '''Call before test case.'''
        self.log_file = '{0}{1}'.format(
            dirname(__file__), ATSLoggingTestCase.LOG_FILE
        )
        self.tool_name = 'simple_test'
        self.logger_ats = ATSLogger(
            self.tool_name, self.log_file, verbose=False
        )

    def tearDown(self):
        '''Call after test case.'''
        self.logger_ats = None
        self.log_file = None
        self.tool_name = None

    def test_debug(self):
        '''Test ATS debug log.'''
        self.logger_ats.write_log('simple debug', ATSLogger.ATS_DEBUG)

    def test_warning(self):
        '''Test ATS warning log.'''
        self.logger_ats.write_log('simple warning', ATSLogger.ATS_WARNING)

    def test_critical(self):
        '''Test ATS critical log.'''
        self.logger_ats.write_log('simple critical', ATSLogger.ATS_CRITICAL)

    def test_error(self):
        '''Test ATS error log.'''
        self.logger_ats.write_log('simple error', ATSLogger.ATS_ERROR)

    def test_info(self):
        '''Test ATS info log.'''
        self.logger_ats.write_log('simple info', ATSLogger.ATS_INFO)
Esempio n. 2
0
class GenSTM32(CfgCLI):
    '''
        Defined class GenSTM32 with attribute(s) and method(s).
        Load a base info, create an CLI interface and run operation(s).
        It defines:

            :attributes:
                | GEN_VERBOSE - console text indicator for process-phase.
                | CONFIG - configuration file path.
                | LOG - tool log file path.
                | OPS - list of tool options.
                | logger - logger object API.
            :methods:
                | __init__ - initial constructor.
                | process - process and run tool option(s).
                | __str__ - dunder method for GenSTM32.
    '''

    GEN_VERBOSE = 'GEN_STM32'
    CONFIG = '/conf/gen_stm32.cfg'
    LOG = '/log/gen_stm32.log'
    OPS = ['-g', '--gen', '-v', '--verbose', '--version']

    def __init__(self, verbose=False):
        '''
            Initial constructor.

            :param verbose: enable/disable verbose option.
            :type verbose: <bool>
            :exceptions: None
        '''
        current_dir = Path(__file__).resolve().parent
        base_info = '{0}{1}'.format(current_dir, GenSTM32.CONFIG)
        CfgCLI.__init__(self, base_info, verbose=verbose)
        verbose_message(GenSTM32.GEN_VERBOSE, verbose, 'init tool info')
        self.logger = ATSLogger(GenSTM32.GEN_VERBOSE.lower(),
                                '{0}{1}'.format(current_dir, GenSTM32.LOG),
                                verbose=verbose)
        if self.tool_operational:
            self.add_new_option(GenSTM32.OPS[0],
                                GenSTM32.OPS[1],
                                dest='gen',
                                help='generate project')
            self.add_new_option(GenSTM32.OPS[2],
                                GenSTM32.OPS[3],
                                action='store_true',
                                default=False,
                                help='activate verbose mode for generation')
            self.add_new_option(GenSTM32.OPS[4],
                                action='version',
                                version=__version__)

    def process(self, verbose=False):
        '''
            Process and run operation.

            :param verbose: enable/disable verbose option.
            :type verbose: <bool>
            :return: boolean status, True (success) | False.
            :rtype: <bool>
            :exceptions: None
        '''
        status = False
        if self.tool_operational:
            num_of_args_sys = len(sys.argv)
            if num_of_args_sys > 1:
                operation = sys.argv[1]
                if operation not in GenSTM32.OPS:
                    sys.argv.append('-h')
            else:
                sys.argv.append('-h')
            args = self.parse_args(sys.argv[1:])
            pro_exists = exists(getattr(args, 'gen'))
            if not pro_exists:
                if bool(getattr(args, 'gen')):
                    print('{0} {1} [{2}]'.format(
                        '[{0}]'.format(GenSTM32.GEN_VERBOSE.lower()),
                        'generating project', getattr(args, 'gen')))
                    generator = STM32Setup(
                        verbose=getattr(args, 'verbose') or verbose)
                    status = generator.gen_pro_setup(
                        '{0}'.format(getattr(args, 'gen')),
                        verbose=getattr(args, 'verbose') or verbose)
                    if status:
                        success_message(GenSTM32.GEN_VERBOSE, 'done\n')
                        self.logger.write_log(
                            '{0} {1} done'.format('generating project',
                                                  getattr(args, 'gen')),
                            ATSLogger.ATS_INFO)
                    else:
                        error_message(GenSTM32.GEN_VERBOSE,
                                      'generation failed')
                        self.logger.write_log('generation failed',
                                              ATSLogger.ATS_ERROR)
                else:
                    error_message(GenSTM32.GEN_VERBOSE, 'provide project name')
                    self.logger.write_log('provide project name',
                                          ATSLogger.ATS_ERROR)
            else:
                error_message(GenSTM32.GEN_VERBOSE, 'project already exist')
                self.logger.write_log('project already exist',
                                      ATSLogger.ATS_ERROR)
        else:
            error_message(GenSTM32.GEN_VERBOSE, 'tool is not operational')
            self.logger.write_log('tool is not operational',
                                  ATSLogger.ATS_ERROR)
        return status

    def __str__(self):
        '''
            Dunder method for GenSTM32.

            :return: object in a human-readable format.
            :rtype: <str>
            :exceptions: None
        '''
        return '{0} ({1}, {2})'.format(self.__class__.__name__,
                                       CfgCLI.__str__(self), str(self.logger))
Esempio n. 3
0
class GenPyTool(CfgCLI):
    '''
        Defined class GenPyTool with attribute(s) and method(s).
        Load a base info, create an CLI interface and run operation(s).
        It defines:

            :attributes:
                | GEN_VERBOSE - console text indicator for process-phase.
                | CONFIG - tool info file path.
                | LOG - tool log file path.
                | LOGO - logo for splash screen.
                | OPS - list of tool options.
                | logger - logger object API.
            :methods:
                | __init__ - initial constructor.
                | process - process and generate module setup.py.
                | __str__ - dunder method for GenPyTool.
    '''

    GEN_VERBOSE = 'GEN_PY_TOOL'
    CONFIG = '/conf/gen_py_tool.cfg'
    LOG = '/log/gen_py_tool.log'
    LOGO = '/conf/gen_py_tool.logo'
    OPS = ['-g', '--gen', '-v', '--verbose', '--version']

    def __init__(self, verbose=False):
        '''
            Initial constructor.

            :param verbose: enable/disable verbose option.
            :type verbose: <bool>
            :exceptions: None
        '''
        current_dir = dirname(realpath(__file__))
        gen_py_tool_property = {
            'ats_organization': 'vroncevic',
            'ats_repository': 'gen_py_tool',
            'ats_name': 'gen_py_tool',
            'ats_logo_path': '{0}{1}'.format(current_dir, GenPyTool.LOGO),
            'ats_use_github_infrastructure': True
        }
        splash = Splash(gen_py_tool_property, verbose=verbose)
        base_info = '{0}{1}'.format(current_dir, GenPyTool.CONFIG)
        CfgCLI.__init__(self, base_info, verbose=verbose)
        verbose_message(GenPyTool.GEN_VERBOSE, verbose, 'init tool info')
        self.logger = ATSLogger(GenPyTool.GEN_VERBOSE.lower(),
                                '{0}{1}'.format(current_dir, GenPyTool.LOG),
                                verbose=verbose)
        if self.tool_operational:
            self.add_new_option(GenPyTool.OPS[0],
                                GenPyTool.OPS[1],
                                dest='gen',
                                help='generate python tool/generator')
            self.add_new_option(GenPyTool.OPS[2],
                                GenPyTool.OPS[3],
                                action='store_true',
                                default=False,
                                help='activate verbose mode for generation')
            self.add_new_option(GenPyTool.OPS[4],
                                action='version',
                                version=__version__)

    def process(self, verbose=False):
        '''
            Process and run operation.

            :param verbose: enable/disable verbose option.
            :type verbose: <bool>
            :return: boolean status, True (success) | False.
            :rtype: <bool>
            :exceptions: None
        '''
        status = False
        if self.tool_operational:
            num_of_args_sys = len(sys.argv)
            if num_of_args_sys > 1:
                operation = sys.argv[1]
                if operation not in GenPyTool.OPS:
                    sys.argv.append('-h')
            else:
                sys.argv.append('-h')
            args = self.parse_args(sys.argv[1:])
            pro_exists = exists(getattr(args, 'gen'))
            if not pro_exists:
                if bool(getattr(args, 'gen')):
                    print('{0} {1} [{2}]'.format(
                        '[{0}]'.format(GenPyTool.GEN_VERBOSE.lower()),
                        'generating python tool/gen', getattr(args, 'gen')))
                    generator = GenPro(getattr(args, 'gen'),
                                       verbose=getattr(args, 'verbose')
                                       or verbose)
                    status = generator.gen_pro(
                        verbose=getattr(args, 'verbose') or verbose)
                    if status:
                        success_message(GenPyTool.GEN_VERBOSE, 'done\n')
                        self.logger.write_log(
                            '{0} {1} done'.format('generating tool/gen',
                                                  getattr(args, 'gen')),
                            ATSLogger.ATS_INFO)
                    else:
                        error_message(GenPyTool.GEN_VERBOSE,
                                      'generation failed')
                        self.logger.write_log('generation failed',
                                              ATSLogger.ATS_ERROR)
                else:
                    error_message(GenPyTool.GEN_VERBOSE,
                                  'provide tool/gen name')
                    self.logger.write_log('provide tool/gen name',
                                          ATSLogger.ATS_ERROR)
            else:
                error_message(GenPyTool.GEN_VERBOSE, 'tool/gen already exist')
                self.logger.write_log('tool/gen already exist',
                                      ATSLogger.ATS_ERROR)
        else:
            error_message(GenPyTool.GEN_VERBOSE, 'tool is not operational')
            self.logger.write_log('tool is not operational',
                                  ATSLogger.ATS_ERROR)
        return status

    def __str__(self):
        '''
            Dunder method for GenPyTool.

            :return: object in a human-readable format.
            :rtype: <str>
            :exceptions: None
        '''
        return '{0} ({1}, {2})'.format(self.__class__.__name__,
                                       CfgCLI.__str__(self), str(self.logger))
Esempio n. 4
0
class GenAVR8(CfgCLI):
    '''
        Defined class GenAVR8 with attribute(s) and method(s).
        Load a base info, create an CLI interface and run operation(s).
        It defines:

            :attributes:
                | GEN_VERBOSE - console text indicator for process-phase.
                | CONFIG - tool info file path.
                | LOG - tool log file path.
                | LOGO - logo for splash screen.
                | OPS - list of tool options.
                | logger - logger object API.
            :methods:
                | __init__ - initial constructor.
                | process - process and run tool option.
                | __str__ - dunder method for GenAVR8.
    '''

    GEN_VERBOSE = 'GEN_AVR8'
    CONFIG = '/conf/gen_avr8.cfg'
    LOG = '/log/gen_avr8.log'
    LOGO = '/conf/gen_avr8.logo'
    OPS = ['-g', '--gen', '-t', '--type', '-v', '--verbose', '--version']

    def __init__(self, verbose=False):
        '''
            Initial constructor.

            :param verbose: enable/disable verbose option.
            :type verbose: <bool>
            :exceptions: None
        '''
        current_dir = dirname(realpath(__file__))
        gen_avr8_property = {
            'ats_organization': 'vroncevic',
            'ats_repository': 'gen_avr8',
            'ats_name': 'gen_avr8',
            'ats_logo_path': '{0}{1}'.format(current_dir, GenAVR8.LOGO),
            'ats_use_github_infrastructure': True
        }
        splash = Splash(gen_avr8_property, verbose=verbose)
        base_info = '{0}{1}'.format(current_dir, GenAVR8.CONFIG)
        CfgCLI.__init__(self, base_info, verbose=verbose)
        verbose_message(GenAVR8.GEN_VERBOSE, verbose, 'init tool info')
        self.logger = ATSLogger(GenAVR8.GEN_VERBOSE.lower(),
                                '{0}{1}'.format(current_dir, GenAVR8.LOG),
                                verbose=verbose)
        if self.tool_operational:
            self.add_new_option(GenAVR8.OPS[0],
                                GenAVR8.OPS[1],
                                dest='gen',
                                help='generate AVR8 project skeleton')
            self.add_new_option(GenAVR8.OPS[2],
                                GenAVR8.OPS[3],
                                dest='type',
                                help='set app/lib type of project')
            self.add_new_option(GenAVR8.OPS[4],
                                GenAVR8.OPS[5],
                                action='store_true',
                                default=False,
                                help='activate verbose mode for generation')
            self.add_new_option(GenAVR8.OPS[6],
                                action='version',
                                version=__version__)

    def process(self, verbose=False):
        '''
            Process and run operation.

            :param verbose: enable/disable verbose option.
            :type verbose: <bool>
            :return: boolean status, True (success) | False.
            :rtype: <bool>
            :exceptions: None
        '''
        status = False
        if self.tool_operational:
            if len(sys.argv) >= 4:
                options = [arg for i, arg in enumerate(sys.argv) if i % 2 != 0]
                if any([arg not in GenAVR8.OPS for arg in options]):
                    sys.argv.append('-h')
            else:
                sys.argv.append('-h')
            args = self.parse_args(sys.argv[1:])
            project_exists = exists('{0}/{1}'.format(getcwd(),
                                                     getattr(args, 'gen')))
            if not project_exists:
                if bool(getattr(args, 'gen')) and bool(getattr(args, 'type')):
                    generator = AVR8Setup(
                        verbose=getattr(args, 'verbose') or verbose)
                    generator.project_setup(getattr(args, 'gen'),
                                            getattr(args, 'type'))
                    print('{0} {1} {2} [{3}]'.format(
                        '[{0}]'.format(GenAVR8.GEN_VERBOSE.lower()),
                        'generating AVR8 project skeleton',
                        getattr(args, 'type'), getattr(args, 'gen')))
                    status = generator.gen_pro_setup(
                        verbose=getattr(args, 'verbose') or verbose)
                    if status:
                        success_message(GenAVR8.GEN_VERBOSE, 'done\n')
                        self.logger.write_log(
                            '{0} {1} done'.format('generation of project',
                                                  getattr(args, 'gen')),
                            ATSLogger.ATS_INFO)
                    else:
                        error_message(GenAVR8.GEN_VERBOSE,
                                      'failed to generate project')
                        self.logger.write_log('generation failed',
                                              ATSLogger.ATS_ERROR)
                else:
                    error_message(GenAVR8.GEN_VERBOSE,
                                  'provide project name and type')
                    self.logger.write_log('provide project name and type',
                                          ATSLogger.ATS_ERROR)
            else:
                error_message(GenAVR8.GEN_VERBOSE, 'project dir already exist')
                self.logger.write_log('project dir already exist',
                                      ATSLogger.ATS_ERROR)
        else:
            error_message(GenAVR8.GEN_VERBOSE, 'tool is not operational')
            self.logger.write_log('tool is not operational',
                                  ATSLogger.ATS_ERROR)
        return status

    def __str__(self):
        '''
            Dunder method for GenAVR8.

            :return: object in a human-readable format.
            :rtype: <str>
            :exceptions: None
        '''
        return '{0} ({1}, {2})'.format(self.__class__.__name__,
                                       CfgCLI.__str__(self), str(self.logger))
Esempio n. 5
0
class SshCrack(CfgCLI):
    '''
        Define class SshCrack with attribute(s) and method(s).
        Load a base info, create an CLI interface and run operation(s).
        It defines:

            :attributes:
                | __metaclass__ - setting cooperative metaclasses.
                | TOOL_VERBOSE - console text indicator for process-phase.
                | CONFIG - tool info file path.
                | LOG - tool log file path.
                | LOGO - logo for splash screen.
                | OPS - list of tool options.
                | logger - logger object API.
            :methods:
                | __init__ - initial constructor.
                | process - process and run tool option(s).
    '''

    __metaclass__ = CooperativeMeta
    TOOL_VERBOSE = 'SSH_CRACK'
    CONFIG = '/conf/ssh_crack.cfg'
    LOG = '/log/ssh_crack.log'
    LOGO = '/conf/ssh_crack.logo'
    OPS = ['-g', '--gen', '-v', '--verbose', '--version']

    def __init__(self, verbose=False):
        '''
            Initial constructor.

            :param verbose: enable/disable verbose option.
            :type verbose: <bool>
            :exceptions: None
        '''
        current_dir = dirname(realpath(__file__))
        ssh_crack_property = {
            'ats_organization': 'vroncevic',
            'ats_repository': 'ssh_crack',
            'ats_name': 'ssh_crack',
            'ats_logo_path': '{0}{1}'.format(current_dir, SshCrack.LOGO),
            'ats_use_github_infrastructure': True
        }
        splash = Splash(ssh_crack_property, verbose=verbose)
        base_info = '{0}{1}'.format(current_dir, SshCrack.CONFIG)
        CfgCLI.__init__(self, base_info, verbose=verbose)
        verbose_message(SshCrack.TOOL_VERBOSE, verbose, 'init tool info')
        self.logger = ATSLogger(SshCrack.TOOL_VERBOSE.lower(),
                                '{0}{1}'.format(current_dir, SshCrack.LOG),
                                verbose=verbose)
        if self.tool_operational:
            self.add_new_option(SshCrack.OPS[0],
                                SshCrack.OPS[1],
                                dest='opt',
                                help='option')
            self.add_new_option(SshCrack.OPS[2],
                                SshCrack.OPS[3],
                                action='store_true',
                                default=False,
                                help='activate verbose mode for generation')
            self.add_new_option(SshCrack.OPS[4],
                                action='version',
                                version=__version__)

    def process(self, verbose=False):
        '''
            Process and run operation.

            :param verbose: enable/disable verbose option.
            :type verbose: <bool>
            :return: boolean status, True (success) | False.
            :rtype: <bool>
            :exceptions: None
        '''
        status = False
        if self.tool_operational:
            num_of_args_sys = len(sys.argv)
            if num_of_args_sys > 1:
                operation = sys.argv[1]
                if operation not in SshCrack.OPS:
                    sys.argv.append('-h')
            else:
                sys.argv.append('-h')
            args = self.parse_args(sys.argv[1:])
            if bool(getattr(args, 'opt')):
                print('{0} {1} [{2}]'.format(
                    '[{0}]'.format(SshCrack.TOOL_VERBOSE.lower()),
                    'running option', getattr(args, 'opt')))
                #
                # Code goes here
                #
                status = True
                if status:
                    success_message(SshCrack.TOOL_VERBOSE, 'done\n')
                    self.logger.write_log(
                        '{0} {1} done'.format('run operation',
                                              getattr(args, 'opt')),
                        ATSLogger.ATS_INFO)
                else:
                    error_message(SshCrack.TOOL_VERBOSE,
                                  'failed to run option')
                    self.logger.write_log('failed to run option',
                                          ATSLogger.ATS_ERROR)
            else:
                error_message(SshCrack.TOOL_VERBOSE, 'provide option')
                self.logger.write_log('provide option', ATSLogger.ATS_ERROR)
        else:
            error_message(SshCrack.TOOL_VERBOSE, 'tool is not operational')
            self.logger.write_log('tool is not operational',
                                  ATSLogger.ATS_ERROR)
        return status

    def __str__(self):
        '''
            Dunder method for Ssh_crack.

            :return: object in a human-readable format.
            :rtype: <str>
            :exceptions: None
        '''
        return '{0} ({1}, {2})'.format(self.__class__.__name__,
                                       CfgCLI.__str__(self), str(self.logger))