def find_config(config, configs):
    config_root, config_ext = path.splitext(config)
    if config_ext not in ['', '.bset', '.cfg']:
        config_root = config
        config_ext = ''
    for c in configs['files']:
        r, e = path.splitext(c)
        if config_root == r:
            if config_ext == '' or config_ext == e:
                return c
    return None
def find_config(config, configs):
    config_root, config_ext = path.splitext(config)
    if config_ext not in ["", ".bset", ".cfg"]:
        config_root = config
        config_ext = ""
    for c in configs["files"]:
        r, e = path.splitext(c)
        if config_root == r:
            if config_ext == "" or config_ext == e:
                return c
    return None
Beispiel #3
0
def find_config(config, configs):
    config_root, config_ext = path.splitext(config)
    if config_ext not in ['', '.bset', '.cfg']:
        config_root = config
        config_ext = ''
    for c in configs['files']:
        r, e = path.splitext(c)
        if config_root == r:
            if config_ext == '' or config_ext == e:
                return c
    return None
def parse_url(url, pathkey, config, opts):
    #
    # Split the source up into the parts we need.
    #
    source = {}
    source['url'] = url
    source['path'] = path.dirname(url)
    source['file'] = path.basename(url)
    source['name'], source['ext'] = path.splitext(source['file'])
    #
    # Get the file. Checks the local source directory first.
    #
    source['local'] = None
    for p in config.define(pathkey).split(':'):
        local = path.join(path.abspath(p), source['file'])
        if source['local'] is None:
            source['local_prefix'] = path.abspath(p)
            source['local'] = local
        if path.exists(local):
            source['local_prefix'] = path.abspath(p)
            source['local'] = local
            break
    source['script'] = ''
    for p in parsers:
        if url.startswith(p):
            source['type'] = p
            if parsers[p](source, config, opts):
                break
    return source
Beispiel #5
0
def parse_url(url, pathkey, config, opts, file_override = None):
    #
    # Split the source up into the parts we need.
    #
    source = {}
    source['url'] = url
    source['options'] = []
    colon = url.find(':')
    if url[colon + 1:colon + 3] != '//':
        raise error.general('malforned URL (no protocol prefix): %s' % (url))
    source['path'] = url[:colon + 3] + path.dirname(url[colon + 3:])
    if file_override is None:
        source['file'] = path.basename(url)
    else:
        bad_chars = [c for c in ['/', '\\', '?', '*'] if c in file_override]
        if len(bad_chars) > 0:
            raise error.general('bad characters in file name: %s' % (file_override))
        log.output('download: file-override: %s' % (file_override))
        source['file'] = file_override
        source['options'] += ['file-override']
    source['name'], source['ext'] = path.splitext(source['file'])
    if source['name'].endswith('.tar'):
        source['name'] = source['name'][:-4]
        source['ext'] = '.tar' + source['ext']
    #
    # Get the file. Checks the local source directory first.
    #
    source['local'] = None
    for p in parsers:
        if url.startswith(p):
            source['type'] = p
            if parsers[p](source, pathkey, config, opts):
                break
    source['script'] = ''
    return source
def parse_url(url, pathkey, config, opts):
    #
    # Split the source up into the parts we need.
    #
    source = {}
    source["url"] = url
    colon = url.find(":")
    if url[colon + 1 : colon + 3] != "//":
        raise error.general("malforned URL: %s" % (url))
    source["path"] = url[: colon + 3] + path.dirname(url[colon + 3 :])
    source["file"] = path.basename(url)
    source["name"], source["ext"] = path.splitext(source["file"])
    if source["name"].endswith(".tar"):
        source["name"] = source["name"][:-4]
        source["ext"] = ".tar" + source["ext"]
    #
    # Get the file. Checks the local source directory first.
    #
    source["local"] = None
    for p in config.define(pathkey).split(":"):
        local = path.join(path.abspath(p), source["file"])
        if source["local"] is None:
            source["local_prefix"] = path.abspath(p)
            source["local"] = local
        if path.exists(local):
            source["local_prefix"] = path.abspath(p)
            source["local"] = local
            break
    source["script"] = ""
    for p in parsers:
        if url.startswith(p):
            source["type"] = p
            if parsers[p](source, config, opts):
                break
    return source
