Add Tizen:Common/update_meta.sh to update metadata from OBS 64/25664/4
authorStephane Desneux <stephane.desneux@open.eurogiciel.org>
Thu, 7 Aug 2014 17:03:05 +0000 (19:03 +0200)
committerStéphane Desneux (sdx) <stephane.desneux@open.eurogiciel.org>
Wed, 27 Aug 2014 14:19:14 +0000 (07:19 -0700)
The script fetches:
- project config and meta (_config, _meta)
- all aggregate packages definitions (_aggregate, _meta)
- all linked packages definitions (_link files)

The script also deletes directories (packages) that have disappeared
on the remote OBS

Change-Id: If4c9c4cad5d63fc7aa9a40d74289b9569f4fb905
Signed-off-by: Stephane Desneux <stephane.desneux@open.eurogiciel.org>
Tizen:Common/update_meta.sh [new file with mode: 0755]

diff --git a/Tizen:Common/update_meta.sh b/Tizen:Common/update_meta.sh
new file mode 100755 (executable)
index 0000000..61cf44a
--- /dev/null
@@ -0,0 +1,84 @@
+#!/bin/bash 
+
+API=https://api.tizen.org
+PRJ=${1:-Tizen:Common}
+
+PARALLEL_JOBS=8
+
+set -e
+
+function parallel_jobs {
+       local max_number=$((0 + ${1:-0}))
+       while true; do
+               jobs &>/dev/null
+               if [[ $(jobs -p | wc -l) -lt $max_number ]]; then
+                       break
+               fi
+               sleep 0.3
+       done
+}
+
+cd $(dirname $0)
+
+# fetch project config
+echo "Fetching project config for $PRJ"
+osc -A $API meta prjconf $PRJ >_config
+
+# fetch project meta
+echo "Fetching project meta for $PRJ"
+osc -A $API meta prj $PRJ >_meta
+
+# check that each subdir exists on OBS project
+shopt -s extglob
+for file in $(ls */@(_aggregate|_link)); do
+       pkg=$(dirname $file)
+       echo "Checking $pkg"
+       if ! osc -A $API ls $PRJ $pkg &>/dev/null; then
+               echo "Package $pkg was removed on OBS. Removing dir $pkg."
+               git rm -rf $pkg
+       fi
+done
+
+function check_package() {
+       pkg=$1
+       pkgtype="X"
+
+       # fetch file list for each package and deduce type
+       for filename in $(osc -A $API ls -u $PRJ $pkg); do
+               case $filename in
+                       _aggregate)     pkgtype="A"; break;;
+                       _link)          pkgtype="L"; break;;
+                       _service)       pkgtype="S"; break;;
+                       *)                      pkgtype="U"; break;;
+               esac
+       done
+       msg="$pkgtype $pkg"
+
+       # uddate aggregate and link packages
+       case $pkgtype in
+               A)
+                       mkdir -p $pkg
+                       osc -A $API api /source/$PRJ/$pkg/_aggregate >$pkg/_aggregate
+                       osc -A $API api /source/$PRJ/$pkg/_meta >$pkg/_meta
+                       msg="$msg (updated)"
+                       ;;
+               L)
+                       mkdir -p $pkg
+                       osc -A $API api /source/$PRJ/$pkg/_link >$pkg/_link
+                       msg="$msg (updated)"
+                       ;;
+               *)
+                       ;;
+       esac
+
+       echo $msg
+}
+
+# fetch packages list 
+osc -A $API ls $PRJ | while read pkg; do
+       parallel_jobs $PARALLEL_JOBS
+       check_package $pkg &
+done
+
+parallel_jobs 1
+