1 # gaf.netlist - gEDA Netlist Extraction and Generation
2 # Copyright (C) 1998-2010 Ales Hvezda
3 # Copyright (C) 1998-2010 gEDA Contributors (see ChangeLog for details)
4 # Copyright (C) 2013-2020 Roland Lutz
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.
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.
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.
20 # Copyright (C) 2001-2010 MIYAMOTO Takanori
22 def get_parts_table(netlist
):
23 return [(package
.refdes
,
24 package
.get_attribute('device', 'unknown'),
25 package
.get_attribute('value', 'unknown'),
26 package
.get_attribute('footprint', 'unknown')) # sdb change
27 for package
in reversed(netlist
.packages
)
28 if package
.get_attribute('device', 'unknown') != 'include']
30 def write_one_row(f
, ls
, separator
, end_char
):
32 f
.write(separator
.join(ls
) + end_char
)
34 def marge_sort_sub(ls1
, ls2
, key_column
):
35 if not ls1
or not ls2
:
38 if ls1
[0][key_column
].lower() <= ls2
[0][key_column
].lower():
39 return [ls1
[0]] + marge_sort_sub(ls1
[1:], ls2
, key_column
)
41 return [ls2
[0]] + marge_sort_sub(ls1
, ls2
[1:], key_column
)
43 def marge_sort(ls
, key_column
):
47 return marge_sort_sub(
48 marge_sort(ls
[:len(ls
) - len(ls
) / 2], key_column
),
49 marge_sort(ls
[len(ls
) - len(ls
) / 2:], key_column
), key_column
)
51 def marge_sort_with_multikey(ls
, key_columns
):
52 if len(ls
) <= 1 or not key_columns
:
55 key_column
= key_columns
[0]
56 sorted_ls
= marge_sort(ls
, key_column
)
58 first_value
= sorted_ls
[0][key_column
]
60 for i
, x
in enumerate(reversed(sorted_ls
)):
61 if x
[key_column
] == first_value
:
62 match_length
= len(sorted_ls
) - i
65 return marge_sort_with_multikey(list(reversed(sorted_ls
[:match_length
])),
67 marge_sort_with_multikey(sorted_ls
[match_length
:], key_columns
)