From 0592ee179bda9857bbd02d426c494a49b60e358d Mon Sep 17 00:00:00 2001 From: Tony Breeds Date: Wed, 10 Jan 2018 11:59:08 +1100 Subject: [PATCH] [tools] Add a tool to grep local repos Sean wanted to know which repos still use mox/mox 3 which can be done with this tool like: tools/code-search.sh --prefix ~/projects/openstack/ \ --projects ~/projects/openstack/*/* \ -- mox origin/master -- *requirements.txt setup.cfg The prefix is essentially a sting to remove from the project name. So the example above would change: /home/tony/projects/openstack/openstack/astara => openstack/astara Change-Id: I927bc96b6eafd2d95dc008b7f1a4374eb9f725b4 --- tools/README.txt | 4 ++++ tools/code-search.sh | 48 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 52 insertions(+) create mode 100755 tools/code-search.sh diff --git a/tools/README.txt b/tools/README.txt index 6f6a91ae81..cfa8b87fc8 100644 --- a/tools/README.txt +++ b/tools/README.txt @@ -28,6 +28,10 @@ Used in tox environment pip-install. Only installs requirements (as opposed to test-requirements and verifies that all console-scripts have all modules needed. +code-search.sh +-------------- +Assuming you have a set of local git repos grep them all for interesting things. + cruft.sh -------- diff --git a/tools/code-search.sh b/tools/code-search.sh new file mode 100755 index 0000000000..b6172f2c1c --- /dev/null +++ b/tools/code-search.sh @@ -0,0 +1,48 @@ +#!/usr/bin/env bash + +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +declare -a projects +in_projects=0 +base=$HOME + +while [ $# -gt 1 ] ; do + case "$1" in + --prefix) + prefix=$2 + shift 1 + ;; + --projects) + in_projects=1 + ;; + --) + break + ;; + *) + if [ "$in_projects" == 1 ] ; then + projects+=($1) + else + echo Unknown arg/context >&2 + exit 1 + fi + ;; + esac + shift 1 +done + +for prj in ${projects[@]} ; do + ( + cd $prj>/dev/null 2>&1 && \ + git grep -HEin $@ 2>/dev/null|sed -e "s,^,${prj#$prefix}:,g" + ) +done