Exemplo n.º 1
0
 def install_configuration(self, image, mountpoint):
     uenv_txt = self['uenv_txt']
     if uenv_txt is not None:
         log.output('Uenv txt: %s' % (uenv_txt))
         image.install(path.abspath(uenv_txt), mountpoint)
     else:
         template = None
         if self['net_dhcp'] or self['net_ip'] is not None:
             if self['net_dhcp']:
                 template = 'uenv_net_dhcp'
             else:
                 template = 'uenv_net_static'
             if self['net_server_ip']:
                 template += '_sip'
             if self['net_fdt']:
                 template += '_net_fdt'
         else:
             if self['kernel'] is not None:
                 template = 'uenv_exe'
             elif self['fdt'] is not None:
                 template = 'uenv'
             if self['fdt'] is not None:
                 template += '_fdt'
         if template is not None:
             log.notice('Uenv template: %s' % (template))
             uenv_start = self.comma_split(self['uenv_start'])
             uenv_body = self.comma_split(self[template])
             uenv_end = self.comma_split(self['uenv_end'])
             uenv = uenv_start + uenv_body + uenv_end
             image.install_text(self.filter_text(uenv),
                                path.join(mountpoint, self['boot_config']))
Exemplo n.º 2
0
    def parse(self):
        if not path.exists(self.summary_file_path):
            log.output('coverage: summary file %s does not exist!' %
                       (self.summary_file_path))
            self.is_failure = True

        with open(self.summary_file_path, 'r') as summary_file:
            self.bytes_analyzed = self._get_next_with_colon(summary_file)
            self.bytes_not_executed = self._get_next_with_colon(summary_file)
            self.percentage_executed = self._get_next_with_colon(summary_file)
            self.percentage_not_executed = self._get_next_with_colon(
                summary_file)
            self.ranges_uncovered = self._get_next_with_colon(summary_file)
            self.branches_total = self._get_next_with_colon(summary_file)
            self.branches_uncovered = self._get_next_with_colon(summary_file)
            self.branches_always_taken = self._get_next_without_colon(
                summary_file)
            self.branches_never_taken = self._get_next_without_colon(
                summary_file)
        if len(self.branches_uncovered) > 0 and len(self.branches_total) > 0:
            self.percentage_branches_covered = \
                1.0 - (float(self.branches_uncovered) / float(self.branches_total))
        else:
            self.percentage_branches_covered = 0.0
        return
Exemplo n.º 3
0
 def install(self, src, dst):
     src_base = path.basename(src)
     log.notice('Install: %s' % (src_base))
     asrc = path.abspath(src)
     adst = path.join(path.abspath(dst), src_base)
     log.output('Copy: %s -> %s' % (asrc, adst))
     path.copy(asrc, adst)
Exemplo n.º 4
0
 def fdt_convert(self, image, fdt):
     dst = path.join(path.abspath(self['build']), path.basename(fdt))
     self['fdt_build'] = dst
     log.output('Copy (into build): %s -> %s' % (fdt, dst))
     image.clean_path(dst)
     path.copy(fdt, dst)
     return self['fdt_image'].replace('@FDT@', dst)
Exemplo n.º 5
0
 def _error(self, msg):
     err = 'error: %s' % (self._name_line_msg(msg))
     log.stderr(err)
     log.output(err)
     self.in_error = True
     if not self.opts.dry_run():
         log.stderr('warning: switched to dry run due to errors')
         self.opts.set_dry_run()
Exemplo n.º 6
0
 def install_text(self, text, dst):
     dst_base = path.basename(dst)
     log.notice('Install: %s' % (dst_base))
     adst = path.abspath(dst)
     log.output('Copy: text[%d] -> %s' % (len(text), adst))
     log.output([' ] ' + l for l in text])
     with open(adst, "w") as o:
         o.write(os.linesep.join(text))
Exemplo n.º 7
0
 def log_output(self, heading):
     log_lock.acquire()
     try:
         log.output(heading + self.text)
     except:
         raise
     finally:
         log_lock.release()
Exemplo n.º 8
0
 def _cleanup(self):
     if not self.no_clean:
         if self.trace:
             log.output('Coverage cleaning tempfiles')
         for exe in self.executables:
             trace_file = exe + '.cov'
             if path.exists(trace_file):
                 os.remove(trace_file)
         os.remove(self.symbol_select_path)
