Changeset e29d0a6 in rtems-tools


Ignore:
Timestamp:
Mar 4, 2020, 5:45:56 PM (4 months ago)
Author:
Amar Takhar <amar@…>
Branches:
5, master
Children:
9c7be8b
Parents:
90713f7
git-author:
Amar Takhar <amar@…> (03/04/20 17:45:56)
git-committer:
Amar Takhar <verm@…> (03/04/20 23:07:37)
Message:

Convert optparse to argparse.

  • Fix exceptions and print exception message.
  • Also add myself to copyright.
File:
1 edited

Legend:

Unmodified
Added
Removed
  • misc/tools/mkimage.py

    r90713f7 re29d0a6  
    44#
    55# Copyright 2010 Craig Barker
     6# Copyright 2020 Amar Takhar <amar@rtems.org>
    67#
    78# Redistribution and use in source and binary forms, with or without
     
    2829
    2930
    30 from optparse import OptionParser
     31import argparse
    3132from struct import *
    3233import sys
     
    5455comps = {'none':0, 'bzip2':2, 'gzip':1, 'lzma':3 }
    5556
    56 usage = "usage: %prog [options] image"
    57 parser = OptionParser(usage=usage)
    58 parser.add_option("-A","--arch", dest="arch", default="powerpc",
     57parser = argparse.ArgumentParser()
     58
     59parser.add_argument("-A","--arch", dest="arch", default="powerpc",
    5960                  help="set architecture to 'arch'", metavar="ARCH")
    60 parser.add_option("-O","--os", dest="os", default="linux",
     61parser.add_argument("-O","--os", dest="os", default="linux",
    6162                  help="set operating system to 'os'", metavar="OS")
    62 parser.add_option("-T","--type", dest="type", default="kernel",
     63parser.add_argument("-T","--type", dest="type", default="kernel",
    6364                  help="set image type to 'type'", metavar="TYPE")
    64 parser.add_option("-C","--comp", dest="comp", default="gzip",
     65parser.add_argument("-C","--comp", dest="comp", default="gzip",
    6566                  help="set compression type 'comp'", metavar="COMP")
    66 parser.add_option("-a","--addr", dest="addr", default="0",
     67parser.add_argument("-a","--addr", dest="addr", default="0",
    6768                  help="set load address to 'addr' (hex)", metavar="ADDR")
    68 parser.add_option("-e","--ep", dest="ep", default="0",
     69parser.add_argument("-e","--ep", dest="ep", default="0",
    6970                  help="set entry point to 'ep' (hex)", metavar="EP")
    70 parser.add_option("-n","--name", dest="name", default="",
     71parser.add_argument("-n","--name", dest="name", default="",
    7172                  help="set image name to 'name'", metavar="NAME")
    72 parser.add_option("-d","--datafile", dest="datafile",
    73                   help="use image data from 'datafile'", metavar="DATAFILE")
    74 parser.add_option("-x","--xip", action="store_true", dest="xip", default=False,
     73parser.add_argument("-d","--datafile", dest="datafile",
     74                  help="use image data from 'datafile'", metavar="DATAFILE", required=True)
     75parser.add_argument("-x","--xip", action="store_true", dest="xip", default=False,
    7576                  help="set XIP (execute in place)")
     77parser.add_argument("outputfile",
     78                  help="Output file.", metavar="OUTPUTFILE")
    7679
    77 (options, args) = parser.parse_args()
    7880
    79 if len(args) != 1: parser.print_help()
     81options = parser.parse_args()
    8082
    8183if options.arch not in archs:
     
    99101        inputfile = open(options.datafile, 'rb')
    100102
    101 except IOError:
    102         print "Invalid datafile specified, aborting"
     103except OSError as e:
     104        print "Invalid datafile specified, aborting: %s" % e
    103105        sys.exit(2)
    104106
    105107try:
    106         outputfile = open(args[0],'wb')
     108        outputfile = open(options.outputfile,'wb')
    107109
    108 except IOError:
    109         print "Error opening output file for writing, aborting"
     110except IOError as e:
     111        print "Error opening output file for writing, aborting: %s" % e
    110112        sys.exit(1)
    111113
Note: See TracChangeset for help on using the changeset viewer.