swc-windows-installer.py: Install nano source syntax highlighters

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
Merge branch 'python' into bc-namespaced-python

* python:
  swc-windows-installer.py: Install nano source syntax highlighters
swc-windows-installer.py: Rename ~/.nanorc to ~/nano.rc

The nano FAQ hints that this is the prefered path on MS Windows [1],
and Ethan White confirmed it in testing [2].

[1]: http://www.nano-editor.org/dist/v2.2/faq.html#3.9.1
[2]: https://github.com/swcarpentry/bc/pull/357#issuecomment-37482899
swc-windows-installer.py: Use '~' in ~/nano.rc includes

On Wed, Mar 12, 2014 at 04:44:31PM -0700, Ethan White wrote [1]:
> Got it. We just need to change the `/c/Users/River/` in the include
> statements to `~/` and everything works great!

[1]: https://github.com/swcarpentry/bc/pull/357#issuecomment-37483149
Merge branch 'python' into bc-namespaced-python

* python:
  swc-windows-installer.py: Use '~' in ~/nano.rc includes
  swc-windows-installer.py: Rename ~/.nanorc to ~/nano.rc
swc-windows-installer.py: Use POSIX paths for ~/nano.rc

On Wed, Mar 12, 2014 at 06:34:43PM -0700, Ethan White wrote [1]:
> The bash script in #228 is now working properly, but the Python
> script is still failing. It reports errors like:
>
>     Error reading ~\.swc\share\nanorc\doc\syntax\python.nanorc
>
> The obvious difference is that the nano.rc files produced by the
> bash script have `/` for paths for the includes, but the Python
> script produces includes that use `\`.

[1]: https://github.com/swcarpentry/bc/pull/357#issuecomment-37491038
Merge branch 'python' into bc-namespaced-python

* python:
  swc-windows-installer.py: Use POSIX paths for ~/nano.rc
swc-windows-installer.py: Force UNIX-style \n line endings for ~/nano.rc

On Thu, Mar 13, 2014 at 03:37:12AM -0700, Ethan White wrote [1]:
> We now have a line ending issue resulting in:
>
>     Error reading /cygdrive/c/Users/...
>
> This is fixed by running `dos2unix` on the resulting nano.rc.

This is also mentioned in the nano FAQ [2]:

> Note that the nano.rc file must remain Unix formated in order for
> nano to unerstand it.

Since Python 3.0 and PEP 3116, Python's open() has taken a 'newline'
argument that allows you to override the default line separator for a
particular file [3,4].  However, Python 2.x does not support that
argument [5].  This commit adds a local 'open3' which uses a terrible
hack of a wrapper on Python 2 to fake that support.  It opens the file
in binary mode, and takes advantage of Python 2's lack of distinction
between str and bytes to treat the \n-terminated strings as the raw
binary output.  That's going to crash and burn if you have any
non-ASCII characters in the output content, but we explicitly set all
the components in our relative include_path, so that shouldn't be a
problem.

Another side effect of binary-mode is that we are going to get
ASCII-encoded output, not output encoded in the user's preferred
encoding (locale.getpreferredencoding [3,6]).  That's unfortunate,
because nano does the right thing and uses your locale to decode input
(at least for UTF-8 locales [7], presumably including your nano.rc
file).

[1]: https://github.com/swcarpentry/bc/pull/357#issuecomment-37518899
[2]: http://www.nano-editor.org/dist/v2.2/faq.html#3.9.1
[3]: http://docs.python.org/3/library/functions.html#open
[4]: http://legacy.python.org/dev/peps/pep-3116/
[5]: http://docs.python.org/2/library/functions.html#open
[6]: http://docs.python.org/2/library/stdtypes.html#file.encoding
[7]: http://www.nano-editor.org/dist/v2.2/faq.html#5.3
Merge branch 'python' into bc-namespaced-python

* python:
  swc-windows-installer.py: Force UNIX-style \n line endings for ~/nano.rc
swc-windows-installer.py: Generalize msysGit download link

SWC's current setup instructions use both "Git for Windows" and "Git
Bash" [1].  They link to the Git for Windows installer [2] and not the
msysGit installer [3].  Since SWC has Make lessons [4], I think it
makes more sense to have students installing msysGit (which has Make
[5]) than to have them install Git for Windows (which does not have
Make [6]).

However, none of this matters for *this* Windows installer.  Because
this script works with both the full msysGit and the minimal Git for
Windows, I'm sticking to msysGit (the more generic project name), and
generalizing the suggested link to
http://code.google.com/p/msysgit/downloads/list.

[1]: https://github.com/swcarpentry/bc/blob/5c26313b0525e9d0b911d9558592a9e33cd03c1e/_includes/setup.html#L86
[2]: http://code.google.com/p/msysgit/downloads/list?q=full+installer+official+git
[3]: http://code.google.com/p/msysgit/downloads/list?q=installer+hack+on+git
[4]: https://github.com/swcarpentry/bc/tree/master/intermediate/make
[5]: https://github.com/msysgit/msysgit#the-build-environment
[6]: https://github.com/msysgit/msysgit#the-relationship-between-msysgit-and-git-for-windows
swc-windows-installer.py: Install the sqlite3 shell

On Thu, Apr 03, 2014 at 09:38:38AM -0700, Ethan White wrote:
> Some instructors like to teach `sqlite` from the command
> line. Therefore we should have the Windows installer handle
> downloading, installing and adding sqlite3 to the path.

The novice/sql lessons currently revolve around some IPython magic,
but even they use the SQLite shell to do the initial database setup
[1].  The SQLite shell has also seen a bit more developer time than
our one-off magic [2], so it's probably more robust ;).

I've installed this in it's own directory (rather than just dumping it
into ~/.swc/bin), because zip_install uses the existence of
${INSTALL_DIRECTORY} to decide whether or not the installation has
already happened.  create_nosetests_entry_point will have already
created ${BIN_DIR}, so we need to use a different target directory for
SQLite.  We could also flip the order and run install_sqlite first,
but that doesn't scale well if we install more packages in the future,
and it's easier to keep the installs separate and keep adding to the
path.

[1]: https://github.com/swcarpentry/bc/blob/1aa0799ac6a48e9815d50bf2f49171b9eb5bf6d4/novice/sql/README.txt#L8
[2]: https://github.com/swcarpentry/bc/blob/1aa0799ac6a48e9815d50bf2f49171b9eb5bf6d4/novice/sql/sqlitemagic.py
Merge branch 'python' into bc-namespaced-python

* python:
  swc-windows-installer.py: Install the sqlite3 shell
  swc-windows-installer.py: Generalize msysGit download link
Merge branch 'bc-namespaced-python' of git://tremily.us/swc-setup-windows-installer

* 'bc-namespaced-python' of git://tremily.us/swc-setup-windows-installer:
  swc-windows-installer.py: Install the sqlite3 shell
  swc-windows-installer.py: Generalize msysGit download link
  swc-windows-installer.py: Force UNIX-style \n line endings for ~/nano.rc
  swc-windows-installer.py: Use POSIX paths for ~/nano.rc
  swc-windows-installer.py: Use '~' in ~/nano.rc includes
  swc-windows-installer.py: Rename ~/.nanorc to ~/nano.rc
  swc-windows-installer.py: Install nano source syntax highlighters

Conflicts:
	setup/swc-windows-installer.py

This resolves a conflict in the Windows installer comments between my
branch and changes from #389 [1].  Joon felt like we should match our
suggested bootcamp installation instructions (which recommend the
limited Git for Windows), but I prefer the more generic msysGit (as I
explain in 4fe28c0e, swc-windows-installer.py: Generalize msysGit
download link, 2014-03-27).  Ethan feels like it isn't a big deal
either way, so I'm going with my version ;).

[1]: https://github.com/swcarpentry/bc/pull/389