示例#1
0
def run(args):
    try:
        long_opts = {
            # key              macro         handler   param  defs   init
            '--test-path'  : ('_test_path',  'path',   True,  None,  False),
            '--test-jobs'  : ('_test_jobs',  'jobs',   True,  'max', True),
            '--test-bool'  : ('_test_bool',  'bool',   False, '0',   True)
        }
        opts = command_line(base_path = '.',
                            argv = args,
                            optargs = None,
                            defaults = macros.macros(),
                            long_opts = long_opts,
                            command_path = '.')
        load(opts)
        log.notice('RTEMS Tools Project - Defaults, v%s' % (version.string()))
        opts.log_info()
        log.notice('Options:')
        log.notice(str(opts))
        log.notice('Defaults:')
        log.notice(str(opts.defaults))
    except error.general as gerr:
        print(gerr)
        sys.exit(1)
    except error.internal as ierr:
        print(ierr)
        sys.exit(1)
    except error.exit:
        pass
    except KeyboardInterrupt:
        _notice(opts, 'abort: user terminated')
        sys.exit(1)
    sys.exit(0)
示例#2
0
def load(args, optargs=None, command_path=None, defaults='%s' % (defaults_mc)):
    #
    # The path to this command if not supplied by the upper layers.
    #
    if command_path is None:
        command_path = path.dirname(args[0])
        if len(command_path) == 0:
            command_path = '.'
    #
    # Check if there is a defaults.mc file under the command path. If so this is
    # the tester being run from within the git repo. If not found assume the tools
    # have been installed and the defaults is in the install prefix.
    #
    if path.exists(path.join(command_path, defaults_mc)):
        rtdir = command_path
    else:
        rtdir = '%{_prefix}/share/rtems/tester'
    defaults = '%s/%s' % (rtdir, defaults_mc)
    #
    # The command line contains the base defaults object all build objects copy
    # and modify by loading a configuration.
    #
    opts = command_line(args, optargs, macros.macros(name=defaults,
                                                     rtdir=rtdir),
                        command_path)
    options.load(opts)
    return opts
示例#3
0
def load(args, optargs=None, command_path=None, defaults="%s" % (defaults_mc)):
    #
    # The path to this command if not supplied by the upper layers.
    #
    if command_path is None:
        command_path = path.dirname(args[0])
        if len(command_path) == 0:
            command_path = "."
    #
    # Check if there is a defaults.mc file under the command path. If so this is
    # the tester being run from within the git repo. If not found assume the tools
    # have been installed and the defaults is in the install prefix.
    #
    if path.exists(path.join(command_path, defaults_mc)):
        rtdir = command_path
    else:
        rtdir = "%{_prefix}/share/rtems/tester"
    defaults = "%s/%s" % (rtdir, defaults_mc)
    #
    # The command line contains the base defaults object all build objects copy
    # and modify by loading a configuration.
    #
    opts = command_line(args, optargs, macros.macros(name=defaults, rtdir=rtdir), command_path)
    options.load(opts)
    return opts
示例#4
0
 def __init__(self, command_path, build=None, bootloader=None):
     #
     # Check if there is a defaults.mc file under the command path. If so
     # this is the tester being run from within the git repo. If not found
     # assume the tools have been installed and the defaults is in the
     # install prefix.
     #
     boot_ini = 'tools/config/rtems-boot.ini'
     if path.exists(path.join(command_path, boot_ini)):
         rtdir = command_path
     else:
         rtdir = '%{_prefix}/share/rtems'
     boot_ini = '%s/%s' % (rtdir, boot_ini)
     self.build = None
     self.macros = macros.macros(rtdir=rtdir, show_minimal=True)
     self.config = configuration.configuration(raw=False)
     self.load_config(bootloader, self.macros.expand(boot_ini))
     self.clean = True
示例#5
0
def load(args, optargs = None,
         command_path = None,
         defaults = '%{_rtdir}/rtems/testing/defaults.mc'):
    #
    # The path to this command if not supplied by the upper layers.
    #
    if command_path is None:
        command_path = path.dirname(args[0])
        if len(command_path) == 0:
            command_path = '.'
    #
    # The command line contains the base defaults object all build objects copy
    # and modify by loading a configuration.
    #
    opts = command_line(args,
                        optargs,
                        macros.macros(name = defaults,
                                      rtdir = command_path),
                        command_path)
    options.load(opts)
    return opts