def parse_url(url, pathkey, config, opts):
    #
    # Split the source up into the parts we need.
    #
    source = {}
    source['url'] = url
    colon = url.find(':')
    if url[colon + 1:colon + 3] != '//':
        raise error.general('malforned URL (no protocol prefix): %s' % (url))
    source['path'] = url[:colon + 3] + path.dirname(url[colon + 3:])
    source['file'] = path.basename(url)
    source['name'], source['ext'] = path.splitext(source['file'])
    if source['name'].endswith('.tar'):
        source['name'] = source['name'][:-4]
        source['ext'] = '.tar' + source['ext']
    #
    # Get the file. Checks the local source directory first.
    #
    source['local'] = None
    for p in parsers:
        if url.startswith(p):
            source['type'] = p
            if parsers[p](source, pathkey, config, opts):
                break
    source['script'] = ''
    return source
Beispiel #8
0
def parse_url(url, pathkey, config, opts):
    #
    # Split the source up into the parts we need.
    #
    source = {}
    source['url'] = url
    source['path'] = path.dirname(url)
    source['file'] = path.basename(url)
    source['name'], source['ext'] = path.splitext(source['file'])
    #
    # Get the file. Checks the local source directory first.
    #
    source['local'] = None
    for p in config.define(pathkey).split(':'):
        local = path.join(path.abspath(p), source['file'])
        if source['local'] is None:
            source['local_prefix'] = path.abspath(p)
            source['local'] = local
        if path.exists(local):
            source['local_prefix'] = path.abspath(p)
            source['local'] = local
            break
    source['script'] = ''
    for p in parsers:
        if url.startswith(p):
            source['type'] = p
            if parsers[p](source, config, opts):
                break
    return source
def parse_url(url, pathkey, config, opts):
    #
    # Split the source up into the parts we need.
    #
    source = {}
    source['url'] = url
    colon = url.find(':')
    if url[colon + 1:colon + 3] != '//':
        raise error.general('malforned URL (no protocol prefix): %s' % (url))
    source['path'] = url[:colon + 3] + path.dirname(url[colon + 3:])
    source['file'] = path.basename(url)
    source['name'], source['ext'] = path.splitext(source['file'])
    if source['name'].endswith('.tar'):
        source['name'] = source['name'][:-4]
        source['ext'] = '.tar' + source['ext']
    #
    # Get the file. Checks the local source directory first.
    #
    source['local'] = None
    for p in parsers:
        if url.startswith(p):
            source['type'] = p
            if parsers[p](source, pathkey, config, opts):
                break
    source['script'] = ''
    return source
Beispiel #10
0
def run(args):
    try:
        optargs = {
            '--list-bsets': 'List available build sets',
            '--list-configs': 'List available configurations',
            '--format': 'Output format (text, html, asciidoc, ini, xml)',
            '--output': 'File name to output the report'
        }
        opts = options.load(args, optargs)
        if opts.get_arg('--output') and len(opts.params()) > 1:
            raise error.general(
                '--output can only be used with a single config')
        print 'RTEMS Source Builder, Reporter v%s' % (version.str())
        opts.log_info()
        if not check.host_setup(opts):
            log.warning('forcing build with known host setup problems')
        configs = build.get_configs(opts)
        if not setbuilder.list_bset_cfg_files(opts, configs):
            output = opts.get_arg('--output')
            if output is not None:
                output = output[1]
            formatter = text_formatter()
            format_opt = opts.get_arg('--format')
            if format_opt:
                if len(format_opt) != 2:
                    raise error.general('invalid format option: %s' %
                                        ('='.join(format_opt)))
                if format_opt[1] == 'text':
                    pass
                elif format_opt[1] == 'asciidoc':
                    formatter = asciidoc_formatter()
                elif format_opt[1] == 'html':
                    formatter = html_formatter()
                elif format_opt[1] == 'ini':
                    formatter = ini_formatter()
                elif format_opt[1] == 'xml':
                    formatter = xml_formatter()
                else:
                    raise error.general('invalid format: %s' % (format_opt[1]))
            r = report(formatter, configs, opts)
            for _config in opts.params():
                if output is None:
                    outname = path.splitext(_config)[0] + formatter.ext()
                    outname = outname.replace('/', '-')
                else:
                    outname = output
                config = build.find_config(_config, configs)
                if config is None:
                    raise error.general('config file not found: %s' % (inname))
                r.create(config, outname)
            del r
        else:
            raise error.general('invalid config type: %s' % (config))
    except error.general, gerr:
        print gerr
        sys.exit(1)
