Mercurial > lcfOS
comparison python/hexutil.py @ 331:a78b41ff6ad2
Added better recipe files
author | Windel Bouwman |
---|---|
date | Fri, 07 Feb 2014 12:39:59 +0100 |
parents | 917eab04b8b7 |
children |
comparison
equal
deleted
inserted
replaced
330:a79ac866732f | 331:a78b41ff6ad2 |
---|---|
10 return int(s, 16) | 10 return int(s, 16) |
11 raise ValueError('Hexadecimal value must begin with 0x') | 11 raise ValueError('Hexadecimal value must begin with 0x') |
12 | 12 |
13 parser = argparse.ArgumentParser( | 13 parser = argparse.ArgumentParser( |
14 description='hexfile manipulation tool by Windel Bouwman') | 14 description='hexfile manipulation tool by Windel Bouwman') |
15 subparsers = parser.add_subparsers(title='commands', | 15 subparsers = parser.add_subparsers(title='commands', |
16 description='possible commands', dest='command') | 16 description='possible commands', dest='command') |
17 | 17 |
18 p = subparsers.add_parser('info', help='dump info about hexfile') | 18 p = subparsers.add_parser('info', help='dump info about hexfile') |
19 p.add_argument('hexfile', type=argparse.FileType('r')) | 19 p.add_argument('hexfile', type=argparse.FileType('r')) |
20 | 20 |
29 p.add_argument('rhexfile', type=argparse.FileType('w'), help="resulting hexfile") | 29 p.add_argument('rhexfile', type=argparse.FileType('w'), help="resulting hexfile") |
30 | 30 |
31 | 31 |
32 def main(args): | 32 def main(args): |
33 if args.command == 'info': | 33 if args.command == 'info': |
34 hf = HexFile() | 34 hexfile = HexFile() |
35 hf.load(args.hexfile) | 35 hexfile.load(args.hexfile) |
36 print(hf) | 36 print(hexfile) |
37 for region in hf.regions: | 37 for region in hexfile.regions: |
38 print(region) | 38 print(region) |
39 elif args.command == 'new': | 39 elif args.command == 'new': |
40 hf = HexFile() | 40 hf = HexFile() |
41 data = args.datafile.read() | 41 data = args.datafile.read() |
42 hf.addRegion(args.address, data) | 42 hf.addRegion(args.address, data) |