summaryrefslogtreecommitdiff
path: root/hash_port.py
blob: c43289e7d53d5aafb64d6a4443afadf06f07ea74 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
"""
Helper script which provides an integer
number from a given range based on a hash of
current directory name.

This is used in continuous integration as a helper
to provide ports to assign to services like
Redis, Memcached when they are run on a per-test basis.

E.g. in a Jenkins job, one could put as the run command::

    export TOX_DOGPILE_PORT=`python hash_port.py 10000 34000`
    tox -r -e ${pyv}-${backend}

So you'd get one TOX_DOGPILE_PORT for the script in
/var/lib/jenkins-workspace/py27-redis, another TOX_DOGPILE_PORT
for the script in /var/lib/jenkins-workspace/py34-memcached.
tox calls the pifpaf tool to run redis/ memcached local to that
build and has it listen on this port.
"""
import os
import sys

start, end = int(sys.argv[1]), int(sys.argv[2])

dir_ = os.getcwd()

print((hash(dir_) % (end - start)) + start)