Skip to content
Snippets Groups Projects
update_duplicate_sources 2.75 KiB
#!/bin/zsh
# vim: set shiftwidth=4 softtabstop=4 tabstop=4 expandtab:
#
# This script update another repository that is a copy of the sources
# 
# Assertion:
# - the source project already exist on bitbucket and its name is the same as the metaproject+_sources
# - the metaproject is the same type as the sources one

here=$(dirname $0)
project_home=$(cd $here && cd .. && echo $PWD)
project_name=$(basename $project_home)
python=python

source_name=${project_name}_sources

odoo_modules=($($python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print(c.has_section('odoo_scripts') and c.has_option('odoo_scripts', 'modules') and ' '.join(c.get('odoo_scripts', 'modules', '').split()) or '' )"))
dependencies=($($python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print(c.has_section('odoo_scripts') and c.has_option('odoo_scripts', 'dependencies') and ' '.join(c.get('odoo_scripts', 'dependencies', '').split()) or '' )"))
other_sources=($($python -B -c "import ConfigParser ; c = ConfigParser.ConfigParser() ; c.read('${project_home}/setup.cfg') ; print(c.has_section('odoo_scripts') and c.has_option('odoo_scripts', 'other_sources') and ' '.join(c.get('odoo_scripts', 'other_sources', '').split()) or '' )"))

# color stuff
autoload colors && colors
for COLOR in RED GREEN YELLOW BLUE MAGENTA CYAN BLACK WHITE; do
    eval $COLOR='$fg_no_bold[${(L)COLOR}]'
    eval BOLD_$COLOR='$fg_bold[${(L)COLOR}]'
done
eval RESET='$reset_color'

pushd $project_home

if [ -e ".hg" ]; then
    branch="$(hg id -b)"
    tags=($(hg id -t))
    hg clone ssh://hg@bitbucket.org/xcg/${source_name} || exit 1
    pushd $source_name
    hg update $branch
    branch_exist=$?
    popd
    echo "${YELLOW}INFO ${RESET} - branch_exist=$branch_exist"
    # Remove any content inside it
    rm -rf ${source_name}/*
    rsync -rRLtC --exclude=.hgtags --exclude=.hgignore $(eval echo $odoo_modules $dependencies $other_sources) $source_name
    pushd $source_name
    hg addremove
    if [[ "x$branch_exist" != "x0" ]];
    then
        hg branch $branch
    fi
    hg commit -m"Update sources"
    # Tagging process only works if done locally
    if [[ "$tags" != "tip" ]]; then
        id_to_tag=$(hg id -i)
        for tag in $tags; do
            echo "${YELLOW}INFO ${RESET} - Add tag $tag"
            hg tag $tag -r $id_to_tag
        done
    fi
    if [[ "x$branch_exist" != "x0" ]];
    then
        echo "${YELLOW}INFO ${RESET} - Pushing new branch $branch"
        hg push --new-branch
    else
        echo "${YELLOW}INFO ${RESET} - Pushing branch $branch"
        hg push
    fi
    popd
    rm -rf ${source_name}
else
    echo "${RED}ERROR${RESET} - Repository VCS unknown/not handled"
    popd
    exit 1
fi

popd