Xorn
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Pages
write.py
Go to the documentation of this file.
1 # xorn.geda - Python library for manipulating gEDA files
2 # Copyright (C) 1998-2010 Ales Hvezda
3 # Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
4 # Copyright (C) 2013-2016 Roland Lutz
5 #
6 # This program is free software; you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation; either version 2 of the License, or
9 # (at your option) any later version.
10 #
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
15 #
16 # You should have received a copy of the GNU General Public License
17 # along with this program; if not, write to the Free Software Foundation,
18 # Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
19 
20 ## \namespace xorn.geda.write
21 ## Writing schematic/symbol files.
22 
23 import xorn.fileutils
26 import xorn.geda.xmlwrite
27 
28 ## Save a symbol or schematic file.
29 #
30 # See \ref xorn.fileutils.write for a description of the keyword
31 # arguments.
32 #
33 # \returns \c None
34 #
35 # \throws xorn.geda.fileformat.UnknownFormatError
36 # \throws IOError, OSError if a filesystem error occurred
37 # \throws ValueError if an object with an unknown type is encountered
38 
39 def write(rev, filename, format = None, write_kwds = {}, **format_kwds):
40  if format is None:
42 
43  def write_func(f):
44  write_file(f, rev, format, **format_kwds)
45 
46  xorn.fileutils.write(filename, write_func, **write_kwds)
47 
48 ## Write a symbol or schematic to a file.
49 #
50 # \param [in] f A file-like object to which to write
51 # \param [in] rev The symbol or schematic which should be written
52 #
53 # \returns \c None
54 #
55 # \throws ValueError if \a format is not a valid file format
56 # \throws ValueError if an object with an unknown type is encountered
57 
58 def write_file(f, rev, format, **kwds):
59  if format == xorn.geda.fileformat.FORMAT_SYM or \
60  format == xorn.geda.fileformat.FORMAT_SCH:
61  return xorn.geda.plainwrite.write_file(f, rev, **kwds)
62  if format == xorn.geda.fileformat.FORMAT_SYM_XML or \
63  format == xorn.geda.fileformat.FORMAT_SCH_XML:
65  f, rev, format == xorn.geda.fileformat.FORMAT_SYM_XML, **kwds)
66  raise ValueError
File formats.
Definition: fileformat.py:1
Writing files in a safe way.
Definition: fileutils.py:1
def write_file
Write a symbol or schematic to a file in libgeda format.
Definition: plainwrite.py:55
def write
Save a symbol or schematic file.
Definition: write.py:39
Writing gEDA schematic/symbol files.
Definition: plainwrite.py:1
def write
Write some data to a file in a reasonably safe way.
Definition: fileutils.py:132
Writing gEDA schematic/symbol files in XML format.
Definition: xmlwrite.py:1
def write_file
Write a symbol or schematic to a file.
Definition: write.py:58