Beispiel #11
0
def run(args):
    try:
        optargs = { '--list-bsets':   'List available build sets',
                    '--list-configs': 'List available configurations',
                    '--format':       'Output format (text, html, asciidoc, ini)',
                    '--output':       'File name to output the report' }
        opts = options.load(args, optargs)
        if opts.get_arg('--output') and len(opts.params()) > 1:
            raise error.general('--output can only be used with a single config')
        print 'RTEMS Source Builder, Reporter v%s' % (version.str())
        opts.log_info()
        if not check.host_setup(opts):
            log.warning('forcing build with known host setup problems')
        configs = build.get_configs(opts)
        if not setbuilder.list_bset_cfg_files(opts, configs):
            output = opts.get_arg('--output')
            if output is not None:
                output = output[1]
            format = 'text'
            ext = '.txt'
            format_opt = opts.get_arg('--format')
            if format_opt:
                if len(format_opt) != 2:
                    raise error.general('invalid format option: %s' % ('='.join(format_opt)))
                if format_opt[1] == 'text':
                    pass
                elif format_opt[1] == 'asciidoc':
                    format = 'asciidoc'
                    ext = '.txt'
                elif format_opt[1] == 'html':
                    format = 'html'
                    ext = '.html'
                elif format_opt[1] == 'ini':
                    format = 'ini'
                    ext = '.ini'
                else:
                    raise error.general('invalid format: %s' % (format_opt[1]))
            r = report(format, configs, opts)
            for _config in opts.params():
                if output is None:
                    outname = path.splitext(_config)[0] + ext
                    outname = outname.replace('/', '-')
                else:
                    outname = output
                config = build.find_config(_config, configs)
                if config is None:
                    raise error.general('config file not found: %s' % (inname))
                r.create(config, outname)
            del r
        else:
            raise error.general('invalid config type: %s' % (config))
    except error.general, gerr:
        print gerr
        sys.exit(1)
def _git_parser(source, config, opts):
    #
    # Symlink.
    #
    us = source["url"].split("?")
    source["path"] = path.dirname(us[0])
    source["file"] = path.basename(us[0])
    source["name"], source["ext"] = path.splitext(source["file"])
    if len(us) > 1:
        source["args"] = us[1:]
    source["local"] = path.join(source["local_prefix"], "git", source["file"])
    source["symlink"] = source["local"]
Beispiel #13
0
def run(args):
    try:
        optargs = {
            "--list-bsets": "List available build sets",
            "--list-configs": "List available configurations",
            "--format": "Output format (text, html, asciidoc)",
            "--output": "File name to output the report",
        }
        opts = options.load(args, optargs)
        if opts.get_arg("--output") and len(opts.params()) > 1:
            raise error.general("--output can only be used with a single config")
        print "RTEMS Source Builder, Reporter v%s" % (version.str())
        opts.log_info()
        if not check.host_setup(opts):
            log.warning("forcing build with known host setup problems")
        configs = build.get_configs(opts)
        if not setbuilder.list_bset_cfg_files(opts, configs):
            output = opts.get_arg("--output")
            if output is not None:
                output = output[1]
            format = "text"
            ext = ".txt"
            format_opt = opts.get_arg("--format")
            if format_opt:
                if len(format_opt) != 2:
                    raise error.general("invalid format option: %s" % ("=".join(format_opt)))
                if format_opt[1] == "text":
                    pass
                elif format_opt[1] == "asciidoc":
                    format = "asciidoc"
                    ext = ".txt"
                elif format_opt[1] == "html":
                    format = "html"
                    ext = ".html"
                else:
                    raise error.general("invalid format: %s" % (format_opt[1]))
            r = report(format, configs, opts)
            for _config in opts.params():
                if output is None:
                    outname = path.splitext(_config)[0] + ext
                    outname = outname.replace("/", "-")
                else:
                    outname = output
                config = build.find_config(_config, configs)
                if config is None:
                    raise error.general("config file not found: %s" % (inname))
                r.create(config, outname)
            del r
        else:
            raise error.general("invalid config type: %s" % (config))
    except error.general, gerr:
        print gerr
        sys.exit(1)