Exemplo n.º 9
0
 def build(self):
     for arch in self.config.archs():
         self.build_arch(arch)
     log.notice('^ Profile Time %s' % (str(end - start)))
     log.notice('+  warnings:%d  exes:%d  objs:%d  libs:%d' % \
                (self.warnings.get(), self.counts['exes'],
                 self.counts['objs'], self.counts['libs']))
     log.output('Profile Warnings:')
     log.output(self.warnings.report())
Exemplo n.º 10
0
 def build(self):
     for arch in self.config.archs():
         self.build_arch(arch)
     log.notice('^ Profile Time %s' % (str(end - start)))
     log.notice('+  warnings:%d  exes:%d  objs:%d  libs:%d' % \
                (self.warnings.get(), self.counts['exes'],
                 self.counts['objs'], self.counts['libs']))
     log.output('Profile Warnings:')
     log.output(self.warnings.report())
Exemplo n.º 11
0
 def log_info(self):
     # Filter potentially sensitive mail options out.
     filtered_args = [
         arg for arg in self.argv
         if all(smtp_opt not in arg for smtp_opt in [
             '--smtp-host', '--mail-to', '--mail-from', '--smtp-user',
             '--smtp-password', '--smtp-port'
         ])
     ]
     log.output(log.info(filtered_args))
Exemplo n.º 12
0
 def _output_line(line, exe, prefix, out, count):
     #exe.lock.acquire()
     #exe.outputting = True
     #exe.lock.release()
     if out:
         out(prefix + line)
     else:
         log.output(prefix + line)
         if count > 10:
             log.flush()
Exemplo n.º 13
0
 def kernel_convert(self, image, kernel):
     dst = path.join(path.abspath(self['build']), path.basename(kernel))
     self['kernel_build'] = dst
     log.output('Copy (into build): %s -> %s' % (kernel, dst))
     image.clean_path(dst)
     path.copy(kernel, dst)
     cmds = self.filter_text(self.comma_split(self['kernel_converter']))
     for cmd in cmds:
         _command(cmd, self['build'])
     return self['kernel_image'].replace('@KERNEL@', dst)
Exemplo n.º 14
0
 def __init__(self, command_path, build, convert_kernel, paths, board):
     self.uboot = {'paths': paths, 'board': board}
     self.convert_kernel = convert_kernel
     super(uboot_bootloader, self).__init__(command_path, build, 'u-boot')
     if self.board() not in self.boards():
         raise error.general('board not found: %s' % (self.board()))
     log.output('Board: %s' % (self.board()))
     self.section_macro_map(self.board())
     self.macros.set_read_map(self['bootloader'] + '-templates')
     self.macros.lock_read_map()
     self._check_frist_second_stages()
Exemplo n.º 15
0
def _check_exes(exes):
    ok = True
    first = True
    for exe in exes:
        log.output('check exe: %s' % (exe))
        if not check.check_exe(None, exe):
            if first:
                log.notice('Host executable(s) not found:')
                first = False
            log.notice(' %s' % (exe))
            ok = False
    return ok
Exemplo n.º 16
0
 def build_profile(self, profile):
     if not self.config.profile_present(profile):
         raise error.general('BSP not found: %s/%s' % (arch, bsp))
     start = datetime.datetime.now()
     log.notice(']] Profile: %s' % (profile))
     for arch in self.config.profile_archs(profile):
         for bsp in self.config.profile_arch_bsps(profile, arch):
             self.build_arch_bsp(arch, bsp)
     end = datetime.datetime.now()
     log.notice('^ Profile Time %s' % (str(end - start)))
     log.notice('  warnings:%d  exes:%d  objs:%d  libs:%d' % \
                (self.warnings.get(), self.counts['exes'],
                 self.counts['objs'], self.counts['libs']))
     log.output('Profile Warnings:')
     log.output(self.warnings.report())
Exemplo n.º 17
0
 def build_profile(self, profile):
     if not self.config.profile_present(profile):
         raise error.general('BSP not found: %s/%s' % (arch, bsp))
     start = datetime.datetime.now()
     log.notice(']] Profile: %s' % (profile))
     for arch in self.config.profile_archs(profile):
         for bsp in self.config.profile_arch_bsps(profile, arch):
             self.build_arch_bsp(arch, bsp)
     end = datetime.datetime.now()
     log.notice('^ Profile Time %s' % (str(end - start)))
     log.notice('  warnings:%d  exes:%d  objs:%d  libs:%d' % \
                (self.warnings.get(), self.counts['exes'],
                 self.counts['objs'], self.counts['libs']))
     log.output('Profile Warnings:')
     log.output(self.warnings.report())
