Skip to content

[Code scan] Search all OUT directories before average_pot exits #7559

Description

@njzjz

This issue is a result of a Codex global repository scan.

aveElecStatPot.py exits as soon as it sees the first OUT.* directory without ElecStaticPot.cube, even if a later OUT.* directory contains the file. If no root-level cube and no matching OUT.* cube are found, the script can also fall through to open(input_file) with input_file undefined.

if os.path.exists(os.path.join(current_dir, "ElecStaticPot.cube")):
input_file = os.path.join(current_dir, "ElecStaticPot.cube")
output_file = os.path.join(current_dir, "ElecStaticPot_AVE")
output_png = os.path.join(current_dir, "ElecStaticPot-vs-Z.png")
else:
for dir_name in os.listdir(current_dir):
dir_path = os.path.join(current_dir, dir_name)
if os.path.isdir(dir_path) and dir_name.startswith("OUT."):
input_file = os.path.join(dir_path, "ElecStaticPot.cube")
output_file = os.path.join(dir_path, "ElecStaticPot_AVE")
output_png = os.path.join(dir_path, "ElecStaticPot-vs-Z.png")
if os.path.exists(input_file):
print(f"Processeding: {input_file}")
break
else:
print(f"File does not exist: {input_file}")
sys.exit()
with open(input_file, 'r') as inpt:

Relevant code:

for dir_name in os.listdir(current_dir):
    dir_path = os.path.join(current_dir, dir_name)

    if os.path.isdir(dir_path) and dir_name.startswith("OUT."):
        input_file = os.path.join(dir_path, "ElecStaticPot.cube")
        ...
        if os.path.exists(input_file):
            break
        else:
            print(f"File does not exist: {input_file}")
            sys.exit()
                        
with open(input_file, 'r') as inpt:

Suggested fix:

Scan all candidate locations first, select the first existing ElecStaticPot.cube, and emit one clear error after the loop if no cube was found.

Metadata

Metadata

Labels

No labels
No labels

Type

No type

Projects

Status
Done

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions