Remove duplicate lookup of next uid number

Change-Id: I5b5e57204841dbbf1b769419c17286298453baa1
Tidy imports

Change-Id: I8cddc0a30960594da7c62332efbc38991d245c89
Avoid circulare dependency between groups and users

Extract the _PREFIX constants to their own file and only import
groups within the method that uses it. While the issue doesn't show
up under the current setup and with Python 2, when fixing the imports
for Python 3 it does appear.

Change-Id: I419bae3d0a088fce5e78c5890aab66423f280465
Various fixes for Python 3

This applies the output of the modernisation tool to the repo, plus
some further manual fixes. It fixes iteration, type checking and
import issues so the source is valid for both Python 2 and 3.

Change-Id: Ia98dae5f5c3e3066412e052b6279575549643120