Exemplo n.º 18
0
 def create_path(self, where, recreate=True, cleanup=True):
     if path.exists(where):
         log.output('remove: %s' % (where))
         path.removeall(where)
     try:
         log.output('make: %s' % (where))
         path.mkdir(where)
     except:
         raise error.general('cannot create build path: %s' % (where))
     if not path.isreadable(where):
         raise error.general('build path is not readable: %s' % (where))
     if not path.iswritable(where):
         raise error.general('build path is not writeable: %s' % (where))
     if cleanup:
         self.remove_paths += [where]
Exemplo n.º 19
0
 def output(self, text):
     for l in text.splitlines():
         if ' warning:' in l:
             self.count += 1
             ws = l.split(' ')
             if len(ws) > 0:
                 ws = ws[0].split(':')
                 w = path.abspath(ws[0])
                 w = w.replace(self.rtems, '')
                 if path.isabspath(w):
                     w = w[1:]
                 w = '%s:%s:%s' % (w, ws[1], ws[2])
                 if w not in self.warnings:
                     self.warnings[w] = 0
                 self.warnings[w] += 1
     log.output(text)
Exemplo n.º 20
0
 def _finished(self):
     log.notice('Total: Warnings:%d  exes:%d  objs:%d  libs:%d' % \
                (self.results.get_warning_count(), self.counts['exes'],
                 self.counts['objs'], self.counts['libs']))
     log.output()
     log.output('Warnings:')
     log.output(self.results.warnings_report())
     log.output()
     log.notice('Failures:')
     log.notice(self.results.failures_report())
     self._warnings_report()
     self._failures_report()
Exemplo n.º 21
0
 def output(self, text):
     for l in text.splitlines():
         if ' warning:' in l:
             self.count += 1
             ws = l.split(' ')
             if len(ws) > 0:
                 ws = ws[0].split(':')
                 w = path.abspath(ws[0])
                 w = w.replace(self.rtems, '')
                 if path.isabspath(w):
                     w = w[1:]
                 #
                 # Ignore compiler option warnings.
                 #
                 if len(ws) >= 3:
                     w = '%s:%s:%s' % (w, ws[1], ws[2])
                     if w not in self.warnings:
                         self.warnings[w] = 0
                     self.warnings[w] += 1
     log.output(text)
Exemplo n.º 22
0
 def _execute(self, phase):
     exit_code = 0
     cmd = self.commands[phase]
     try:
         # This should locked; not sure how to do that
         self.proc = execute.capture_execution(log=self.output)
         log.output(wrap(('run:', self.build.key(), cmd), lineend='\\'))
         if not self.commands['dry-run']:
             exit_code, proc, output = self.proc.shell(
                 cmd, cwd=path.host(self._build_dir()))
     except:
         traceback.print_exc()
         self.lock.acquire()
         if self.proc is not None:
             self.proc.kill()
         self.lock.release()
         exit_code = 1
     self.lock.acquire()
     self.proc = None
     self.lock.release()
     return exit_code == 0
Exemplo n.º 23
0
def _command(cmd, cwd):
    e = execute.capture_execution()
    cwd = path.abspath(cwd)
    log.output('>> cwd: %s' % (cwd))
    log.output('> %s' % (cmd))
    exit_code, proc, output = e.shell(cmd, cwd=path.host(cwd))
    output_split = output.split(os.linesep)
    if len(output_split) >= 1 and len(output_split[0]) > 0:
        log.output(['> ' + l for l in output_split])
    log.output('> exit: %d' % (exit_code))
    if exit_code != 0:
        err = 'executing failure: (exit:%d) %s' % (exit_code, cmd)
        raise error.general(err)
    return output
