Skip to content

Commit

Permalink
Combining Multiple Developer Scripts into One (#621)
Browse files Browse the repository at this point in the history
* Rename Dockerfile to DockerFile

* Backup the files in the ~/.obdiag/ directory

* fix

* fixed: gather tabledump

* Simplify the display of table information in the tabledump result.

* fixed: unit test

* fixed: unit test

* fix

* Combining Multiple Developer Scripts into One

* Combining Multiple Developer Scripts into One

* Combining Multiple Developer Scripts into One
  • Loading branch information
Teingi authored Dec 12, 2024
1 parent 10bcb2c commit e7020f7
Show file tree
Hide file tree
Showing 7 changed files with 119 additions and 83 deletions.
5 changes: 2 additions & 3 deletions README-CN.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ sh /usr/local/oceanbase-diagnostic-tool/init.sh
源码安装需要在python >= 3.8的环境下进行

```shell
pip3 install -r requirements3.txt
./dev_init.sh
./dev_helper.sh init
source ~/.bashrc
```

Expand Down Expand Up @@ -110,7 +109,7 @@ git clone https://github.com/your_username/your_repo_here.git
3. 通过 black 工具统一格式化你的代码 🎨

```bash
black -S -l 256 {source_file_or_directory}
./dev_helper.sh format
```

4. 提交你的改动:完成优化后,利用Git提交你的修改。
Expand Down
5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,7 @@ sh /usr/local/oceanbase-diagnostic-tool/init.sh
To install obdiag on Python >= 3.8, run these commands:

```shell
pip3 install -r requirements3.txt
./dev_init.sh
./dev_helper.sh init
source ~/.bashrc
```

Expand Down Expand Up @@ -116,7 +115,7 @@ git clone https://github.com/your_username/your_repo_here.git
3. Format your code with black tool 🎨

```bash
black -S -l 256 {source_file_or_directory}
./dev_helper.sh format
```

4. Commit Your Changes: Once you've made your enhancements, commit them using Git.
Expand Down
12 changes: 0 additions & 12 deletions build_rpm.sh

This file was deleted.

4 changes: 0 additions & 4 deletions clean_all_result.sh

This file was deleted.

114 changes: 114 additions & 0 deletions dev_helper.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
#!/usr/bin/env bash

PROJECT_PATH=$(cd "$(dirname "$0")"; pwd)
WORK_DIR=$(readlink -f "$(dirname ${BASH_SOURCE[0]})")

build_rpm() {
export RELEASE=`date +%Y%m%d%H%M`
sed -i 's/pip install -r requirements3.txt/curl https:\/\/bootstrap.pypa.io\/get-pip.py -o get-pip.py\n\
python3 get-pip.py\n\
pip3 install -r requirements3.txt/' ./rpm/oceanbase-diagnostic-tool.spec
cat ./rpm/oceanbase-diagnostic-tool.spec
yum install rpm-build -y
rpmbuild -bb ./rpm/oceanbase-diagnostic-tool.spec
find ~/ -name oceanbase-diagnostic-tool-*.rpm
}


clean_files() {
rm -rf ./obdiag_gather_pack_* ./obdiag_analyze_pack_* ./obdiag_analyze_flt_result* ./obdiag_check_report
}


initialize_environment() {
export PYTHONPATH=$PYTHONPATH:$PROJECT_PATH
check_python_version() {
local version_output=$(python3 -c "import sys; print(sys.version_info.major, sys.version_info.minor)")
IFS=' ' read -ra version <<< "$version_output"

major=${version[0]}
minor=${version[1]}

if (( major < 3 || (major == 3 && minor < 8) )); then
echo "Your Python3 version is less than 3.8. Please updating Python3..."
exit 1
fi
}

install_requirements() {
REQ_FILE="${PROJECT_PATH}/requirements3.txt"
if [[ -f "$REQ_FILE" ]]; then
echo "Installing packages listed in $REQ_FILE..."
pip3 install -r "$REQ_FILE"
else
echo "No requirements3.txt file found at the expected location."
fi
}

copy_file(){
if [ ${OBDIAG_HOME} ]; then
OBDIAG_HOME=${OBDIAG_HOME}
else
OBDIAG_HOME="${HOME}/.obdiag"
fi

mkdir -p ${OBDIAG_HOME} && cd ${OBDIAG_HOME}
mkdir -p ${OBDIAG_HOME}/check
mkdir -p ${OBDIAG_HOME}/gather
mkdir -p ${OBDIAG_HOME}/display
cp -rf ${WORK_DIR}/plugins/* ${OBDIAG_HOME}/
if [ -d "${WORK_DIR}/example" ]; then
cp -rf ${WORK_DIR}/example ${OBDIAG_HOME}/
fi
}

copy_file
echo "File initialization completed"

check_python_version
install_requirements

source ${WORK_DIR}/rpm/init_obdiag_cmd.sh

echo "Creating or updating alias 'obdiag' to run 'python3 ${PROJECT_PATH}/src/main.py'"
echo "alias obdiag='PYTHONPATH=\$PYTHONPATH:${PROJECT_PATH} python3 ${PROJECT_PATH}/src/main.py'" >> ~/.bashrc
source ~/.bashrc
echo "Initialization completed successfully!"
}

show_help() {
echo "Usage: $0 {pack|clean|init|format}"
echo " pack - Start packaging rpm"
echo " clean - Clean result files"
echo " init - Initialize dev environment"
echo " format - Format code with black"
}

format_code() {
# Check if black is installed, if not, try to install it.
if ! command -v black &> /dev/null; then
echo "Black is not installed. Attempting to install..."
pip3 install --user black
fi

# Run black on the project directory with specified options.
black -S -l 256 .
}

case "$1" in
pack)
build_rpm
;;
clean)
clean_files
;;
init)
initialize_environment
;;
format)
format_code
;;
*)
show_help
;;
esac
60 changes: 0 additions & 60 deletions dev_init.sh

This file was deleted.

2 changes: 1 addition & 1 deletion src/common/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
absPath = os.path.dirname(os.path.abspath(sys.executable))
else:
absPath = os.path.dirname(os.path.abspath(__file__))
INNER_CONFIG_FILE = os.path.join(absPath, "conf/inner_config.yml")
INNER_CONFIG_FILE = os.path.join(absPath, "../../conf/inner_config.yml")

DEFAULT_CONFIG_DATA = '''
obcluster:
Expand Down

0 comments on commit e7020f7

Please sign in to comment.