Xorn
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
Classes | Functions | Variables
xorn.geda.clib Namespace Reference

The component library system. More...

Classes

class  CommandSource
 Source object representing a pair of symbol-generating commands. More...
 
class  DirectorySource
 Source object representing a directory of symbol files. More...
 

Functions

def sym_filename_filter
 Decide based on filename whether a file in a directory source is considered a symbol. More...
 
def add_source
 Add a component source to the library. More...
 
def lookup_source
 Get a component source by name. More...
 
def uniquify_source_name
 Make sure a source name is unique. More...
 
def refresh
 Rescan all available component libraries. More...
 
def reset
 Remove all component library sources. More...
 
def get_symbol
 Get symbol object for a given source object and symbol name. More...
 
def invalidate_symbol_data
 Invalidate cached data about a symbol. More...
 
def search
 Find all symbols matching a pattern. More...
 
def lookup_symbol_source
 Get source for a given symbol name. More...
 
def lookup_symbol
 Get symbol object for a given symbol name. More...
 
def used_symbols0
 Return a list of symbols used in a revision. More...
 
def used_symbols1
 Return a list of symbols used in a revision. More...
 

Variables

tuple Source = collections.namedtuple('Source', ['callback', 'symbols', 'name'])
 Named tuple class for storing data about a particular component source. More...
 
list _sources = []
 List of source triples for all known component sources. More...
 
dictionary _search_cache = {}
 Cache for search results of search. More...
 
dictionary _symbol_cache = {}
 Symbol data cache. More...
 
 load_pixmaps = False
 Whether to load pixmaps referenced by symbols. More...
 

Detailed Description

The component library system.

The component library is made up of a number of component sources, each of which in turn makes available a number of component symbols. Each source is represented by a Python object which implements the methods list() to retrieve a list of symbol names, and get(symbol) to retrieve the symbol data for a given symbol name.

There are two predefined source types: a DirectorySource represents a directory on disk containing symbol files, and a CommandSource represents a command in the system PATH which can generate gEDA symbol data (e.g. from a database).

Each symbol is identified by its name, which is stored in the saved schematic file. The name must be valid for storage in a gEDA schematic file as the "basename" of a "component" object. For symbols from directory sources, the filename of the symbol is taken as the symbol name. For a command source, the name may be any permissible string. Guidelines to follow:

  1. Do not begin a symbol name with "EMBEDDED"
  2. Do not use whitespace, or any of the characters "/", ":", "!", "*", or "?".
  3. Try to use unique names.

The component database may be queried using search. A revision object containing the symbol data may be obtained using get_symbol. If the source of a symbol isn't known, the symbol data may be requested using the convenience function lookup_symbol.

Function Documentation

def xorn.geda.clib.add_source (   callback,
  name 
)

Add a component source to the library.

callback must implement two methods: callback.list() to return a list of symbol names, and callback.get(symbol) to return the symbol data for a given a symbol name.

Parameters
callbacksource object which implements list and get
nameunique descriptive name for the component source
Exceptions
ValueErrorif another source with this name already exists

Definition at line 285 of file clib.py.

def xorn.geda.clib.get_symbol (   source,
  symbol 
)

Get symbol object for a given source object and symbol name.

Returns a xorn.geda.ref.Symbol object containing the symbol called symbol from the component source source.

Exceptions
ValueErrorif the source object's get function doesn't return a xorn.storage.Revision or xorn.proxy.RevisionProxy instance

Definition at line 364 of file clib.py.

def xorn.geda.clib.invalidate_symbol_data (   source,
  symbol 
)

Invalidate cached data about a symbol.

Definition at line 392 of file clib.py.

def xorn.geda.clib.lookup_source (   name)

Get a component source by name.

Iterates through the known component sources, checking if there is a source with the given name.

Exceptions
ValueErrorif no matching source was found

Definition at line 307 of file clib.py.

def xorn.geda.clib.lookup_symbol (   name)

Get symbol object for a given symbol name.

Returns the xorn.geda.ref.Symbol object for the first symbol found with the given name. This is a helper function for the schematic load system, as it will always want to load symbols given only their name.

Exceptions
ValueErrorif the component was not found

Definition at line 456 of file clib.py.

def xorn.geda.clib.lookup_symbol_source (   name)

Get source for a given symbol name.

Returns the source of the first symbol found with the given name. If more than one matching symbol is found, emits a warning to stderr.

Exceptions
ValueErrorif the component was not found

Definition at line 432 of file clib.py.

def xorn.geda.clib.refresh ( )

Rescan all available component libraries.

Resets the list of symbols available from each source, and repopulates it from scratch. Useful e.g. for checking for new symbols.

Definition at line 340 of file clib.py.

def xorn.geda.clib.reset ( )

Remove all component library sources.

Definition at line 349 of file clib.py.

def xorn.geda.clib.search (   pattern,
  glob = False 
)

Find all symbols matching a pattern.

Searches the library, returning all symbols whose names match pattern. If glob is True, then pattern is assumed to be a glob pattern; otherwise, only exact matches are returned.

Returns
a list of pairs (source, symbol)

Definition at line 407 of file clib.py.

def xorn.geda.clib.sym_filename_filter (   basename)

Decide based on filename whether a file in a directory source is considered a symbol.

Definition at line 62 of file clib.py.

def xorn.geda.clib.uniquify_source_name (   name)

Make sure a source name is unique.

Checks if a source with the given name already exists. If it does, appends a number in angular brackets to the source name making it unique. If name is not already in use, returns it as is.

Definition at line 320 of file clib.py.

def xorn.geda.clib.used_symbols0 (   rev)

Return a list of symbols used in a revision.

The list is free of duplicates and preserves the order of the symbols as they appear first in the file. Each symbol is represented by its actual xorn.geda.ref.Symbol object.

Definition at line 466 of file clib.py.

def xorn.geda.clib.used_symbols1 (   rev)

Return a list of symbols used in a revision.

Scan a revision looking for symbols, look them up in the library, and return them as a list. Each symbol is represented by a pair (source, symbol). The returned list only contains symbols that were found in the library and is sorted in alphabetical order.

Bug:
Only includes components which are not embedded, but they should (probably) also appear in the list.

Definition at line 485 of file clib.py.

Variable Documentation

dictionary xorn.geda.clib._search_cache = {}

Cache for search results of search.

The key of the hashtable is a pair (pattern, glob) describing the search that was carried out, and the value is a list of pairs (source, symbol).

Definition at line 80 of file clib.py.

list xorn.geda.clib._sources = []

List of source triples for all known component sources.

Definition at line 72 of file clib.py.

dictionary xorn.geda.clib._symbol_cache = {}

Symbol data cache.

The key of the hashtable is a pair (source, symbol), and the value is the data.

Definition at line 87 of file clib.py.

xorn.geda.clib.load_pixmaps = False

Whether to load pixmaps referenced by symbols.

This should be set before reading any symbols. Otherwise, cached symbols loaded with the wrong load_pixmaps flag may be returned.

Definition at line 94 of file clib.py.

tuple xorn.geda.clib.Source = collections.namedtuple('Source', ['callback', 'symbols', 'name'])

Named tuple class for storing data about a particular component source.

Definition at line 68 of file clib.py.