objdictgen/objdictgen.py
author Christian Taedcke <hacking@taedcke.com>
Tue, 08 Nov 2011 08:59:30 +0000
changeset 687 e23df9586397
parent 580 2ae92a99ac10
permissions -rw-r--r--
Win32:
CHANGED: - Switch character encoding to unicode.
- Changed logging format strings from %s to %S.
FIXED: - second argument to swprintf() is now the size of the target buffer

Win32 IXXAT:
CHANGED: - Changed logging format strings from %s to %S.
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
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 512
diff changeset
    29
_ = lambda x: x
2ae92a99ac10 Adding support for internationalization
laurent
parents: 512
diff changeset
    30
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    31
def usage():
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 512
diff changeset
    32
    print _("\nUsage of objdictgen.py :")
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    33
    print "\n   %s XMLFilePath CFilePath\n"%sys.argv[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    34
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    35
try:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    36
    opts, args = getopt.getopt(sys.argv[1:], "h", ["help"])
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    37
except getopt.GetoptError:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    38
    # print help information and exit:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    39
    usage()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    40
    sys.exit(2)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    41
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    42
for o, a in opts:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    43
    if o in ("-h", "--help"):
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    44
        usage()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    45
        sys.exit()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    46
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    47
fileIn = ""
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    48
fileOut = ""        
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    49
if len(args) == 2:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    50
    fileIn = args[0]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    51
    fileOut = args[1]
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    52
else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    53
    usage()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    54
    sys.exit()
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    55
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    56
if __name__ == '__main__':
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    57
    if fileIn != "" and fileOut != "":
283
e0b3096230e5 Fixed typo in objdictgen.py preventing generation of examples' ODs
baf
parents: 199
diff changeset
    58
        manager = NodeManager()
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    59
        if os.path.isfile(fileIn):
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 512
diff changeset
    60
            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
    61
            result = manager.OpenFileInCurrent(fileIn)
512
e84806c0ada4 Some instance type test improved
lbessard
parents: 283
diff changeset
    62
            if not isinstance(result, (StringType, UnicodeType)):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    63
                Node = result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    64
            else:
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    65
                print result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    66
                sys.exit(-1)
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    67
        else:
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 512
diff changeset
    68
            print _("%s is not a valid file!")%fileIn
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    69
            sys.exit(-1)
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 512
diff changeset
    70
        print _("Writing output file")
199
greg
parents: 184
diff changeset
    71
        result = manager.ExportCurrentToCFile(fileOut)
512
e84806c0ada4 Some instance type test improved
lbessard
parents: 283
diff changeset
    72
        if isinstance(result, (UnicodeType, StringType)):
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    73
            print result
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    74
            sys.exit(-1)
580
2ae92a99ac10 Adding support for internationalization
laurent
parents: 512
diff changeset
    75
        print _("All done")
0
4472ee7c6c3e Commit a new cvs repo.
etisserant
parents:
diff changeset
    76