author | greg |
Tue, 19 Feb 2008 14:53:59 +0100 | |
changeset 403 | 57d5da3b6228 |
parent 400 | 7d845f5d730c |
permissions | -rw-r--r-- |
400
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
1 |
#! /usr/bin/env python |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
2 |
# |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
3 |
# -*- coding: iso-8859-1 -*- |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
4 |
# |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
5 |
# |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
6 |
# FILE: EDS2CSV.py |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
7 |
# BEGIN: Nov 30,2007 |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
8 |
# AUTHOR: Giuseppe Massimo Bertani |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
9 |
# EMAIL gmbertani@users.sourceforge.net |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
10 |
# |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
11 |
# This program is free software; you can redistribute it and/or modify |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
12 |
# it under the terms of the GNU General Public License as published by |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
13 |
# the Free Software Foundation; either version 2 of the License, or |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
14 |
# (at your option) any later version. |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
15 |
# |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
16 |
# Coding style params: |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
17 |
# <TAB> skips=4 |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
18 |
# <TAB> are replaced with blanks |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
19 |
# |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
20 |
# |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
21 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
22 |
import sys |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
23 |
import os |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
24 |
import ConfigParser as cp |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
25 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
26 |
if (len(sys.argv) != 2): |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
27 |
print "Usage:" |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
28 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
29 |
print "EDS2CSV.py <input file> " |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
30 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
31 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
32 |
sys.exit(0) |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
33 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
34 |
EDSname = os.path.abspath( os.path.dirname(sys.argv[1]) ) + '/' + sys.argv[1] |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
35 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
36 |
if (os.path.exists(EDSname) is not True): |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
37 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
38 |
print "Input file ",EDS2CSV," not found." |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
39 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
40 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
41 |
sys.exit(0) |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
42 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
43 |
eds = cp.ConfigParser() |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
44 |
eds.read(EDSname) |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
45 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
46 |
ssorted = sorted(eds.sections()) |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
47 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
48 |
# dump entire EDS file to stdout in CSV format comma separated |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
49 |
print "Object Dictionary,",sys.argv[1] |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
50 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
51 |
for section in ssorted: |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
52 |
print section |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
53 |
print ",", |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
54 |
osorted = sorted(eds.options(section)) |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
55 |
for option in osorted: |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
56 |
print option, ",", |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
57 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
58 |
print ",", |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
59 |
for option in osorted: |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
60 |
print eds.get(section, option), ",", |
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
61 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
62 |
|
7d845f5d730c
Added Kvaser hardware support, thanks to Giuseppe Massimo Bertani .
etisserant
parents:
diff
changeset
|
63 |