示例#6
0
    def __init__(self, base_path = None, argv = None, optargs = None,
                 defaults = None, long_opts = None, long_opts_help = None,
                 command_path = '', log_default = None):

        if argv is None:
            return

        global basepath

        if long_opts == None:
            long_opts = {}

        basepath = base_path

        if log_default is not None and type(log_default) is not list:
            raise error.general('log default is not a list')
        self.log_default = log_default

        if defaults is None:
            defaults = macros.macros()

        self.long_opts = {
            # key                 macro                handler            param  defs       init
            '--jobs'           : ('_jobs',             self._lo_jobs,     True,  'default', True),
            '--log'            : ('_logfile',          self._lo_string,   True,  None,      False),
            '--macros'         : ('_macros',           self._lo_string,   True,  None,      False),
            '--force'          : ('_force',            self._lo_bool,     False, '0',       True),
            '--quiet'          : ('_quiet',            self._lo_bool,     False, '0',       True),
            '--trace'          : ('_trace',            self._lo_bool,     False, '0',       True),
            '--dry-run'        : ('_dry_run',          self._lo_bool,     False, '0',       True),
            '--warn-all'       : ('_warn_all',         self._lo_bool,     False, '0',       True),
            '--no-clean'       : ('_no_clean',         self._lo_bool,     False, '0',       True),
            '--keep-going'     : ('_keep_going',       self._lo_bool,     False, '0',       True),
            '--always-clean'   : ('_always_clean',     self._lo_bool,     False, '0',       True),
            '--no-install'     : ('_no_install',       self._lo_bool,     False, '0',       True),
            '--help'           : (None,                self._lo_help,     False, None,      False)
        }
        self.long_opts_help = {
            '--force':                      'Force the build to proceed',
            '--quiet':                      'Quiet output (not used)',
            '--trace':                      'Trace the execution',
            '--dry-run':                    'Do everything but actually run the build',
            '--warn-all':                   'Generate warnings',
            '--no-clean':                   'Do not clean up the build tree',
            '--always-clean':               'Always clean the build tree, even with an error',
            '--keep-going':                 'Do not stop on an error.',
            '--jobs=[0..n,none,half,full]': 'Run with specified number of jobs, default: num CPUs.',
            '--macros file[,file]':         'Macro format files to load after the defaults',
            '--log file':                   'Log file where all build output is written to',
        }
        self.opts = { 'params' : [] }
        self.command_path = command_path
        self.command_name = path.basename(argv[0])
        self.argv = argv
        self.args = argv[1:]
        self.optargs = optargs
        self.defaults = defaults
        for lo in self.long_opts:
            self.opts[lo[2:]] = self.long_opts[lo][3]
            if self.long_opts[lo][4]:
                self.defaults[self.long_opts[lo][0]] = ('none', 'none', self.long_opts[lo][3])
        for lo in long_opts:
            if lo in self.long_opts:
                raise error.general('suplicate option: %s' % (lo))
            self.opts[lo[2:]] = long_opts[lo][3]
            if long_opts[lo][4]:
                self.defaults[long_opts[lo][0]] = ('none', 'none', long_opts[lo][3])
            if long_opts[lo][1] == 'int':
                handler = self._lo_int
            elif long_opts[lo][1] == 'string':
                handler = self._lo_string
            elif long_opts[lo][1] == 'path':
                handler = self._lo_path
            elif long_opts[lo][1] == 'jobs':
                handler = self._lo_jobs
            elif long_opts[lo][1] == 'bool':
                handler = self._lo_bool
            elif long_opts[lo][1] == 'triplet':
                handler = self._lo_triplets
            else:
                raise error.general('invalid option handler: %s: %s' % (lo, long_opts[lo][1]))
            self.long_opts[lo] = (long_opts[lo][0], handler, long_opts[lo][2],
                                   long_opts[lo][3], long_opts[lo][4])
            if long_opts_help is not None:
                if lo not in long_opts_help:
                    raise error.general('no help for option: %s' % (lo))
                self.long_opts_help[lo] = long_opts_help[lo]
示例#7
0
    def send_file_as_body(self, to_addr, subject, name, intro=None):
        try:
            with open(name, 'r') as f:
                body = f.readlines()
        except IOError as err:
            raise error.general('error reading mail body: %s' % (name))
        if intro is not None:
            body = intro + body
        self.send(to_addr, from_addr, body)


if __name__ == '__main__':
    import sys
    from rtemstoolkit import macros
    optargs = {}
    rtdir = 'rtemstoolkit'
    defaults = '%s/defaults.mc' % (rtdir)
    append_options(optargs)
    opts = options.command_line(base_path='.',
                                argv=sys.argv,
                                optargs=optargs,
                                defaults=macros.macros(name=defaults,
                                                       rtdir=rtdir),
                                command_path='.')
    options.load(opts)
    m = mail(opts)
    print('From: %s' % (m.from_address()))
    print('SMTP Host: %s' % (m.smtp_host()))
    if '--mail' in sys.argv:
        m.send(m.from_address(), 'Test mailer.py', 'This is a test')