File: hash_port.py

package info (click to toggle)
python-dogpile.cache 1.5.0-1
  • links: PTS, VCS
  • area: main
  • in suites: experimental
  • size: 836 kB
  • sloc: python: 6,620; makefile: 159; sh: 104
file content (27 lines) | stat: -rw-r--r-- 881 bytes parent folder | download
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
"""
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 tools/hash_port.py 10000 34000`
    nox -v -t ${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. nox (as well as the previous tox
setup) 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)