| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
"""check_utf8 command for setup.py. |
| 21 |
It checks contents of source files to be UTF-8 encoded. |
| 22 |
""" |
| 23 |
|
| 24 |
from distutils.core import Command |
| 25 |
from distutils.errors import DistutilsPlatformError |
| 26 |
from distutils import log |
| 27 |
import os |
| 28 |
import sys |
| 29 |
|
| 30 |
|
| 31 |
class check_utf8(Command): |
| 32 |
|
| 33 |
description = ("check contents of source files to be UTF-8 encoded") |
| 34 |
user_options = [] |
| 35 |
|
| 36 |
def initialize_options(self): |
| 37 |
pass |
| 38 |
|
| 39 |
def finalize_options(self): |
| 40 |
pass |
| 41 |
|
| 42 |
def run(self): |
| 43 |
for root, dirs, files in os.walk('.'): |
| 44 |
for fname in sorted(files): |
| 45 |
ext = os.path.splitext(fname)[1].lower() |
| 46 |
if ext in ('.py', '.txt', '.ui'): |
| 47 |
fullname = os.path.join(root, fname)[2:] |
| 48 |
|
| 49 |
if self.verbose: |
| 50 |
log.info('checking ' + fullname) |
| 51 |
if not self.dry_run: |
| 52 |
f = open(fullname, 'rb') |
| 53 |
content = f.read() |
| 54 |
f.close() |
| 55 |
try: |
| 56 |
content.decode('utf-8') |
| 57 |
except UnicodeDecodeError as e: |
| 58 |
log.error(fullname + ': ' + str(e)) |
| 59 |
|
| 60 |
for dname in dirs[:]: |
| 61 |
fullname = os.path.join(root, dname).replace('\\','/') |
| 62 |
if fullname in ('./_lib', './build', './dist', './installer'): |
| 63 |
dirs.remove(dname) |