-
Notifications
You must be signed in to change notification settings - Fork 104
/
test_images.py
executable file
·66 lines (51 loc) · 1.72 KB
/
test_images.py
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
#!/usr/bin/env python
# Cherokee Doc: Image checker
#
# Authors:
# Alvaro Lopez Ortega <alvaro@alobbs.com>
#
# Copyright (C) 2001-2011 Alvaro Lopez Ortega
# This file is distributed under the GPL2 license.
import os
import sys
def get_img_refs():
img_refs = {}
for file in filter(lambda x: x.endswith('.txt'), os.listdir('.')):
for img_line in filter (lambda x: 'image:' in x, open (file, 'r').readlines()):
filename = img_line.replace('::',':').strip()[6:]
fin = filename.rfind('[')
if fin > 0:
filename = filename[:fin]
img_refs[filename] = None
return img_refs.keys()
def get_img_files():
def is_image(file):
return file.endswith('.jpg') or file.endswith('.jpeg') or file.endswith('.png')
tmp = ['media/images/%s'%(x) for x in os.listdir('media/images')]
return filter (is_image, tmp)
def check_images():
error = False
img_refs = get_img_refs()
img_files = get_img_files()
for ref in img_refs:
if not ref in img_files:
print "ERROR: %s: File not found" %(ref)
error = True
for img in img_files:
if not img in img_refs:
print "ERROR: %s: No longer used" %(img)
error = True
automake_am = open("Makefile.am", 'r').read()
for img in img_refs:
if not img in automake_am:
print "ERROR: %s isn't covered in Makefile.am " %(img)
error = True
return error
if __name__ == "__main__":
# Exit if .txt files are not included
if not filter (lambda x: x.endswith('.txt'), os.listdir('.')):
print "Nothing to check.."
raise SystemExit
# Test
error = check_images()
sys.exit(int(error))