Exemplo n.º 24
0
 def log(self, name, mode):
     status_fails = [
         'failed', 'timeout', 'invalid', 'wrong-version', 'wrong-build',
         'wrong-tools'
     ]
     if mode != 'none':
         self.lock.acquire()
         if name not in self.results:
             self.lock.release()
             raise error.general('test report missing: %s' % (name))
         exe = path.basename(self.results[name]['exe'])
         result = self.results[name]['result']
         time = self.results[name]['end'] - self.results[name]['start']
         failed = result in status_fails
         result = 'Result: %-10s Time: %s %s' % (result, str(time), exe)
         if mode != 'none':
             header = self.results[name]['header']
         if mode == 'all' or failed:
             output = self.results[name]['output']
         else:
             output = None
         self.lock.release()
         if header:
             log.output(header)
         if output:
             log.output(result)
             log.output(output)
Exemplo n.º 25
0
 def host_partition(self, image_, device, ptype, plabel, pformat, psize,
                    palign):
     types = {'MBR': 'MBR'}
     formats = {'fat16': '6', 'fat32': 'b'}
     if ptype not in types:
         err = 'unknown type of partitioning: %s' % (ptype)
         raise error.general(err)
     if pformat not in formats:
         raise error.general('unknown format: %s' % (pformat))
     #
     # Datch the loop back device, we use fdisk on the image to avoid any
     # kernel errors related to re-reading the updated partition data.
     #
     self.host_image_detach(device)
     #
     # This awkward exchange is needed to script fdisk, hmmm.
     #
     with tempfile.NamedTemporaryFile() as tmp:
         s = os.linesep.join([
             'o',  # create a new empty part table
             'n',  # add a new partition
             'p',  # primary
             '1',  # partition 1
             '%d' % (_si_size(palign) / 512),
             '%d' % (_si_size(psize) / 512),
             't',  # change a partition type
             '%s' % (formats[pformat]),  # hex code
             'a',  # toggle a bootable flag
             'p',  # print
             'w',  # write table to disk and exit
             ''
         ])
         log.output('fdisk script:')
         log.output(s)
         tmp.write(s.encode())
         tmp.seek(0)
         self.command('cat %s | fdisk -t %s %s' %
                      (tmp.name, types[ptype], image_))
     return self.host_image_attach(image_)
Exemplo n.º 26
0
 def open(self, command, capture = True, shell = False,
          cwd = None, env = None,
          stdin = None, stdout = None, stderr = None,
          timeout = None):
     """Open a command with arguments. Provide the arguments as a list or
     a string."""
     if self.verbose:
         s = command
         if type(command) is list:
             def add(x, y): return x + ' ' + str(y)
             s = functools.reduce(add, command, '')[1:]
         what = 'spawn'
         if shell:
             what = 'shell'
         log.output(what + ': ' + s)
     if self.output is None:
         raise error.general('capture needs an output handler')
     if shell and self.shell_exe:
         command = arg_list(command)
         command[:0] = self.shell_exe
     if not stdin and self.input:
         stdin = subprocess.PIPE
     if not stdout:
         stdout = subprocess.PIPE
     if not stderr:
         stderr = subprocess.PIPE
     proc = None
     if cwd is None:
         cwd = self.path
     if env is None:
         env = self.environment
     try:
         # Work around a problem on Windows with commands that
         # have a '.' and no extension. Windows needs the full
         # command name.
         if sys.platform == "win32" and type(command) is list:
             if command[0].find('.') >= 0:
                 r, e = os.path.splitext(command[0])
                 if e not in ['.exe', '.com', '.bat']:
                     command[0] = command[0] + '.exe'
         log.trace('exe: %s' % (command))
         proc = subprocess.Popen(command, shell = shell,
                                 cwd = cwd, env = env,
                                 stdin = stdin, stdout = stdout,
                                 stderr = stderr,
                                 close_fds = False)
         if not capture:
             return (0, proc)
         if self.output is None:
             raise error.general('capture needs an output handler')
         exit_code = self.capture(proc, command, timeout)
         if self.verbose:
             log.output('exit: ' + str(exit_code))
     except OSError as ose:
         exit_code = ose.errno
         if self.verbose:
             log.output('exit: ' + str(ose))
     return (exit_code, proc)
Exemplo n.º 27
0
 def cleanup(self):
     log.notice('Cleaning up')
     for m in self.unmount_paths:
         log.output('unmount: %s' % (m))
         self.unmount(m)
     for i in self.detach_images:
         log.output('detach: %s' % (i))
         self.image_detach(i)
     if self.loader.clean:
         for r in self.remove_paths:
             if path.exists(r):
                 log.output('remove: %s' % (r))
                 path.removeall(r)
