~joel-auterson/python-snippets/bluetooth-snippets

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/bash

# find snippets whose filename conflicts with module names in the Python
# Standard Library. This is problematic if a snippet wonts to import a
# standard module and wrongly imports a snippet.

# try to import snippets in python, if an ImportError is raised,
# the filename is OK.
cd $(dirname $0)
files=$(find "." -type f |
        sed 's#.*/##' |
        sed -n 's/^\([a-zA-Z0-9_]*\)\.py$/try:\n import \1\nexcept ImportError:\n pass\nelse:\n print "\1"/p' |
        python)

[ "$files" ] && {
    echo "Files conflicts with module names in the Python Standard Library:"
    echo "$files"
    exit 1
}