import os


def test_filename():
    """
    We are not allowed uppercase software directory name
    """

    basedir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..'))
    for name in os.listdir(basedir) + os.listdir(os.path.join(basedir, 'base')):
        if not os.path.isdir(name):
            continue

        assert name.islower()

    for (now_dir, dirs, files) in os.walk(basedir):
        for name in files:
            if name.lower() == 'readme.md' or name.lower() == 'readme.zh-cn.md':
                assert name == 'README.md' or name == 'README.zh-cn.md', f"README filename must be 'README.md' or 'README.zh-cn.md', not {now_dir} / {name}"

import os
import re


ARCHIVE_FILE_PATTERN = re.compile(r'^.*\.(tar\.gz|zip|7z|rar|exe|jar|xz|gz|tar|war)$', re.I)
ARCHIVE_EXCEPTED = re.compile(r'[/\\](struts2|CVE-2016-9086|weblogic[/\\]weak_password)[/\\]?')


def test_filename():
    """
    We are not allowed uppercase software directory name
    """

    basedir = os.path.realpath(os.path.join(os.path.dirname(os.path.realpath(__file__)), '..', '..'))
    for name in os.listdir(basedir) + os.listdir(os.path.join(basedir, 'base')):
        if not os.path.isdir(name):
            continue

        assert name.islower()

    for (now_dir, dirs, files) in os.walk(basedir):
        for name in files:
            if name.lower() == 'readme.md' or name.lower() == 'readme.zh-cn.md':
                assert name == 'README.md' or name == 'README.zh-cn.md', "README filename must be 'README.md' or 'README.zh-cn.md', not %r %r" % (now_dir, name)

            if ARCHIVE_EXCEPTED.search(now_dir) is None:
                assert ARCHIVE_FILE_PATTERN.match(name) is None, "You should not upload a archive file like %r %r" % (now_dir, name)

check archive filename