检查各个ros包仓库git状态

 1#!/usr/bin/python3
 2
 3import os
 4import subprocess
 5import sys
 6from prettytable import PrettyTable
 7
 8# 获取命令行参数
 9dir = sys.argv[1]
10
11# 切换到指定目录
12os.chdir(dir)
13
14# 获取当前目录下的所有子目录
15subdirs = [d for d in os.listdir('.') if os.path.isdir(d)]
16
17# 创建表格
18table1 = PrettyTable(['子目录', '工作区', '本地分支'])
19table2 = PrettyTable(['子目录', '工作区', '本地分支'])
20
21# 遍历所有子目录
22for subdir in subdirs:
23    # 检查子目录是否是Git仓库
24    if os.path.exists(os.path.join(subdir, '.git')):
25        # 切换到子目录
26        os.chdir(subdir)
27        # 检查工作区是否clean
28        if subprocess.call(['git', 'diff', '--quiet']) == 0:
29            workspace = 'clean'
30        else:
31            workspace = 'dirty'
32        # 检查本地分支是否和远程分支保持同步
33        if subprocess.call(['git', 'diff', '@{upstream}', '--quiet']) == 0:
34            branch = '同步'
35        else:
36            branch = '不同步'
37        # 添加行到表格
38        if workspace == 'clean' and branch == '同步':
39            table1.add_row([subdir, workspace, branch])
40        else:
41            table2.add_row([subdir, workspace, branch])
42        # 切换回上级目录
43        os.chdir('..')
44
45# 打印表格
46print('符合条件的结果:')
47print(table1)
48
49# 打印表格
50print('不符合条件的结果:')
51print(table2)

下载Google Drive文件脚本

原脚本地址: https://github.com/HongbiaoZ/autonomous_exploration_development_environment/blob/melodic/src/vehicle_simulator/mesh/download_environments.sh

1ggID='file_id'
2ggURL='https://drive.google.com/uc?export=download'
3
4filename="$(curl -sc /tmp/gcokie "${ggURL}&id=${ggID}" | grep -o '="uc-name.*</span>' | sed 's/.*">//;s/<.a> .*//')"
5html=`curl -c /tmp/gcokie -s -L "https://drive.google.com/uc?export=download&id=${ggID}"`
6curl -Lb /tmp/gcokie "https://drive.google.com/uc?export=download&`echo ${html}|grep -Po '(confirm=[a-zA-Z0-9\-_]+)'`&id=${ggID}" -o ${filename}