swcarpentry/bc — pull request #357 by wking (2014-03-05 18:02:36+00:00)
Title: swc-windows-installer.py: Install nano source syntax highlighters

As suggested in #354. Currently untested on Windows ;).

Make writing Python source code (and a number of other languages) a bit more
exciting for the eyes and easier on the brain by coloring strings, comments,
and such.

We need to install the source tarball because the compiled zip doesn't include
the syntax highlighting scripts. To make that easier, I've extracted out the
download / hash-check functionality into a new download(), which I use in both
the old zip_install() and the new tar_install(). If the user doesn't have an
existing ~/.nanorc, we populate it by adding 'include' options for each of the
syntax files in the Nano tarball. If they do have an existing ~/.nanorc, I
assume they know what they're doing ;).

The default '*' compression is for transparent detection [1], but you can
override it to explicitly select the compression type if you like.

There's a bit of ugliness to work around the lack of a
--strip-components analog in TarFile.extractall [2]. Instead, we iterate over
the TarInfo members and strip leading components from their 'name' by hand
[3].

[1]: http://docs.python.org/3/library/tarfile.html#tarfile.open
[2]: http://docs.python.org/3/library/tarfile.html#tarfile.TarFile.extractall
[3]: http://docs.python.org/3/library/tarfile.html#tarfile.TarInfo.name