def _git_parser(source, config, opts):
    #
    # Symlink.
    #
    us = source['url'].split('?')
    source['path'] = path.dirname(us[0])
    source['file'] = path.basename(us[0])
    source['name'], source['ext'] = path.splitext(source['file'])
    if len(us) > 1:
        source['args'] = us[1:]
    source['local'] = \
        path.join(source['local_prefix'], 'git', source['file'])
    source['symlink'] = source['local']
def _git_parser(source, config, opts):
    #
    # Symlink.
    #
    us = source['url'].split('?')
    source['path'] = path.dirname(us[0])
    source['file'] = path.basename(us[0])
    source['name'], source['ext'] = path.splitext(source['file'])
    if len(us) > 1:
        source['args'] = us[1:]
    source['local'] = \
        path.join(source['local_prefix'], 'git', source['file'])
    source['symlink'] = source['local']
 def load(self):
     #
     # If the build set file ends with .cfg the user has passed to the
     # buildset builder a configuration so we just return it.
     #
     if self.bset.endswith('.cfg'):
         configs = [self.bset]
     else:
         exbset = self.macros.expand(self.bset)
         self.macros['_bset'] = exbset
         self.macros['_bset_tmp'] = build.short_name(exbset)
         root, ext = path.splitext(exbset)
         if exbset.endswith('.bset'):
             bset = exbset
         else:
             bset = '%s.bset' % (exbset)
         configs = self.parse(bset)
     return configs
    def load(self):

        #
        # If the build set file ends with .cfg the user has passed to the
        # buildset builder a configuration so we just return it.
        #
        if self.bset.endswith(".cfg"):
            configs = [self.bset]
        else:
            exbset = self.macros.expand(self.bset)
            self.macros["_bset"] = exbset
            root, ext = path.splitext(exbset)
            if exbset.endswith(".bset"):
                bset = exbset
            else:
                bset = "%s.bset" % (exbset)
            configs = self.parse(bset)
        return configs
    def load(self):

        #
        # If the build set file ends with .cfg the user has passed to the
        # buildset builder a configuration so we just return it.
        #
        if self.bset.endswith('.cfg'):
            configs = [self.bset]
        else:
            exbset = self.macros.expand(self.bset)
            self.macros['_bset'] = exbset
            root, ext = path.splitext(exbset)
            if exbset.endswith('.bset'):
                bset = exbset
            else:
                bset = '%s.bset' % (exbset)
            configs = self.parse(bset)
        return configs
Beispiel #19
0
def parse_url(url, pathkey, config, opts, file_override=None):
    #
    # Split the source up into the parts we need.
    #
    source = {}
    source['url'] = url
    source['options'] = []
    colon = url.find(':')
    if url[colon + 1:colon + 3] != '//':
        raise error.general('malforned URL (no protocol prefix): %s' % (url))
    source['path'] = url[:colon + 3] + path.dirname(url[colon + 3:])
    if file_override is None:
        source['file'] = path.basename(url)
    else:
        bad_chars = [c for c in ['/', '\\', '?', '*'] if c in file_override]
        if len(bad_chars) > 0:
            raise error.general('bad characters in file name: %s' %
                                (file_override))

        log.output('download: file-override: %s' % (file_override))
        source['file'] = file_override
        source['options'] += ['file-override']
    source['name'], source['ext'] = path.splitext(source['file'])
    if source['name'].endswith('.tar'):
        source['name'] = source['name'][:-4]
        source['ext'] = '.tar' + source['ext']
    #
    # Get the file. Checks the local source directory first.
    #
    source['local'] = None
    for p in parsers:
        if url.startswith(p):
            source['type'] = p
            if parsers[p](source, pathkey, config, opts):
                break
    source['script'] = ''
    return source
