Skip to content

Commit

Permalink
dynamic analysis python script: fix syntax error, don't raise ValueEr…
Browse files Browse the repository at this point in the history
…ror on incorrect args passed, make main() return exit code

Signed-off-by: Max Fisher <[email protected]>
  • Loading branch information
maxfisher-g committed Oct 18, 2023
1 parent d20d3b1 commit e39e573
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions sandboxes/dynamicanalysis/analyze-python.py
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ def import_module(import_path):
return


def execute_package(import_path)
def execute_package(import_path):
"""Execute phase for analyzing the package."""
for path in files(package.name):
# TODO: pyc, C extensions?
Expand Down Expand Up @@ -267,12 +267,13 @@ def is_non_init_method(m):
}


def main():
def main() -> int:
args = list(sys.argv)
script = args.pop(0)

if len(args) < 2 or len(args) > 4:
raise ValueError(f'Usage: {script} [--local file | --version version] phase package_name')
print(f'Usage: {script} [--local file | --version version] phase package_name')
return -1

# Parse the arguments manually to avoid introducing unnecessary dependencies
# and side effects that add noise to the strace output.
Expand All @@ -294,23 +295,26 @@ def main():

if phase not in PHASES:
print(f'Unknown phase {phase} specified.')
exit(1)
return 1

if package_name is None:
# single module mode
if phase == 'import' and local_path is not None:
import_single_module(local_path)
return
return 0
else:
print('install requested but no package name given, or local file missing for single module import')
exit(1)
return 1

package = Package(name=package_name, version=version, local_path=local_path)

# Execute for the specified phase.
for phase in PHASES[phase]:
phase(package)

return 0


if __name__ == '__main__':
main()
ret = main()
exit(ret)

0 comments on commit e39e573

Please sign in to comment.