objdictgen/objdictgen.py
author lbessard
Tue, 29 Apr 2008 13:50:56 +0200
changeset 452 9b67c71adbb7
parent 283 e0b3096230e5
child 512 e84806c0ada4
permissions -rw-r--r--
Inversion between Array and Record fixed
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     1
#!/usr/bin/env python
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     2
# -*- coding: utf-8 -*-
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     3
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     4
#This file is part of CanFestival, a library implementing CanOpen Stack. 
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     5
#
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     6
#Copyright (C): Edouard TISSERANT, Francis DUPIN and Laurent BESSARD
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     7
#
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     8
#See COPYING file for copyrights details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
     9
#
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    10
#This library is free software; you can redistribute it and/or
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    11
#modify it under the terms of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    12
#License as published by the Free Software Foundation; either
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    13
#version 2.1 of the License, or (at your option) any later version.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    14
#
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    15
#This library is distributed in the hope that it will be useful,
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    16
#but WITHOUT ANY WARRANTY; without even the implied warranty of
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    17
#MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    18
#Lesser General Public License for more details.
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    19
#
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    20
#You should have received a copy of the GNU Lesser General Public
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    21
#License along with this library; if not, write to the Free Software
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    22
#Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    23
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    24
import getopt,sys,os
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    25
from types import *
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    26
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    27
from nodemanager import *
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    28
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    29
def usage():
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    30
    print "\nUsage of objdictgen.py :"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
    print "\n   %s XMLFilePath CFilePath\n"%sys.argv[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    32
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
try:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
    opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
except getopt.GetoptError:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
    # print help information and exit:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
    usage()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
    sys.exit(2)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
for o, a in opts:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
    if o in ("-h", "--help"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
        usage()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
        sys.exit()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
fileIn = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
fileOut = ""        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
if len(args) == 2:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
    fileIn = args[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
    fileOut = args[1]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
    usage()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
    sys.exit()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
if __name__ == '__main__':
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
    if fileIn != "" and fileOut != "":
283
e0b3096230e5 Fixed typo in objdictgen.py preventing generation of examples' ODs
baf
parents: 199
diff changeset
    56
        manager = NodeManager()
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
        if os.path.isfile(fileIn):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    58
            print "Parsing input file"
93
16c8ceea8f18 Removed all non-supported and uncontrolled source code. Please refer to CVS version "Before_..." to see old code.
etisserant
parents: 0
diff changeset
    59
            result = manager.OpenFileInCurrent(fileIn)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    60
            if type(result) != UnicodeType:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    61
                Node = result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    62
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
                print result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
                sys.exit(-1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
        else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
            print "%s is not a valid file!"%fileIn
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
            sys.exit(-1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    68
        print "Writing output file"
199
greg
parents: 184
diff changeset
    69
        result = manager.ExportCurrentToCFile(fileOut)
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    70
        if type(result) == UnicodeType:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    71
            print result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    72
            sys.exit(-1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
        print "All done"
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74