Move write_pbr_json to avoid issues with nose

Put write_pbr_json in pbr.pbr_json so that you do not need to import
pbr.packaging to use it. This avoids python3 errors with nose where nose
is imported by pbr before it is converted to python3 by 2to3 under
python3.

Also port the pbr.git refactor from the master branch.

Co-Authored-By: Jeremy Stanley <fungi@yuggoth.org>
Change-Id: I1c420fed609bc60bbfdf78eb219e067ccab1a61e
(cherry picked from commit 3550e89db42002e226ea70b1d0314a319b2ecd10)