change .encode to to_bytes (#35522)

ignore backup dir in test integration targets folder
This commit is contained in:
Jordan Borean 2018-01-31 08:58:03 +10:00 committed by GitHub
parent c24e092865
commit 62b87bc925
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -5,8 +5,11 @@
# https://msdn.microsoft.com/en-us/library/aa365247#naming_conventions # https://msdn.microsoft.com/en-us/library/aa365247#naming_conventions
import os import os
import re
import struct import struct
from ansible.module_utils.basic import to_bytes
ILLEGAL_CHARS = [ ILLEGAL_CHARS = [
b'<', b'<',
b'>', b'>',
@ -62,16 +65,23 @@ def check_path(path, dir=False):
if file_name[-1] in ILLEGAL_END_CHARS: if file_name[-1] in ILLEGAL_END_CHARS:
errors.append("Illegal %s name end-char '%s': %s" % (type_name, file_name[-1], path)) errors.append("Illegal %s name end-char '%s': %s" % (type_name, file_name[-1], path))
bfile = file_name.encode('utf-8') bfile = to_bytes(file_name, encoding='utf-8')
for char in ILLEGAL_CHARS: for char in ILLEGAL_CHARS:
if char in bfile: if char in bfile:
errors.append("Illegal char %s in %s name: %s" % (char, type_name, path.encode('utf-8'))) bpath = to_bytes(path, encoding='utf-8')
errors.append("Illegal char %s in %s name: %s" % (char, type_name, bpath))
return errors return errors
def main(): def main():
errors = [] errors = []
pattern = re.compile("^./test/integration/targets/.*/backup")
for root, dirs, files in os.walk('.'): for root, dirs, files in os.walk('.'):
# ignore test/integration/targets/*/backup
if pattern.match(root):
continue
for dir_name in dirs: for dir_name in dirs:
errors += check_path(os.path.abspath(os.path.join(root, dir_name)), dir=True) errors += check_path(os.path.abspath(os.path.join(root, dir_name)), dir=True)