Exemplo n.º 28
0
 def build_arch(self, arch):
     start = datetime.datetime.now()
     log.output('=' * 70)
     log.notice(']] Architecture: %s' % (arch))
     if not self.confif.arch_present(arch):
         raise error.general('Architecture not found: %s' % (arch))
     for bsp in self._bsps(arch):
         self.build_arch_bsp(arch, bsp)
     log.notice('^ Architecture Time %s' % (str(end - start)))
     log.notice('  warnings:%d  exes:%d  objs:%s  libs:%d' % \
                self.warnings.get(), self.counts['exes'],
                self.counts['objs'], self.counts['libs'])
     log.output('Architecture Warnings:')
     log.output(self.warnings.report())
Exemplo n.º 29
0
 def build_arch(self, arch):
     start = datetime.datetime.now()
     log.output('=' * 70)
     log.notice(']] Architecture: %s' % (arch))
     if not self.config.arch_present(arch):
         raise error.general('Architecture not found: %s' % (arch))
     for bsp in self._bsps(arch):
         self.build_arch_bsp(arch, bsp)
     end = datetime.datetime.now()
     log.notice('^ Architecture Time %s' % (str(end - start)))
     log.notice('  warnings:%d  exes:%d  objs:%d  libs:%d' % \
                (self.warnings.get(), self.counts['exes'],
                 self.counts['objs'], self.counts['libs']))
     log.output('Architecture Warnings:')
     log.output(self.warnings.report())
Exemplo n.º 30
0
 def log(self, name, mode):
     if mode != 'none':
         self.lock.acquire()
         if name not in self.results:
             self.lock.release()
             raise error.general('test report missing: %s' % (name))
         exe = path.basename(self.results[name]['exe'])
         result = self.results[name]['result']
         time = self.results[name]['end'] - self.results[name]['start']
         if mode != 'none':
             header = self.results[name]['header']
         if mode == 'all' or result != 'passed':
             output = self.results[name]['output']
         else:
             output = None
         self.lock.release()
         if header:
             log.output(header)
         if output:
             log.output(output)
             log.output('Result: %-10s Time: %s %s' % (result, str(time), exe))
Exemplo n.º 31
0
 def log(self, name, mode):
     if mode != 'none':
         self.lock.acquire()
         if name not in self.results:
             self.lock.release()
             raise error.general('test report missing: %s' % (name))
         result = self.results[name]['result']
         time = self.results[name]['end'] - self.results[name]['start']
         if mode != 'none':
             header = self.results[name]['header']
         if mode == 'all' or result != 'passed':
             output = self.results[name]['output']
         else:
             output = None
         self.lock.release()
         if header:
             log.output(header)
         if output:
             log.output(output)
         if header:
             log.output('Result: %-10s Time: %s' % (result, str(time)))
