File: check_dilate.py

package info (click to toggle)
ddnet 19.1-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 68,960 kB
  • sloc: cpp: 195,050; ansic: 58,572; python: 5,568; asm: 946; sh: 941; java: 366; xml: 206; makefile: 31
file content (50 lines) | stat: -rwxr-xr-x 1,239 bytes parent folder | download
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
#!/usr/bin/env python3

import os
import subprocess
import sys

def check_file(dilate_path, filename):
	executable_path = os.path.join(dilate_path, "dilate")
	try:
		with subprocess.Popen(
			[executable_path, "--dry-run", filename],
			stdout=subprocess.PIPE,
			stderr=subprocess.PIPE
		) as process:
			process.communicate()
			not_dilated = process.returncode != 0
			if not_dilated:
				print(f"Error: '{filename}' is not dilated.")
			return not_dilated
	except FileNotFoundError:
		print(f"Error: Executable not found at '{executable_path}'.")
		return 1

def check_dir(dilate_path, directory):
	errors = 0
	for file in os.listdir(directory):
		path = os.path.join(directory, file)
		if os.path.isdir(path):
			errors += check_dir(dilate_path, path)
		elif file.endswith(".png"):
			errors += check_file(dilate_path, path)
	return errors

def main(arguments):
	if len(arguments) != 3:
		print(f"Usage: {arguments[0]} <dilate executable folder> <check folder>")
		return 1

	dilate_path = arguments[1]
	check_path = arguments[2]

	errors = check_dir(dilate_path, check_path)
	if errors > 0:
		return 1

	print(f"Success: All .png files in '{check_path}' are dilated.")
	return 0

if __name__ == "__main__":
	sys.exit(main(sys.argv))