Beispiel #20
0
def parse_url(url, pathkey, config, opts):
    #
    # Split the source up into the parts we need.
    #
    source = {}
    source['url'] = url
    colon = url.find(':')
    if url[colon + 1:colon + 3] != '//':
        raise error.general('malforned URL: %s' % (url))
    source['path'] = url[:colon + 3] + path.dirname(url[colon + 3:])
    source['file'] = path.basename(url)
    source['name'], source['ext'] = path.splitext(source['file'])
    if source['name'].endswith('.tar'):
        source['name'] = source['name'][:-4]
        source['ext'] = '.tar' + source['ext']
    #
    # Get the file. Checks the local source directory first.
    #
    source['local'] = None
    for p in config.define(pathkey).split(':'):
        local = path.join(path.abspath(p), source['file'])
        if source['local'] is None:
            source['local_prefix'] = path.abspath(p)
            source['local'] = local
        if path.exists(local):
            source['local_prefix'] = path.abspath(p)
            source['local'] = local
            _hash_check(source['file'], local, config.macros)
            break
    source['script'] = ''
    for p in parsers:
        if url.startswith(p):
            source['type'] = p
            if parsers[p](source, config, opts):
                break
    return source
Beispiel #21
0
def check_orphans(opts):

    def _find_files(path, globs, excludes = []):
        ff = []
        for root, dirs, files in os.walk(path, followlinks = True):
            for f in files:
                for g in globs:
                    if fnmatch.fnmatch(f, g) and f not in excludes:
                        ff += [os.path.join(root, f)]
        return sorted(ff)

    def _clean(line):
        line = line[0:-1]
        b = line.find('#')
        if b >= 0:
            line = line[1:b]
        return line.strip()

    def _find(name, opts):
        ename = opts.defaults.expand(name)
        if ':' in ename:
            paths = path.dirname(ename).split(':')
            name = path.basename(name)
        else:
            paths = opts.defaults.get_value('_configdir').split(':')
        for p in paths:
            n = path.join(opts.defaults.expand(p), name)
            if path.exists(n):
                return n
        return None

    paths = opts.defaults.get_value('_configdir').split(':')

    cfgs = {}
    for p in paths:
        ep = opts.defaults.expand(p)
        print('Scanning: %s (%s)' % (p, ep))
        for f in _find_files(ep, ['*.cfg', '*.bset']):
            root, ext = path.splitext(f)
            cfgs[f] = { 'src': None, 'ext': ext, 'refs': 0, 'errors':[] }

    wss = re.compile(r'\s+')

    for c in cfgs:
        with open(c, 'r') as f:
            cfgs[c]['src'] = f.readlines()
        lc = 0
        for l in cfgs[c]['src']:
            lc += 1
            l = _clean(l)
            if len(l) == 0:
                continue
            if l[0] == '%':
                ls = wss.split(l, 2)
                if ls[0] == '%include':
                    name = _find(ls[1], opts)
                    if name is None:
                        cfgs[c]['errors'] += [lc]
                    elif name not in cfgs:
                        raise error.general('include: %s: not present' % (ls[1]))
                    else:
                        cfgs[name]['refs'] += 1
            elif cfgs[c]['ext'] == '.bset' and ':' not in l:
                for ext in ['', '.cfg', '.bset']:
                    name = _find(l + ext, opts)
                    if name is not None:
                        if name not in cfgs:
                            raise error.general('include: %s: not present' % (ls[1]))
                        else:
                            cfgs[name]['refs'] += 1
                        break

    topdir = opts.defaults.expand('%{_topdir}')

    orphans = []
    show = True

    for c in cfgs:
        if cfgs[c]['refs'] == 0:
            orphans += [c]
        if len(cfgs[c]['errors']) != 0:
            if show:
                print('Warnings:')
                show = False
            print(' %s:' % (path.relpath(c)))
            for l in cfgs[c]['errors']:
                print('  %3d: %s' % (l, cfgs[c]['src'][l - 1][:-1]))

    show = True

    for o in sorted(orphans):
        if show:
            print('Orphans:')
            show = False
        print(' %s' % (path.relpath(o)))
