Beispiel #1
0
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))
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
Beispiel #3
0
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
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