Skip to content

Commit

Permalink
espefuse: Handle errors from script files for execute_scripts cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
KonstantinKondrashov committed Feb 19, 2022
1 parent 8fa1f76 commit 4151344
Show file tree
Hide file tree
Showing 7 changed files with 49 additions and 14 deletions.
9 changes: 7 additions & 2 deletions espressif/efuse/esp32/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import argparse
import os # noqa: F401. It is used in IDF scripts
import traceback

import espsecure

Expand Down Expand Up @@ -220,7 +221,11 @@ def espefuse(esp, efuses, args, command):
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='operation')
add_commands(subparsers, efuses)
cmd_line_args = parser.parse_args(command.split())
try:
cmd_line_args = parser.parse_args(command.split())
except SystemExit:
traceback.print_stack()
raise esptool.FatalError('"{}" - incorrect command'.format(command))
if cmd_line_args.operation == 'execute_scripts':
configfiles = cmd_line_args.configfiles
index = cmd_line_args.index
Expand All @@ -245,7 +250,7 @@ def execute_scripts(esp, efuses, args):

for file in scripts:
with open(file.name, 'r') as file:
exec(file.read())
exec(compile(file.read(), file.name, 'exec'))

if args.debug:
for block in efuses.blocks:
Expand Down
9 changes: 7 additions & 2 deletions espressif/efuse/esp32c2/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import argparse
import os # noqa: F401. It is used in IDF scripts
import traceback

import espsecure

Expand Down Expand Up @@ -210,7 +211,11 @@ def espefuse(esp, efuses, args, command):
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='operation')
add_commands(subparsers, efuses)
cmd_line_args = parser.parse_args(command.split())
try:
cmd_line_args = parser.parse_args(command.split())
except SystemExit:
traceback.print_stack()
raise esptool.FatalError('"{}" - incorrect command'.format(command))
if cmd_line_args.operation == 'execute_scripts':
configfiles = cmd_line_args.configfiles
index = cmd_line_args.index
Expand All @@ -235,7 +240,7 @@ def execute_scripts(esp, efuses, args):

for file in scripts:
with open(file.name, 'r') as file:
exec(file.read())
exec(compile(file.read(), file.name, 'exec'))

if args.debug:
for block in efuses.blocks:
Expand Down
9 changes: 7 additions & 2 deletions espressif/efuse/esp32c3/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import argparse
import os # noqa: F401. It is used in IDF scripts
import traceback

import espsecure

Expand Down Expand Up @@ -236,7 +237,11 @@ def espefuse(esp, efuses, args, command):
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='operation')
add_commands(subparsers, efuses)
cmd_line_args = parser.parse_args(command.split())
try:
cmd_line_args = parser.parse_args(command.split())
except SystemExit:
traceback.print_stack()
raise esptool.FatalError('"{}" - incorrect command'.format(command))
if cmd_line_args.operation == 'execute_scripts':
configfiles = cmd_line_args.configfiles
index = cmd_line_args.index
Expand All @@ -261,7 +266,7 @@ def execute_scripts(esp, efuses, args):

for file in scripts:
with open(file.name, 'r') as file:
exec(file.read())
exec(compile(file.read(), file.name, 'exec'))

if args.debug:
for block in efuses.blocks:
Expand Down
9 changes: 7 additions & 2 deletions espressif/efuse/esp32h2beta1/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import argparse
import os # noqa: F401. It is used in IDF scripts
import traceback

import espsecure

Expand Down Expand Up @@ -237,7 +238,11 @@ def espefuse(esp, efuses, args, command):
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='operation')
add_commands(subparsers, efuses)
cmd_line_args = parser.parse_args(command.split())
try:
cmd_line_args = parser.parse_args(command.split())
except SystemExit:
traceback.print_stack()
raise esptool.FatalError('"{}" - incorrect command'.format(command))
if cmd_line_args.operation == 'execute_scripts':
configfiles = cmd_line_args.configfiles
index = cmd_line_args.index
Expand All @@ -262,7 +267,7 @@ def execute_scripts(esp, efuses, args):

for file in scripts:
with open(file.name, 'r') as file:
exec(file.read())
exec(compile(file.read(), file.name, 'exec'))

if args.debug:
for block in efuses.blocks:
Expand Down
9 changes: 7 additions & 2 deletions espressif/efuse/esp32s2/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import argparse
import io
import os # noqa: F401. It is used in IDF scripts
import traceback

import espsecure

Expand Down Expand Up @@ -340,7 +341,11 @@ def espefuse(esp, efuses, args, command):
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='operation')
add_commands(subparsers, efuses)
cmd_line_args = parser.parse_args(command.split())
try:
cmd_line_args = parser.parse_args(command.split())
except SystemExit:
traceback.print_stack()
raise esptool.FatalError('"{}" - incorrect command'.format(command))
if cmd_line_args.operation == 'execute_scripts':
configfiles = cmd_line_args.configfiles
index = cmd_line_args.index
Expand All @@ -365,7 +370,7 @@ def execute_scripts(esp, efuses, args):

for file in scripts:
with open(file.name, 'r') as file:
exec(file.read())
exec(compile(file.read(), file.name, 'exec'))

if args.debug:
for block in efuses.blocks:
Expand Down
9 changes: 7 additions & 2 deletions espressif/efuse/esp32s3/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import argparse
import io
import os # noqa: F401. It is used in IDF scripts
import traceback

import espsecure

Expand Down Expand Up @@ -339,7 +340,11 @@ def espefuse(esp, efuses, args, command):
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='operation')
add_commands(subparsers, efuses)
cmd_line_args = parser.parse_args(command.split())
try:
cmd_line_args = parser.parse_args(command.split())
except SystemExit:
traceback.print_stack()
raise esptool.FatalError('"{}" - incorrect command'.format(command))
if cmd_line_args.operation == 'execute_scripts':
configfiles = cmd_line_args.configfiles
index = cmd_line_args.index
Expand All @@ -364,7 +369,7 @@ def execute_scripts(esp, efuses, args):

for file in scripts:
with open(file.name, 'r') as file:
exec(file.read())
exec(compile(file.read(), file.name, 'exec'))

if args.debug:
for block in efuses.blocks:
Expand Down
9 changes: 7 additions & 2 deletions espressif/efuse/esp32s3beta2/operations.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@

import argparse
import os # noqa: F401. It is used in IDF scripts
import traceback

import espsecure

Expand Down Expand Up @@ -274,7 +275,11 @@ def espefuse(esp, efuses, args, command):
parser = argparse.ArgumentParser()
subparsers = parser.add_subparsers(dest='operation')
add_commands(subparsers, efuses)
cmd_line_args = parser.parse_args(command.split())
try:
cmd_line_args = parser.parse_args(command.split())
except SystemExit:
traceback.print_stack()
raise esptool.FatalError('"{}" - incorrect command'.format(command))
if cmd_line_args.operation == 'execute_scripts':
configfiles = cmd_line_args.configfiles
index = cmd_line_args.index
Expand All @@ -299,7 +304,7 @@ def execute_scripts(esp, efuses, args):

for file in scripts:
with open(file.name, 'r') as file:
exec(file.read())
exec(compile(file.read(), file.name, 'exec'))

if args.debug:
for block in efuses.blocks:
Expand Down

0 comments on commit 4151344

Please sign in to comment.