Beispiel #22
0
def check_orphans(opts):
    def _find_files(path, globs, excludes=[]):
        ff = []
        for root, dirs, files in os.walk(path, followlinks=True):
            for f in files:
                for g in globs:
                    if fnmatch.fnmatch(f, g) and f not in excludes:
                        ff += [os.path.join(root, f)]
        return sorted(ff)

    def _clean(line):
        line = line[0:-1]
        b = line.find('#')
        if b >= 0:
            line = line[1:b]
        return line.strip()

    def _find(name, opts):
        ename = opts.defaults.expand(name)
        if ':' in ename:
            paths = path.dirname(ename).split(':')
            name = path.basename(name)
        else:
            paths = opts.defaults.get_value('_configdir').split(':')
        for p in paths:
            n = path.join(opts.defaults.expand(p), name)
            if path.exists(n):
                return n
        return None

    paths = opts.defaults.get_value('_configdir').split(':')

    cfgs = {}
    for p in paths:
        ep = opts.defaults.expand(p)
        print('Scanning: %s (%s)' % (p, ep))
        for f in _find_files(ep, ['*.cfg', '*.bset']):
            root, ext = path.splitext(f)
            cfgs[f] = {'src': None, 'ext': ext, 'refs': 0, 'errors': []}

    wss = re.compile(r'\s+')

    for c in cfgs:
        with open(c, 'r') as f:
            cfgs[c]['src'] = f.readlines()
        lc = 0
        for l in cfgs[c]['src']:
            lc += 1
            l = _clean(l)
            if len(l) == 0:
                continue
            if l[0] == '%':
                ls = wss.split(l, 2)
                if ls[0] == '%include':
                    name = _find(ls[1], opts)
                    if name is None:
                        cfgs[c]['errors'] += [lc]
                    elif name not in cfgs:
                        raise error.general('include: %s: not present' %
                                            (ls[1]))
                    else:
                        cfgs[name]['refs'] += 1
            elif cfgs[c]['ext'] == '.bset' and ':' not in l:
                for ext in ['', '.cfg', '.bset']:
                    name = _find(l + ext, opts)
                    if name is not None:
                        if name not in cfgs:
                            raise error.general('include: %s: not present' %
                                                (ls[1]))
                        else:
                            cfgs[name]['refs'] += 1
                        break

    topdir = opts.defaults.expand('%{_topdir}')

    orphans = []
    show = True

    for c in cfgs:
        if cfgs[c]['refs'] == 0:
            orphans += [c]
        if len(cfgs[c]['errors']) != 0:
            if show:
                print('Warnings:')
                show = False
            print(' %s:' % (path.relpath(c)))
            for l in cfgs[c]['errors']:
                print('  %3d: %s' % (l, cfgs[c]['src'][l - 1][:-1]))

    show = True

    for o in sorted(orphans):
        if show:
            print('Orphans:')
            show = False
        print(' %s' % (path.relpath(o)))
def _tree_name(path_):
    return path.splitext(path.basename(path_))[0]
def run(args):
    try:
        optargs = {
            '--list-bsets': 'List available build sets',
            '--list-configs': 'List available configurations',
            '--format': 'Output format (text, html, markdown, ini, xml)',
            '--output': 'File name to output the report',
            '--sanitize': 'Remove Remotes information from report'
        }
        opts = options.load(args, optargs, logfile=False)
        if opts.get_arg('--output') and len(opts.params()) > 1:
            raise error.general(
                '--output can only be used with a single config')
        print('RTEMS Source Builder, Reporter, %s' % (version.string()))
        opts.log_info()
        if not check.host_setup(opts):
            log.warning('forcing build with known host setup problems')
        configs = build.get_configs(opts)
        if not setbuilder.list_bset_cfg_files(opts, configs):
            output = opts.get_arg('--output')
            if output is not None:
                output = output[1]
            formatter = text_formatter()
            format_opt = opts.get_arg('--format')
            if format_opt:
                if len(format_opt) != 2:
                    raise error.general('invalid format option: %s' %
                                        ('='.join(format_opt)))
                if format_opt[1] == 'text':
                    pass
                elif format_opt[1] == 'markdown':
                    formatter = markdown_formatter()
                elif format_opt[1] == 'html':
                    formatter = html_formatter()
                elif format_opt[1] == 'ini':
                    formatter = ini_formatter()
                elif format_opt[1] == 'xml':
                    formatter = xml_formatter()
                else:
                    raise error.general('invalid format: %s' % (format_opt[1]))
            sanitize = False
            if opts.get_arg('--sanitize'):
                sanitize = True
            r = report(formatter, sanitize, configs, opts)
            for _config in opts.params():
                if output is None:
                    outname = path.splitext(_config)[0] + formatter.ext()
                    outname = outname.replace('/', '-')
                else:
                    outname = output
                config = build.find_config(_config, configs)
                if config is None:
                    raise error.general('config file not found: %s' %
                                        (_config))
                r.create(config, outname)
            del r
    except error.general as gerr:
        print(gerr)
        sys.exit(1)
    except error.internal as ierr:
        print(ierr)
        sys.exit(1)
    except error.exit as eerr:
        pass
    except KeyboardInterrupt:
        log.notice('abort: user terminated')
        sys.exit(1)
    sys.exit(0)
