SPECS: utf8_check.py (NEW) - utf8_check.py tests whether given fil...
witekfl
witekfl at pld-linux.org
Mon Dec 31 11:25:36 CET 2007
Author: witekfl Date: Mon Dec 31 10:25:36 2007 GMT
Module: SPECS Tag: HEAD
---- Log message:
- utf8_check.py tests whether given files are properly
encoded in UTF-8
- when run without arguments checks all .spec files
in the current directory
- prints names of faulty files to stdout
---- Files affected:
SPECS:
utf8_check.py (NONE -> 1.1) (NEW)
---- Diffs:
================================================================
Index: SPECS/utf8_check.py
diff -u /dev/null SPECS/utf8_check.py:1.1
--- /dev/null Mon Dec 31 11:25:36 2007
+++ SPECS/utf8_check.py Mon Dec 31 11:25:31 2007
@@ -0,0 +1,25 @@
+#!/usr/bin/python
+import codecs, dircache, fnmatch, sys
+# This program check whether given files are properly encoded in UTF-8
+# It prints names of faulty files.
+# Usage: utf8_check.py file1 file2 ...
+# When invoked without arguments checks all .spec files in the current directory
+dec = codecs.getdecoder("UTF-8")
+
+def check(name):
+ global dec
+ f = open(name, "r")
+ data = f.read()
+ try:
+ dec(data)
+ except UnicodeDecodeError:
+ print name
+
+
+if len(sys.argv) > 1:
+ a = sys.argv[1:]
+else:
+ a = dircache.listdir(".")
+ a = fnmatch.filter(a, "*.spec")
+for name in a:
+ check(name)
================================================================
More information about the pld-cvs-commit
mailing list