aboutsummaryrefslogtreecommitdiff
path: root/admin/sbols
blob: d5825c05d990ddff9de58c4d18a3bb30f8dbd420 (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
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#!/bin/sh

VERSION="0.0.1"
SELF="$( basename $0 )"

die() {
  echo "$SELF: fatal: $@" 1>&2
  exit 1
}

warn() {
  echo "$SELF: warning: $@" 1>&2
}

usage() {
  cat <<EOF
$SELF - query SBo git tree for info on builds

Usage: $SELF [-[onsrcdla] ...] [ -m <maintainer> | <build> [<build> ...] ]

Build arguments are build names as used with cdsb: category/build, or
just build, and partial matches are supported. For each one, show the
category/build (and optionally the maintainer, dependencies, and/or
description). Output is one line per argument.

Options:
  -m <maintainer>  Show all builds for given maintainer. If this
      option is used, it must be the last option (this is done to
      avoid the need to quote maintainer names with spaces in them).
  -o  Same as -m "orphaned - no maintainer"; lists orphans.
  -i <file>  Read list of builds from <file> (use - for stdin).
      Builds are separated by whitespace (including newlines), so
      they can be one per line or multiple per line. Cannot be
      used with -m <maintainer> option.
  -n  Show maintainer name and email.
  -s  Show short description (from top of slack-desc).
  -r  Show REQUIRES.
  -c  Show last git commit date/author/description (slow!).
  -d  Show dependees (requires hoorex on \$PATH).
  -l  Same as -nsr (show "long" info, no last commit or dependees).
  -a  Same as -nsrcd (show all info).

Environment:
  SBO_GITROOT - set this to the path of the local SBo git clone.
    If not set, the current directory is assumed.

Exit status is 0 (success) if any builds were listed, or 1 (failure)
if no builds were listed at all.
EOF
}

if [ "$1" = "--help" -o "$1" = "" ]; then
  usage ; exit 0
fi

while getopts ":moi:nsrcdla" OPT; do
  case "$OPT" in
    m) opt_m=1 ;;
    o) opt_o=1 ;;
    n) opt_n=1 ;;
    i) opt_i="$OPTARG" ;;
    s) opt_s=1 ;;
    r) opt_r=1 ;;
    c) opt_c=1 ;;
    d) opt_d=1 ;;
    l) opt_n=1 ; opt_s=1 ; opt_r=1 ;;
    a) opt_n=1 ; opt_s=1 ; opt_r=1 ; opt_c=1 ; opt_d=1 ;;
    *) die "invalid option -$OPTARG, try --help" ;;
  esac
done
shift $(($OPTIND - 1))

# sbostuff.sh defines cdsb(), which we can't do without.
source ~/sbostuff/sbostuff.sh || exit 1

# we're going to cd to $SBO_GITROOT, so canonicalize the -i file
# if one was given.
[ "$opt_i" != "" -a "$opt_i" != "-" ] && opt_i="$( realpath "$opt_i" )"

# if we have this, use it, otherwise use current dir.
[ "$SBO_GITROOT" != "" ] && cd "$SBO_GITROOT"

# either way, check that it's for real.
[ -d .git -a -d system -a -d academic ] || die "not a valid SBo git checkout"

if [ "$opt_o" = "1" ]; then
  opt_m=1
  set "orphaned - no maintainer"
fi

if [ "$opt_m" = "1" ]; then
  [ "$opt_i" != "" ] && die "-i option not compatible with -m or -o"
  cdsb
  builds="$( git grep -l "$*" '*/*/*.info' | cut -d/ -f1,2 )"
  [ "$builds" = "" ] && die "maintainer '$*' not found"
  set $builds
elif [ "$opt_i" != "" ]; then
  builds="$( cat "$opt_i" )"
  [ "$builds" = "" ] && die "can't read any build names from $opt_i"
  set $builds
fi

[ "$*" = "" ] && usage && exit 1

ret=1

for i; do
  if cdsb $i 2>/dev/null; then
    ret=0
    i="$( basename $( pwd ) )"
    prgcat="$( pwd | rev | cut -d/ -f1,2 | rev )"
    echo -n $prgcat
    if [ "$opt_n" = "1" ]; then
      source ./$i.info
      echo -n ": $MAINTAINER <$EMAIL>"
    fi
    if [ "$opt_s" = "1" ]; then
      echo -n " $( grep $i: slack-desc | head -1 | cut -d' ' -f3- )"
    fi
    if [ "$opt_r" = "1" ]; then
      echo -n " $( grep ^REQUIRES $i.info | grep -v '""' )"
    fi
    if [ "$opt_c" = "1" ]; then
      echo -n " $( git -P log -n1 --format="%as;%an;%s" . | sed "s,;$prgcat: ,;,")"
    fi
    if [ "$opt_d" = "1" ]; then
      x="$( hoorex -a $i | cut -d' ' -f2- )"
      [ "$x" != "" ] && echo -n " | $x"
    fi
    echo
  else
    warn "build $i not found in repo"
  fi
done

exit $ret