Beispiel #25
0
def _tree_name(path_):
    return path.splitext(path.basename(path_))[0]
Beispiel #26
0
def run(args):
    try:
        optargs = { '--list-bsets':   'List available build sets',
                    '--list-configs': 'List available configurations',
                    '--format':       'Output format (text, html, markdown, ini, xml)',
                    '--output':       'File name to output the report' }
        opts = options.load(args, optargs, logfile = False)
        if opts.get_arg('--output') and len(opts.params()) > 1:
            raise error.general('--output can only be used with a single config')
        print('RTEMS Source Builder, Reporter, %s' % (version.str()))
        opts.log_info()
        if not check.host_setup(opts):
            log.warning('forcing build with known host setup problems')
        configs = build.get_configs(opts)
        if not setbuilder.list_bset_cfg_files(opts, configs):
            output = opts.get_arg('--output')
            if output is not None:
                output = output[1]
            formatter = text_formatter()
            format_opt = opts.get_arg('--format')
            if format_opt:
                if len(format_opt) != 2:
                    raise error.general('invalid format option: %s' % ('='.join(format_opt)))
                if format_opt[1] == 'text':
                    pass
                elif format_opt[1] == 'markdown':
                    formatter = markdown_formatter()
                elif format_opt[1] == 'html':
                    formatter = html_formatter()
                elif format_opt[1] == 'ini':
                    formatter = ini_formatter()
                elif format_opt[1] == 'xml':
                    formatter = xml_formatter()
                else:
                    raise error.general('invalid format: %s' % (format_opt[1]))
            r = report(formatter, configs, opts)
            for _config in opts.params():
                if output is None:
                    outname = path.splitext(_config)[0] + formatter.ext()
                    outname = outname.replace('/', '-')
                else:
                    outname = output
                config = build.find_config(_config, configs)
                if config is None:
                    raise error.general('config file not found: %s' % (_config))
                r.create(config, outname)
            del r
        else:
            raise error.general('invalid config type: %s' % (config))
    except error.general as gerr:
        print(gerr)
        sys.exit(1)
    except error.internal as ierr:
        print(ierr)
        sys.exit(1)
    except error.exit as eerr:
        pass
    except KeyboardInterrupt:
        log.notice('abort: user terminated')
        sys.exit(1)
    sys.exit(0)
Beispiel #27
0
            landmarks[48][0], landmarks[48][1], landmarks[59][0],
            landmarks[59][1])

        eye_distance = cul_distance(landmarks[39][0], landmarks[39][1],
                                    landmarks[42][0], landmarks[42][1])

        base_distance = cul_distance(landmarks[58][0], landmarks[58][0],
                                     landmarks[9][0], landmarks[9][1])
    else:
        pass
    return eye_surrounding, eye_distance, eye_eyebrow, mouse_surrounding, mouse_distance, base_distance


def cul_distance(x1, y1, x2, y2):
    x1 = np.array(x1)
    x2 = np.array(x2)
    y1 = np.array(y1)
    y2 = np.array(y2)
    dis = np.sqrt((x1 - x2)**2 + (y1 - y2)**2)
    return dis


if __name__ == "__main__":
    name = input("名前を入力してください")
    for file in images_list:
        root, exi = path.splitext(images_path + file)
        if exi == ".jpg" or exi == ".png":
            register(images_path + file, name)
        else:
            pass
Beispiel #28
0
import os
import path

files = [
    src + '\\' + file_ for src, dir_, files in os.walk(os.getcwd() + '\\music')
    for file_ in files if file_.endswith('.mp3')
]
print(files, '\n')
f = open('music\\music.txt', 'r', encoding='utf-8')
txt = [line.rstrip('\n') for line in f]
index = 0
for line in txt:
    name = path.splitext(path.basename(files[index]))[0]
    if name in line:
        os.rename(f'music\\{name}.mp3', f'music\\{line}.mp3')
    index += 1
files = [
    src + '\\' + file_ for src, dir_, files in os.walk(os.getcwd() + '\\music')
    for file_ in files if file_.endswith('.mp3')
]
print(files)
f.close()