コード例 #1
0
ファイル: sanename.py プロジェクト: tlvince/scripts-python
def main():
    """Start execution of sanename."""
    args = parseArguments()

    for f in args.file:
        sane = sanitise(os.path.basename(f))
        shutil.move(f, os.path.join(os.path.dirname(f), sane))
コード例 #2
0
def testUnamed():
    """Special case when all characters are removed.

    In cases when the string contains no sanitisable characters, it should be
    replaced with a prefix and 6 random elements from the permitted character
    set.
    """
    actual = sanitise("!£$%")
    prefix = "untitled-"

    assert actual.startswith(prefix)
    assert len(actual) == len(prefix) + 6
コード例 #3
0
ファイル: git-archive.py プロジェクト: tlvince/scripts-python
def saneName(path):
    """Return a sane name from the repository's path."""
    base = os.path.basename(path)
    try:
        # Sanitised basename of the repository root
        name = sanitise(base)
    except NameError:
        logging.warn("The sanitise module was not imported")
        logging.warn("Using repository basename as is")
        name = base

    return name
コード例 #4
0
def testReplacements():
    """Coverage for find and replace cases."""
    cases = {
        "hello": "hello",
        "foo-bar#baz?qux@127/\\9]": "foo-barbazqux1279",
        "éèêàùçÇ": "eeeaucc",
        "CRaZyCASE": "crazycase",
        "Bill & Ted": "bill-and-ted",
        "file.MP3": "file.mp3",
        ".dotfile.txt": ".dotfile.txt",
        "---heLLO": "hello",
        "infix----dashes": "infix-dashes",
        "---hello....txt.": "hello.txt",
    }

    i = 1
    for case in cases:
        expected = cases[case]
        actual = sanitise(case)
        print("({0}) {1}: {2} -> {3}".format(i, case, expected, actual))
        assert expected == actual
        i += 1