EagleFile Base Class

Swoop provides one class for each of the three Eagle file types: EagleBoard, EagleSchematic, and EagleLibrary. Each of them are subclasses of the EagleFile base class. The base class provides functions for parsing, verifying, and writing Eagle files.

Swoop and the Eagle File Format

Swoop has two goals in terms of conformance to the Eagle file format. The first is that Swoop should be able to read any Eagle file produced by a version of Eagle it supports (currently 6.5-7.2), by Swoop, or by a combination of the two.

Second, Swoop should only output files that conform to a modified version of the DTD. This modified DTD is provided with the Swoop distribution. It is based on the DTD that ships with Eagle, but it includes changes to accomodate files that we observe Eagle to produce in practice. You can see the changes we have made by looking at eagle.dtd.diff in the source distribution of Swoop.

Swoop also aspires to produce output that specifies a valid Eagle schematic, library, or board. This is challenging, since CadSoft doesn’t publish a detailed specification of the file format’s semantics (the DTD just specifies its syntax). By default, EagleFile performs a set of sanity checks before writing out the file. If you find that a file produced by Swoop (with the sanity checks enabled) produces error when loaded by Eagle, please consider filing a bug report.

EagleFile

class Swoop.EagleFile[source]

Bases: Swoop.Swoop.EagleFilePart

Base class for Eagle files. It handle opening, parsing, validation, associated errors, writing output, and the mapping between layer numbers and layer names.

This class also serves a factory class for EagleFilePart objects. Calling the new_*() methods on an EagleFile, yields new objects that include any Swoop extensions that have been applied.

add_layer(layer)[source]

Add a layer to this file.

Parameters:layer – The Layer to add.
Return type:None
find_library_by_name(l)[source]

Lookup a library by name and return it.

Parameters:l – Library name.
Return type:Library or None if the library is not present.
classmethod from_file(filename, bestEffort=True)[source]

Loads a Eagle file from a .sch, .lbr, or .brd file. A synonym for EagleFile.open()

Parameters:
  • filename – Filename to load.
  • bestEffort – If True, load the file even if it doesn’t conform to the DTD.
Returns:

A new BoardFile, LibraryFile, or SchematicFile object

get_layers()[source]

Get a map of names to Layer objects

Return type:Map of EagleFilePart objects keyed by layer name.
get_layersByNumber()[source]

Get a map of numbers to Layer objects.

Return type:Map of EagleFilePart objects keyed by layer number.
layer_name_to_number(name)[source]

Given a layer name, return the number.

Return type:Layer
layer_number_to_name(num)[source]

Given a layer number, return the name.

Return type:Layer
classmethod open(filename, bestEffort=True)[source]

Loads a Eagle file from a .sch, .lbr, or .brd file. A synonym for EagleFile.from_file()

Parameters:
  • filename – Filename to load.
  • bestEffort – If True, load the file even if it doesn’t conform to the DTD.
Returns:

A new BoardFile, LibraryFile, or SchematicFile object

remove_layer(layer)[source]

Remove a layer.

Parameters:layerLayer object, layer name, or layer number that should be deleted.
Return type:None
validate()[source]

Check that this file conforms to the eagle DTD. Return True, if it does, False otherwise.

Return type:Bool
write(file, check_sanity=True, dtd_validate=True)[source]

Exports the Schematic to an EAGLE schematic file.

Parameters:
  • file – Filename or file-like object for output.
  • check_sanity – Perform semantic sanity checks before output.
  • dtd_validate – Check for DTD compliance before output.