-
Notifications
You must be signed in to change notification settings - Fork 2
/
b2analysis-create
executable file
·131 lines (120 loc) · 4.54 KB
/
b2analysis-create
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
#!/bin/bash
VALID_GROUP_NAMES="bhad charm dark-lm ewp quark slme tau tdcpv"
# check for help option
if [ "$1" = "--help" -o "$1" = "-h" -o "$1" = "-?" ]; then
echo
echo "Usage: `basename $0` directory release [group]"
echo
echo "- This command creates a local directory with the given name"
echo " for the development of analysis code."
echo " It also prepares the build system and adds the analysis"
echo " directory to git."
echo "- The second argument specifies the central release on which"
echo " the analysis should be based."
echo "- If the third argument is given the repository is created"
echo " in the given physics working group directory."
echo " Valid physics working group names are"
echo " ${VALID_GROUP_NAMES}"
echo
exit 0
fi
# check number of arguments
if [ $# -gt 3 ] || [ $# -lt 2 ]; then
echo "Usage: `basename $0` directory release [group]" 1>&2
exit 1
fi
# read arguments
DIR=$1
if [ -d ${DIR} ]; then
echo "Error: The directory ${DIR} already exists." 1>&2
exit 1
fi
RELEASE=$2
if [ ! -d ${VO_BELLE2_SW_DIR}/releases/${RELEASE} ]; then
echo "Error: The central release ${RELEASE} does not exist." 1>&2
exit 1
fi
if [ $# -gt 2 ]; then
if [[ "$VALID_GROUP_NAMES" =~ (" "|^)$3(" "|$) ]]; then
ANALYSIS_PROJECT="belle2/physics/$3/${DIR}"
else
echo "Error: The group name $3 does not exist." 1>&2
exit 1
fi
else
ANALYSIS_PROJECT=${BELLE2_ANALYSES_PROJECT}/${BELLE2_USER}_${DIR}
fi
# check git access
git ls-remote ${BELLE2_SOFTWARE_REPOSITORY} main > /dev/null
if [ "$?" != "0" ]; then
echo "Error: Could not access the git server." 1>&2
exit 1
fi
# check whether this analysis git repository already exists
ANALYSIS_REPOSITORY=${BELLE2_GIT_SERVER}${ANALYSIS_PROJECT}.git
REPOSITORY_EXISTS_MASTER=`git ls-remote ${ANALYSIS_REPOSITORY} master 2> /dev/null | wc -l`
REPOSITORY_EXISTS_MAIN=`git ls-remote ${ANALYSIS_REPOSITORY} main 2> /dev/null | wc -l`
if [ "${REPOSITORY_EXISTS_MASTER}" = "1" ] || [ "${REPOSITORY_EXISTS_MAIN}" = "1" ]; then
echo "Error: The analysis git repository https://gitlab.desy.de/${ANALYSIS_PROJECT} already exists." 1>&2
exit 1
fi
# check support of release version
SUPPORTED_RELEASE=`b2anypython -c 'from versioning import supported_release;import sys;print(supported_release(sys.argv[1]))' ${RELEASE}`
if [ "${RELEASE}" != "${SUPPORTED_RELEASE}" ]; then
echo "Warning: The release ${RELEASE} is not supported any more. It is recommended to use ${SUPPORTED_RELEASE} instead." 1>&2
read -p "Would you like to continue nevertheless (y/n)? " -n 1 REPLY
echo
if [ "$REPLY" != "y" ]; then
exit 0
fi
fi
# create analysis git repository
NAME=$(basename ${ANALYSIS_PROJECT})
GROUP=$(dirname ${ANALYSIS_PROJECT})
echo "Enter your DESY password to create your analysis directory on the gitlab server."
wget --ca-certificate=${BELLE2_TOOLS}/certchain.pem --user=${BELLE2_USER} --ask-password --auth-no-challenge -o /dev/null -O /dev/null --post-data="name=${NAME}&group=${GROUP}" "https://software.belle2.org/create_analysis"
if [ "$?" = "0" ]; then
sleep 2
REMOTE_EXISTS=1
git clone ${ANALYSIS_REPOSITORY} ${DIR}
cd ${DIR}
git switch --create main
else
echo "WARNING: The creation of the analysis directory on the gitlab server failed. Go to https://gitlab.desy.de/"${GROUP}", click \"New project\" and \"Create blank project\", then enter the Name \""${NAME}"\" as project name, deactivate the initialization with a README, and click the \"Create project\" button."
REMOTE_EXISTS=0
mkdir ${DIR}
cd ${DIR}
git init
git checkout -b main
git remote add origin ${ANALYSIS_REPOSITORY}
fi
# get site-scons and write release version to .analysis
ln -s ${VO_BELLE2_SW_DIR}/releases/${RELEASE}/site_scons .
ln -s site_scons/SConstruct .
cat > SConscript <<EOT
Import('env')
# This file specifies the dependencies of your analysis code to parts of the
# Belle II Software. It should be fine for most analyses but if you need to link
# against additional libraries please put them here.
env['LIBS'] = [
'mdst_dataobjects',
'analysis_dataobjects',
'analysis',
'framework',
'\$ROOT_LIBS',
]
Return('env')
EOT
echo ${RELEASE} > .analysis
# commit to git
echo site_scons > .gitignore
echo SConstruct >> .gitignore
git add .analysis .gitignore SConscript
git commit -a -m "Analysis ${DIR} by ${BELLE2_USER}"
if [ "${REMOTE_EXISTS}" = "1" ]; then
git push -u origin main
fi
# inform user about successful completion
echo
echo "New analysis directory created for ${RELEASE} release: ${DIR}"
echo "-> change to the new directory and set up the environment: cd ${DIR}; b2setup"