Exemplo n.º 32
0
 def build_arch_bsp(self, arch, bsp):
     if not self.config.bsp_present(arch, bsp):
         raise error.general('BSP not found: %s/%s' % (arch, bsp))
     log.output('-' * 70)
     log.notice('] BSP: %s/%s' % (arch, bsp))
     log.notice('. Creating: %s' % (self._path(arch, bsp)))
     self._arch_bsp_dir_clean(arch, bsp)
     self._arch_bsp_dir_make(arch, bsp)
     variations = self._variations(arch, bsp)
     build_set = self._build_set(variations)
     bsp_start = datetime.datetime.now()
     bsp_warnings = warnings_counter(self.rtems)
     env_path = os.environ['PATH']
     os.environ['PATH'] = path.host(path.join(self.tools, 'bin')) + \
                          os.pathsep + os.environ['PATH']
     for bs in sorted(build_set.keys()):
         warnings = warnings_counter(self.rtems)
         start = datetime.datetime.now()
         log.output('- ' * 35)
         log.notice('. Configuring: %s' % (bs))
         try:
             result = '+ Pass'
             bpath = self._build_dir(arch, bsp, bs)
             path.mkdir(bpath)
             config_cmd = self._config_command(build_set[bs], arch, bsp)
             cmd = config_cmd
             e = execute.capture_execution(log = warnings)
             log.output('run: ' + cmd)
             if self.options['dry-run']:
                 exit_code = 0
             else:
                 exit_code, proc, output = e.shell(cmd, cwd = path.host(bpath))
             if exit_code != 0:
                 result = '- FAIL'
                 self.errors['configure'] += 1
                 log.notice('- Configure failed: %s' % (bs))
                 log.output('cmd failed: %s' % (cmd))
                 if self.options['stop-on-error']:
                     raise error.general('Configuring %s failed' % (bs))
             else:
                 log.notice('. Building: %s' % (bs))
                 cmd = 'make'
                 if 'jobs' in self.options:
                     cmd += ' -j %s' % (self.options['jobs'])
                 log.output('run: ' + cmd)
                 if self.options['dry-run']:
                     exit_code = 0
                 else:
                     exit_code, proc, output = e.shell(cmd, cwd = path.host(bpath))
                 if exit_code != 0:
                     result = '- FAIL'
                     self.errors['build'] += 1
                     log.notice('- FAIL: %s: %s' % (bs, self._error_str()))
                     log.output('cmd failed: %s' % (cmd))
                     if self.options['stop-on-error']:
                         raise error.general('Building %s failed' % (bs))
                 files = self._count_files(arch, bsp, bs)
                 log.notice('%s: %s: warnings:%d  exes:%d  objs:%s  libs:%d' % \
                            (result, bs, warnings.get(),
                             files['exes'], files['objs'], files['libs']))
             log.notice('  %s' % (self._error_str()))
             self.results.add(result[0] == '+', arch, bsp, config_cmd, warnings.get())
         finally:
             end = datetime.datetime.now()
             if not self.options['no-clean']:
                 log.notice('. Cleaning: %s' % (self._build_dir(arch, bsp, bs)))
                 path.removeall(self._build_dir(arch, bsp, bs))
         log.notice('^ Time %s' % (str(end - start)))
         log.output('Warnings Report:')
         log.output(warnings.report())
         warnings.accumulate(bsp_warnings)
         warnings.accumulate(self.warnings)
     bsp_end = datetime.datetime.now()
     log.notice('^ BSP Time %s' % (str(bsp_end - bsp_start)))
     log.output('BSP Warnings Report:')
     log.output(bsp_warnings.report())
     os.environ['PATH'] = env_path
Exemplo n.º 33
0
 def report(self):
     log.notice('* Passes: %d   Failures: %d' %
                (len(self.passes), len(self.fails)))
     log.output()
     log.output('Build Report')
     log.output('   Passes: %d   Failures: %d' %
                (len(self.passes), len(self.fails)))
     log.output(' Failures:')
     if len(self.fails) == 0:
         log.output('None')
     else:
         max_col = 0
         for f in self.fails:
             arch_bsp = self._arch_bsp(f[0], f[1])
             if len(arch_bsp) > max_col:
                 max_col = len(arch_bsp)
         for f in self.fails:
             config_cmd = f[2]
             config_at = config_cmd.find('configure')
             if config_at != -1:
                 config_cmd = config_cmd[config_at:]
             log.output(' %*s:  %s' % (max_col + 2,
                                       self._arch_bsp(f[0], f[1]),
                                       config_cmd))
     log.output(' Passes:')
     if len(self.passes) == 0:
         log.output('None')
     else:
         max_col = 0
         for f in self.passes:
             arch_bsp = self._arch_bsp(f[0], f[1])
             if len(arch_bsp) > max_col:
                 max_col = len(arch_bsp)
         for f in self.passes:
             config_cmd = f[2]
             config_at = config_cmd.find('configure')
             if config_at != -1:
                 config_cmd = config_cmd[config_at:]
             log.output(' %*s:  %5d  %s' % (max_col + 2,
                                            self._arch_bsp(f[0], f[1]),
                                            f[3],
                                            config_cmd))
Exemplo n.º 34
0
 def log_info(self):
     log.output(log.info(self.argv))
Exemplo n.º 35
0
 def summary(self):
     log.output()
     log.notice(self.score_card())
     log.output(self.failures())
