Basic file system listing for JSON consumers
Python
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
imagedex
.gitignore
imagedex.py
readme.md

readme.md

Generate a JSON representation of a given directory listing, like so:

$ imagedex -r -P repo ./ | python -mjson.tool
{
    "repo": [
        "./.gitignore",
        "./imagedex.py",
        "./readme.md",
        {
            ".git": [
                "./.git/packed-refs",
                "./.git/FETCH_HEAD",
                "./.git/description",
                "./.git/ORIG_HEAD",
                "./.git/COMMIT_EDITMSG",
                "./.git/HEAD",
                "./.git/index",
                "./.git/config"
            ]
        },
        {
            "imagedex": [
                "./imagedex/__init__.py",
                "./imagedex/__init__.pyc"
            ]
        }
    ]
}

Almost everything about the output is configurable via command line options.

$ imagedex -j jsonPcallBack -P repo ./ | python -mjson.tool
jsonPcallBack({
    "repo": [
        / * ... */
    ]
})

#Use: To see all available flags and options, run: imagedex.py -h

I run this script as a response to inotify events; only generating a .json file when something in the target directory supposedly changes. For a live example, see api_drawings script I run on my web server:

while inotifywait --excludei='.*.swp' -r -e modify /some/dir/; do
    imagedex -r -j callBack -p '/api/3/' -f /api/path/imagedex.json /some/dir
done

##TODO:

  • Write proper unit tests for all our little quirks

##Notes:

  • Be aware that the -r recursive option is a lie and only provides data for a single directory level down.
  • As this script is just a wrapper around the python module, simplejson it must be installed.