-
Notifications
You must be signed in to change notification settings - Fork 5
Expand file tree
/
Copy pathformat-py
More file actions
executable file
·33 lines (30 loc) · 811 Bytes
/
Copy pathformat-py
File metadata and controls
executable file
·33 lines (30 loc) · 811 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
#!/usr/bin/env bash
set -euo pipefail
valid_shebang='#!/usr/bin/env python'
updated=0
while IFS= read -r -d '' path; do
first_line=''
if IFS= read -r first_line < "$path"; then
:
fi
if [[ "$first_line" == "$valid_shebang" ]]; then
continue
fi
tmp="$(mktemp)"
if [[ "$first_line" == '#!'* ]]; then
{
printf '%s\n' "$valid_shebang"
tail -n +2 "$path"
} > "$tmp"
else
{
printf '%s\n' "$valid_shebang"
cat "$path"
} > "$tmp"
fi
chmod --reference="$path" "$tmp"
mv "$tmp" "$path"
printf 'updated %s\n' "$path"
updated=$((updated + 1))
done < <(find solvers -maxdepth 1 -type f -name '*.py' -print0 | sort -z)
printf 'normalized %d solver Python files\n' "$updated"