How to use the kicost.sexpdata.Symbol function in kicost

To help you get started, we’ve selected a few kicost examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github xesscorp / KiCost / kicost / kicad_config.py View on Github external
if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
            name = name.replace("\\",'/')
        for plugin in bom_list[1:]:
            search = plugin[1]
            if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
                search = plugin[1].replace("\\",'/')
            if re.findall(name, search, re_flags):
                if not nickname:
                    return # Plugin already added and don't have nickname.
                for entry in plugin[2:]:
                    if entry[0]==sexpdata.Symbol('opts') and\
                        re.findall('nickname\s*=\s*'+nickname, entry[1], re_flags):
                            return # Plugin already added with this nickname.
            new_list.append(plugin)
    if not nickname:
        new_list.append([sexpdata.Symbol('plugin'), sexpdata.Symbol(name), [sexpdata.Symbol('cmd'), cmd]])
    else:
        new_list.append([sexpdata.Symbol('plugin'), name,
                        [sexpdata.Symbol('cmd'), cmd],
                        [sexpdata.Symbol('opts'), 'nickname={}'.format(nickname)]] )
    if len(new_list):
        # Put KiCost at first.
        if put_first:
            new_list.insert(1, new_list[-1])
            del new_list[-1]
    config = update_config_file(config, "bom_plugins", escape( sexpdata.dumps(new_list) ))
    write_config_file(PATH_EESCHEMA_CONFIG, config)
    if set_default:
        import fileinput
        for line in fileinput.input(PATH_EESCHEMA_CONFIG, inplace=True):
            if line.strip().startswith('bom_plugin_selected='):
                line = 'bom_plugin_selected={}\n'.format(nickname)
github xesscorp / KiCost / kicost / kicad_config.py View on Github external
if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
                search = plugin[1].replace("\\",'/')
            if re.findall(name, search, re_flags):
                if not nickname:
                    return # Plugin already added and don't have nickname.
                for entry in plugin[2:]:
                    if entry[0]==sexpdata.Symbol('opts') and\
                        re.findall('nickname\s*=\s*'+nickname, entry[1], re_flags):
                            return # Plugin already added with this nickname.
            new_list.append(plugin)
    if not nickname:
        new_list.append([sexpdata.Symbol('plugin'), sexpdata.Symbol(name), [sexpdata.Symbol('cmd'), cmd]])
    else:
        new_list.append([sexpdata.Symbol('plugin'), name,
                        [sexpdata.Symbol('cmd'), cmd],
                        [sexpdata.Symbol('opts'), 'nickname={}'.format(nickname)]] )
    if len(new_list):
        # Put KiCost at first.
        if put_first:
            new_list.insert(1, new_list[-1])
            del new_list[-1]
    config = update_config_file(config, "bom_plugins", escape( sexpdata.dumps(new_list) ))
    write_config_file(PATH_EESCHEMA_CONFIG, config)
    if set_default:
        import fileinput
        for line in fileinput.input(PATH_EESCHEMA_CONFIG, inplace=True):
            if line.strip().startswith('bom_plugin_selected='):
                line = 'bom_plugin_selected={}\n'.format(nickname)
            sys.stdout.write(line)
github xesscorp / KiCost / kicost / kicad_config.py View on Github external
if len(values) == 1:
        values = after(values[0], "FieldNames=")
        values = de_escape(values)
        values = sexpdata.loads(values)
        if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
            name = name.replace("\\",'/')
        for idx, value_modify in enumerate(values_modify):
            value_found = False
            for idx, value in enumerate(values[1:]):
                search = value[1]
                if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
                    search = value[1].replace("\\",'/')
                if re.findall(value_modify, search[1], re_flags):
                    value_found = True
            if not value_found:
                values.append([sexpdata.Symbol('field'), [sexpdata.Symbol('name'), value_modify]])
                changes = True
    if changes:
        s = sexpdata.dumps(values)
        config = update_config_file(config, "FieldNames", escape(s))
    write_config_file(PATH_EESCHEMA_CONFIG, config)
github xesscorp / KiCost / kicost / kicad_config.py View on Github external
def bom_plugin_remove_entry(name, re_flags=re.IGNORECASE):
    '''Remove a BOM plugin entry to the Eeschema configuration file.'''
    config = read_config_file(PATH_EESCHEMA_CONFIG)
    bom_plugins_raw = [p for p in config if p.startswith("bom_plugins")]
    new_list = []
    new_list.append(sexpdata.Symbol("plugins"))
    changes = False
    if len(bom_plugins_raw) == 1:
        bom_plugins_raw = after(bom_plugins_raw[0], "bom_plugins=")
        bom_plugins_raw = de_escape(bom_plugins_raw)
        bom_list = sexpdata.loads(bom_plugins_raw)
        if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
            name = name.replace("\\",'/')
        for plugin in bom_list[1:]:
            search = plugin[1]
            if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
                search = plugin[1].replace("\\",'/')
            if re.findall(name, search, re_flags):
                changes = True # The name in really in the 'name'.
                continue # We want to delete this entry.
            else:
                for entry in plugin[2:]:
github xesscorp / KiCost / kicost / kicad_config.py View on Github external
def bom_plugin_add_entry(name, cmd, nickname=None, re_flags=re.IGNORECASE, put_first=True, set_default=True):
    '''Add a BOM plugin entry to the Eeschema configuration file.'''
    config = read_config_file(PATH_EESCHEMA_CONFIG)
    bom_plugins_raw = [p for p in config if p.startswith("bom_plugins")]
    new_list = []
    new_list.append(sexpdata.Symbol("plugins"))
    if len(bom_plugins_raw)==1:
        bom_plugins_raw = after(bom_plugins_raw[0], "bom_plugins=")
        bom_plugins_raw = de_escape(bom_plugins_raw)
        bom_list = sexpdata.loads(bom_plugins_raw)
        if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
            name = name.replace("\\",'/')
        for plugin in bom_list[1:]:
            search = plugin[1]
            if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
                search = plugin[1].replace("\\",'/')
            if re.findall(name, search, re_flags):
                if not nickname:
                    return # Plugin already added and don't have nickname.
                for entry in plugin[2:]:
                    if entry[0]==sexpdata.Symbol('opts') and\
                        re.findall('nickname\s*=\s*'+nickname, entry[1], re_flags):
github xesscorp / KiCost / kicost / kicad_config.py View on Github external
for plugin in bom_list[1:]:
            search = plugin[1]
            if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
                search = plugin[1].replace("\\",'/')
            if re.findall(name, search, re_flags):
                if not nickname:
                    return # Plugin already added and don't have nickname.
                for entry in plugin[2:]:
                    if entry[0]==sexpdata.Symbol('opts') and\
                        re.findall('nickname\s*=\s*'+nickname, entry[1], re_flags):
                            return # Plugin already added with this nickname.
            new_list.append(plugin)
    if not nickname:
        new_list.append([sexpdata.Symbol('plugin'), sexpdata.Symbol(name), [sexpdata.Symbol('cmd'), cmd]])
    else:
        new_list.append([sexpdata.Symbol('plugin'), name,
                        [sexpdata.Symbol('cmd'), cmd],
                        [sexpdata.Symbol('opts'), 'nickname={}'.format(nickname)]] )
    if len(new_list):
        # Put KiCost at first.
        if put_first:
            new_list.insert(1, new_list[-1])
            del new_list[-1]
    config = update_config_file(config, "bom_plugins", escape( sexpdata.dumps(new_list) ))
    write_config_file(PATH_EESCHEMA_CONFIG, config)
    if set_default:
        import fileinput
        for line in fileinput.input(PATH_EESCHEMA_CONFIG, inplace=True):
            if line.strip().startswith('bom_plugin_selected='):
                line = 'bom_plugin_selected={}\n'.format(nickname)
            sys.stdout.write(line)
github xesscorp / KiCost / kicost / kicad_config.py View on Github external
search = plugin[1]
            if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
                search = plugin[1].replace("\\",'/')
            if re.findall(name, search, re_flags):
                if not nickname:
                    return # Plugin already added and don't have nickname.
                for entry in plugin[2:]:
                    if entry[0]==sexpdata.Symbol('opts') and\
                        re.findall('nickname\s*=\s*'+nickname, entry[1], re_flags):
                            return # Plugin already added with this nickname.
            new_list.append(plugin)
    if not nickname:
        new_list.append([sexpdata.Symbol('plugin'), sexpdata.Symbol(name), [sexpdata.Symbol('cmd'), cmd]])
    else:
        new_list.append([sexpdata.Symbol('plugin'), name,
                        [sexpdata.Symbol('cmd'), cmd],
                        [sexpdata.Symbol('opts'), 'nickname={}'.format(nickname)]] )
    if len(new_list):
        # Put KiCost at first.
        if put_first:
            new_list.insert(1, new_list[-1])
            del new_list[-1]
    config = update_config_file(config, "bom_plugins", escape( sexpdata.dumps(new_list) ))
    write_config_file(PATH_EESCHEMA_CONFIG, config)
    if set_default:
        import fileinput
        for line in fileinput.input(PATH_EESCHEMA_CONFIG, inplace=True):
            if line.strip().startswith('bom_plugin_selected='):
                line = 'bom_plugin_selected={}\n'.format(nickname)
            sys.stdout.write(line)
github xesscorp / KiCost / kicost / kicad_config.py View on Github external
if len(bom_plugins_raw) == 1:
        bom_plugins_raw = after(bom_plugins_raw[0], "bom_plugins=")
        bom_plugins_raw = de_escape(bom_plugins_raw)
        bom_list = sexpdata.loads(bom_plugins_raw)
        if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
            name = name.replace("\\",'/')
        for plugin in bom_list[1:]:
            search = plugin[1]
            if sys.platform.startswith(PLATFORM_WINDOWS_STARTS_WITH):
                search = plugin[1].replace("\\",'/')
            if re.findall(name, search, re_flags):
                changes = True # The name in really in the 'name'.
                continue # We want to delete this entry.
            else:
                for entry in plugin[2:]:
                    if entry[0]==sexpdata.Symbol('opts') and\
                        re.findall('nickname\s*=\s*'+name, entry[1], re_flags):
                            changes = True
                            continue # The name is in the 'nickname'.
                new_list.append(plugin) # This plugin remains on the list.
    if changes:
        s = sexpdata.dumps(new_list)
        config = update_config_file(config, "bom_plugins", escape(s))
    write_config_file(PATH_EESCHEMA_CONFIG, config)