source: LMDZ5/trunk/tools/diffdef.sh @ 2412

Last change on this file since 2412 was 2412, checked in by lguez, 9 years ago

Make the use of python or python3 more transparent.

  • Property svn:executable set to *
File size: 2.4 KB
Line 
1# This is a script in Bash.
2# Author: Lionel GUEZ
3
4# This script compares files "*.def" other than "traceur.def" and
5# "out.def" in two directories.
6
7# This script uses GNU versions of the utilities cut, sort and uniq,
8# and calls a Python script.
9
10# See guide:
11# http://lmdz.lmd.jussieu.fr/utilisateurs/outils/utilisation-de-lmdz#section-5
12
13USAGE="usage: `basename $0` directory_1 directory_2"
14
15if (($# != 2))
16    then
17    echo "$USAGE" >&2
18    exit 1
19fi
20
21##set -x
22
23type python3 >/dev/null 2>&1
24if (($? == 0))
25then
26    my_python=python3
27else
28    my_python=python
29fi
30
31set -e
32
33script_dir=`dirname $0`
34
35# Let us make sure we know what the sort order is:
36export LC_ALL=C
37
38# Enable extended pattern matching features:
39shopt -s extglob
40
41for my_directory in $*
42  do
43  cd $my_directory
44  rm -f all.def
45  echo "def files in $my_directory:"
46  ls !(traceur|out).def
47
48  # Concatenate and format the def files:
49  cat !(traceur|out).def | tr -d " " | grep -v -E '(^#|^!|INCLUDEDEF|^$)' \
50      | tr '[:lower:]' '[:upper:]' | sed 's/=[NF]$/=FALSE/' \
51      | sed 's/=[YT]$/=TRUE/' | sort >all.def
52
53  # Check that no variable is repeated:
54  cut --fields=1 --delimiter="=" all.def | uniq --repeated >plouf_$$
55  if [[ -s plouf_$$ ]]
56      then
57      echo
58      echo "Error: a variable is repeated in directory \"$my_directory\"."
59      echo
60      echo "Here is the list of repeated variables in directory \"$my_directory\":"
61      echo
62      cat plouf_$$
63      rm plouf_$$
64      rm all.def
65      exit 1
66  fi
67  rm plouf_$$
68
69  cd - >/dev/null
70done
71
72
73sort $1/all.def $2/all.def | uniq --repeated >common_lines
74
75for my_directory in $*
76  do
77  sort $my_directory/all.def common_lines | uniq --unique \
78      >$my_directory/uniq_lines
79done
80
81sort --field-separator="=" --key=1,1 --unique $2/uniq_lines $1/uniq_lines \
82    | sort - $2/uniq_lines | uniq --unique >$1/uniq_var
83sort --field-separator="=" --key=1,1 --unique $1/uniq_lines $2/uniq_lines \
84    | sort - $1/uniq_lines | uniq --unique >$2/uniq_var
85
86for my_directory in $*
87  do
88  cd $my_directory
89  echo "Created file \"$my_directory/uniq_var\"."
90  sort uniq_lines uniq_var | uniq --unique >common_var
91  rm uniq_lines
92  cd - >/dev/null
93done
94
95$my_python $script_dir/compare_real.py $*
96sort common_lines --output=common_lines # was modified by the Python script
97echo "Created files \"./common_lines\" and \"./uniq_val\"."
98
99# Clean up:
100for my_directory in $*
101  do
102    rm $my_directory/common_var $my_directory/all.def
103done
Note: See TracBrowser for help on using the repository browser.