debian/lib/python: Again fix recognizing versions
In commit
55129e390c I changed this code to recognize a few patterns,
but it turns out the code was not fully functioning.
Also move determining the treeish to the same place with the version
regex.
See the numbered comments when determining the treeish for valid
patterns:
1. pre version in between stable releases with explicit commit
e.g. 4.10.2~pre+1.
25e0657ed4-1
-> use commit
25e0657ed4
2. explicit commit while in rc
e.g. 4.11.0~rc6+1.
35fcb982ea-1~exp1
-> use commit
35fcb982ea
3. release candidate
e.g. 4.11.0~rc7-1~exp1
-> use tag 4.11.0-rc7
4. regular release, like 4.10.2
-> use tag RELEASE-4.10.2
Signed-off-by: Hans van Kranenburg <hans@knorrie.org>