Exemplo n.º 36
0
def run(args=sys.argv, command_path=None):
    '''Run a TFTP server session.'''
    # pylint: disable=dangerous-default-value
    # pylint: disable=unused-argument
    # pylint: disable=too-many-branches
    # pylint: disable=too-many-statements
    ecode = 0
    notice = None
    server = None
    # pylint: disable=bare-except
    try:
        description = 'A TFTP Server that supports a read only TFTP session.'

        nice_cwd = os.path.relpath(os.getcwd())
        if len(nice_cwd) > len(os.path.abspath(nice_cwd)):
            nice_cwd = os.path.abspath(nice_cwd)

        argsp = argparse.ArgumentParser(prog='rtems-tftp-server',
                                        description=description)
        argsp.add_argument('-l',
                           '--log',
                           help='log file.',
                           type=str,
                           default=None)
        argsp.add_argument('-v',
                           '--trace',
                           help='enable trace logging for debugging.',
                           action='store_true',
                           default=False)
        argsp.add_argument('--trace-packets',
                           help='enable trace logging of packets.',
                           action='store_true',
                           default=False)
        argsp.add_argument('--show-backtrace',
                           help='show the exception backtrace.',
                           action='store_true',
                           default=False)
        argsp.add_argument(
            '-B',
            '--bind',
            help='address to bind the server too (default: %(default)s).',
            type=str,
            default='all')
        argsp.add_argument(
            '-P',
            '--port',
            help='port to bind the server too (default: %(default)s).',
            type=int,
            default='69')
        argsp.add_argument('-t', '--timeout',
                           help = 'timeout in seconds, client can override ' \
                           '(default: %(default)s).',
                           type = int, default = '10')
        argsp.add_argument(
            '-b',
            '--base',
            help='base path, not checked (default: %(default)s).',
            type=str,
            default=nice_cwd)
        argsp.add_argument(
            '-F',
            '--force-file',
            help='force the file to be downloaded overriding the client.',
            type=str,
            default=None)
        argsp.add_argument('-s', '--sessions',
                           help = 'number of TFTP sessions to run before exiting ' \
                           '(default: forever.',
                           type = int, default = None)

        argopts = argsp.parse_args(args[1:])

        load_log(argopts.log)
        log.notice('RTEMS Tools - TFTP Server, %s' % (version.string()))
        log.output(log.info(args))
        log.tracing = argopts.trace

        server = tftp_server(argopts.bind, argopts.port, argopts.timeout,
                             argopts.base, argopts.force_file,
                             argopts.sessions)
        server.enable_notices()
        if argopts.trace_packets:
            server.trace_packets()
        if argopts.show_backtrace:
            server.except_is_raise()

        try:
            server.start()
            server.run()
        finally:
            server.stop()

    except error.general as gerr:
        notice = str(gerr)
        ecode = 1
    except error.internal as ierr:
        notice = str(ierr)
        ecode = 1
    except error.exit:
        pass
    except KeyboardInterrupt:
        notice = 'abort: user terminated'
        ecode = 1
    except SystemExit:
        pass
    except:
        notice = 'abort: unknown error'
        ecode = 1
    if server is not None:
        del server
    if notice is not None:
        log.stderr(notice)
    sys.exit(ecode)
Exemplo n.º 37
0
 def show_state(results, state, max_len):
     for name in results:
         if results[name]['result'] == state:
             log.output(' %s' % (path.basename(name)))
Exemplo n.º 38
0
 def summary(self):
     def show_state(results, state, max_len):
         for name in results:
             if results[name]['result'] == state:
                 log.output(' %s' % (path.basename(name)))
     log.output()
     log.notice('Passed:   %*d' % (self.total_len, self.passed))
     log.notice('Failed:   %*d' % (self.total_len, self.failed))
     log.notice('Timeouts: %*d' % (self.total_len, self.timeouts))
     log.notice('Invalid:  %*d' % (self.total_len, self.invalids))
     log.output('----------%s' % ('-' * self.total_len))
     log.notice('Total:    %*d' % (self.total_len, self.total))
     log.output()
     if self.failed:
         log.output('Failures:')
         show_state(self.results, 'failed', self.name_max_len)
     if self.timeouts:
         log.output('Timeouts:')
         show_state(self.results, 'timeout', self.name_max_len)
     if self.invalids:
         log.output('Invalid:')
         show_state(self.results, 'invalid', self.name_max_len)
Exemplo n.º 39
0
 def show_state(results, state, max_len):
     for name in results:
         if results[name]['result'] == state:
             log.output(' %s' % (path.basename(name)))