检查各个ros包仓库git状态

#!/usr/bin/python3

import os
import subprocess
import sys
from prettytable import PrettyTable

# 获取命令行参数
dir = sys.argv[1]

# 切换到指定目录
os.chdir(dir)

# 获取当前目录下的所有子目录
subdirs = [d for d in os.listdir('.') if os.path.isdir(d)]

# 创建表格
table1 = PrettyTable(['子目录', '工作区', '本地分支'])
table2 = PrettyTable(['子目录', '工作区', '本地分支'])

# 遍历所有子目录
for subdir in subdirs:
    # 检查子目录是否是Git仓库
    if os.path.exists(os.path.join(subdir, '.git')):
        # 切换到子目录
        os.chdir(subdir)
        # 检查工作区是否clean
        if subprocess.call(['git', 'diff', '--quiet']) == 0:
            workspace = 'clean'
        else:
            workspace = 'dirty'
        # 检查本地分支是否和远程分支保持同步
        if subprocess.call(['git', 'diff', '@{upstream}', '--quiet']) == 0:
            branch = '同步'
        else:
            branch = '不同步'
        # 添加行到表格
        if workspace == 'clean' and branch == '同步':
            table1.add_row([subdir, workspace, branch])
        else:
            table2.add_row([subdir, workspace, branch])
        # 切换回上级目录
        os.chdir('..')

# 打印表格
print('符合条件的结果:')
print(table1)

# 打印表格
print('不符合条件的结果:')
print(table2)

下载Google Drive文件脚本

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

ggID='file_id'
ggURL='https://drive.google.com/uc?export=download'

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