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
|
"""": # -*-python-*-
command -v python3 > /dev/null && exec python3 "$0" "$@"
command -v python2 > /dev/null && exec python2 "$0" "$@"
echo "error: unable to find python3 or python2" 1>&2; exit 2
"""
# Parses a spec for a given prefix and returns the ref (version number)
# Basically prints out everything after the prefix up to the next / or end of spec
# prefixed-ref-from-spec core/openjdk8/pg-9.6 pg- => 9.6
from __future__ import print_function
from sys import exit, stderr
import os, sys
def usage(stream):
print('Usage: prefixed-ref-from-spec .../pup-5.5.x/srv-5.3.x/pg-9.6 srv-',
file=stream)
def misuse():
usage(stderr)
exit(2)
len(sys.argv) == 3 or misuse()
specs, prefix = sys.argv[1:]
specs = specs.split('/')
specs = [x for x in specs if x.startswith(prefix)]
len(specs) == 1 or misuse()
print(specs[0][len(prefix):])
|