开源 企业版 高校版 私有云 模力方舟 AI 队友
代码拉取完成,页面将自动刷新
加入 Gitee
与超过 1400万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
已有帐号? 立即登录
文件
master
分支 (2)
标签 (2)
master
feat/add_timeout
v1.0.0_beta2
v1.0.0_beta1
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
项目仓库所选许可证以仓库主分支所使用许可证为准
master
分支 (2)
标签 (2)
master
feat/add_timeout
v1.0.0_beta2
v1.0.0_beta1
克隆/下载
克隆/下载
提示
下载代码请复制以下命令到终端执行
为确保你提交的代码身份被 Gitee 正确识别,请执行以下命令完成配置
初次使用 SSH 协议进行代码克隆、推送等操作时,需按下述提示完成 SSH 配置
1 生成 RSA 密钥
2 获取 RSA 公钥内容,并配置到 SSH公钥
在 Gitee 上使用 SVN,请访问 使用指南
使用 HTTPS 协议时,命令行会出现如下账号密码验证步骤。基于安全考虑,Gitee 建议 配置并使用私人令牌 替代登录密码进行克隆、推送等操作
Username for 'https://gitee.com': userName
Password for 'https://userName@gitee.com': # 私人令牌
master
分支 (2)
标签 (2)
master
feat/add_timeout
v1.0.0_beta2
v1.0.0_beta1
qpm
/
command_ls.py
qpm
/
command_ls.py
command_ls.py 8.30 KB
一键复制 编辑 原始数据 按行查看 历史
chenchi 提交于 2025年03月12日 21:44 +08:00 . Removed github access token.
import subprocess
import sys
from pathlib import Path
from common import (
check_in_project,
get_git_access_token,
get_git_api_url_org,
request_get)
from command_ls_p import get_and_print_remote_repo_tree
def get_submodule_info(submodule_path):
"""
Get the commit-id (first 7 characters), current branch name, and current version (git tag) of the submodule.
"""
info = {}
submodule_abs_path = Path(submodule_path)
# Get the commit-id (first 7 characters)
git_rev_parse_command = ['git', 'rev-parse', '--verify', 'HEAD']
full_commit_id = subprocess.check_output(git_rev_parse_command, cwd=submodule_abs_path, text=True).strip()
info['commit_id'] = full_commit_id[:7]
# Get the current branch name
git_branch_command = ['git', 'symbolic-ref', '--short', '-q', 'HEAD']
info['current_branch'] = subprocess.check_output(git_branch_command, cwd=submodule_abs_path, text=True).strip()
# Get the current version (latest git tag)
try:
git_describe_command = ['git', 'describe', '--tags', '--abbrev=0']
info['current_version'] = subprocess.check_output(git_describe_command, cwd=submodule_abs_path, stderr=subprocess.DEVNULL, text=True).strip()
except subprocess.CalledProcessError as e:
if e.returncode != 0:
info['current_version'] = ''
return info
def get_git_repo_tree_recursively(base_path, repo_tree=None, processed_submodules=set(), root_path=None):
if repo_tree is None:
repo_tree = []
current_path = Path(base_path)
submodule_list_command = ['git', 'submodule', 'status']
submodule_status_output = subprocess.check_output(submodule_list_command, cwd=current_path, text=True)
submodule_lines = submodule_status_output.splitlines()
for line in submodule_lines:
# Parse the submodule status line to get the submodule path and SHA
submodule_info = line.strip().split(' ')
submodule_path = submodule_info[1]
# Construct the absolute path of the submodule
submodule_abs_path = current_path / submodule_path
# Avoid processing already processed submodules
if submodule_abs_path in processed_submodules:
continue
processed_submodules.add(submodule_abs_path)
# Get detailed information of the submodule
submodule_info = get_submodule_info(submodule_abs_path)
# Calculate the relative path of the submodule to the top-level repository
relative_submodule_path = submodule_abs_path.relative_to(root_path)
# Create a dictionary for the submodule and add it to the current repository tree
submodule_repo_dict = {
'repo_path': str(relative_submodule_path),
'commit_id': submodule_info.get('commit_id'),
'current_branch': submodule_info.get('current_branch'),
'current_version': submodule_info.get('current_version') or '',
'submodules': []
}
repo_tree.append(submodule_repo_dict)
# Recursively process nested submodules
get_git_repo_tree_recursively(submodule_abs_path, submodule_repo_dict['submodules'], processed_submodules, root_path=root_path)
return repo_tree
def highlight(text, color_code):
return f'033円[{color_code}m{text}033円[0m'
def print_git_repo_tree(repo_tree, indent=0, is_last=False):
for i, repo in enumerate(repo_tree):
branch_symbol = '├──' if i < len(repo_tree) - 1 else '└──'
info_line = f' {indent * " "}{highlight(branch_symbol + " " + repo["repo_path"], 35)}'
if any([repo['commit_id'], repo['current_branch'], repo['current_version']]):
info_line += ' ('
if repo['commit_id']:
info_line += f'commit: {highlight(repo["commit_id"], 32)}, '
if repo['current_branch']:
info_line += f'branch: {highlight(repo["current_branch"], 33)}, '
if repo['current_version']:
info_line += f'version: {highlight(repo["current_version"], 36)}'
info_line = info_line.rstrip(', ') + ')'
print(info_line)
if repo['submodules']:
print_git_repo_tree(repo['submodules'], indent + 2, is_last=(i == len(repo_tree) - 1))
def get_and_print_git_repo_tree():
top_level_path = subprocess.check_output(['git', 'rev-parse', '--show-toplevel'], text=True).strip()
# Get detailed information of the top-level repository
top_repo_info = {
'repo_path': '.',
'commit_id': subprocess.check_output(['git', 'rev-parse', '--verify', 'HEAD'], cwd=top_level_path, text=True).strip()[:7],
'current_branch': subprocess.check_output(['git', 'symbolic-ref', '--short', '-q', 'HEAD'], cwd=top_level_path, text=True).strip(),
'current_version': ''
}
# Try to get the latest git tag of the top-level repository
try:
git_describe_command = ['git', 'describe', '--tags', '--abbrev=0']
top_repo_info['current_version'] = subprocess.check_output(git_describe_command, cwd=top_level_path, stderr=subprocess.DEVNULL, text=True).strip()
except subprocess.CalledProcessError as e:
if e.returncode != 0:
top_repo_info['current_version'] = ''
# Print the information of the top-level repository ensuring that the information is highlighted
print_git_repo_tree_entry(top_repo_info['repo_path'], top_repo_info, highlight_top=True)
repo_tree = get_git_repo_tree_recursively(top_level_path, root_path=top_level_path)
print_git_repo_tree(repo_tree)
def print_git_repo_tree_entry(path, info, highlight_top=False):
commit_id = info.get('commit_id')
current_branch = info.get('current_branch')
current_version = info.get('current_version') or ''
# If it's the top-level repository, use highlighting
if highlight_top:
commit_id = highlight(commit_id, 32)
current_branch = highlight(current_branch, 33)
current_version = highlight(current_version, 36)
print(f"{' ' * 0}{highlight('├── ' + path, 35)} (commit: {commit_id}, branch: {current_branch}, version: {current_version})")
def get_and_print_remote_git_repos():
repos = []
page = 1
while True:
api_url = get_git_api_url_org()
response = request_get(api_url, params={'page': page, 'per_page': 100})
response.raise_for_status()
current_repos = response.json()
repos.extend(repo['name'] for repo in current_repos)
if len(current_repos) < 100:
break
page += 1
for repo in repos:
print(repo)
# List package information
def list_packages(local=True, remote=False, remote_pkg_name=None, version=None):
try:
if local:
if version:
print("Error: The -v option can only be used with the -p option, but is not required.")
sys.exit(1)
if remote or remote_pkg_name:
print("Error: Cannot simultaneously use the options -l, -r and -p for `ls` command.")
sys.exit(1)
if not check_in_project():
print("Error: Current directory is not in QuecPython project.")
sys.exit(1)
get_and_print_git_repo_tree() # ls -l
elif remote:
if version:
print("Error: The -v option can only be used with the -p option, but is not required.")
sys.exit(1)
if remote_pkg_name:
print("Error: Cannot simultaneously use the options -l, -r and -p for `ls` command.")
sys.exit(1)
get_and_print_remote_git_repos() # ls -r
elif remote_pkg_name:
get_and_print_remote_repo_tree(remote_pkg_name, version) # ls -p <remote_pkg_name> [-v <version>]
elif version:
print("Error: The -v option can only be used with the -p option, but is not required.")
sys.exit(1)
else:
if not check_in_project():
print("Error: Current directory is not in QuecPython project.")
sys.exit(1)
get_and_print_git_repo_tree() # ls
except Exception as e:
print(f"Error: Failed to list packages: {e}")
sys.exit(1)
Loading...
举报
举报成功
我们将于2个工作日内通过站内信反馈结果给你!
请认真填写举报原因,尽可能描述详细。
请选择举报类型
取消
发送
误判申诉

此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。

如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。

取消
提交

简介

QuecPython Project Manager
取消

发行版

暂无发行版

贡献者

全部

近期动态

不能加载更多了
编辑仓库简介
简介内容
主页
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
1
https://gitee.com/quecpython/qpm.git
git@gitee.com:quecpython/qpm.git
quecpython
qpm
qpm
master
点此查找更多帮助

搜索帮助

评论
仓库举报
回到顶部
登录提示
该操作需登录 Gitee 帐号,请先登录后再操作。
立即登录
没有帐号,去注册

AltStyle によって変換されたページ (->オリジナル) /