Skip to content

Commit

Permalink
✨ 添加 Poetry支持; 添加Git仓库同步支持
Browse files Browse the repository at this point in the history
  • Loading branch information
233Official committed Oct 18, 2024
1 parent 7b86b2e commit 323d437
Show file tree
Hide file tree
Showing 5 changed files with 269 additions and 2 deletions.
3 changes: 3 additions & 0 deletions install/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
from summerlog import logger
import httpx
from download_extract_zip import download_extract_zips
from sync_git_repo import sync_git_repos


CURRENT_DIR = Path(__file__).resolve().parent
Expand Down Expand Up @@ -33,6 +34,8 @@ def main():
logger.info("代理可用, 进入安装流程")
os_name_lower = platform.system().lower()
download_extract_zips(os_name_lower=os_name_lower, proxies=PROXIES)
sync_git_repos(http_proxy=HTTP_PROXY)


if __name__ == "__main__":
main()
190 changes: 190 additions & 0 deletions install/poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

17 changes: 17 additions & 0 deletions install/pyproject.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
[tool.poetry]
name = "install"
version = "0.1.0"
description = ""
authors = ["233 <[email protected]>"]
readme = "README.md"

[tool.poetry.dependencies]
python = "^3.12"
gitpython = "^3.1.43"
httpx = "^0.27.2"
colorlog = "^6.8.2"


[build-system]
requires = ["poetry-core"]
build-backend = "poetry.core.masonry.api"
4 changes: 2 additions & 2 deletions install/summerlog.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
logging.Formatter("%(asctime)s - %(name)s - %(levelname)s - %(message)s")
)

# logging.basicConfig(level=logging.DEBUG, handlers=[file_handler, handler])
logging.basicConfig(level=logging.INFO, handlers=[file_handler, handler])
logging.basicConfig(level=logging.DEBUG, handlers=[file_handler, handler])
# logging.basicConfig(level=logging.INFO, handlers=[file_handler, handler])


logger = logging.getLogger(__name__)
57 changes: 57 additions & 0 deletions install/sync_git_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import git
from pathlib import Path
from summerlog import logger
import os

CURRENT_DIR = Path(__file__).resolve().parent
PROJECT_BASE_DIR = (CURRENT_DIR / "..").resolve()

GIT_REPO_DICT = {
"java-memshell-generator": {
"git_repo_url": "https://github.com/pen4uin/java-memshell-generator.git",
"local_repo_path": PROJECT_BASE_DIR
/ "Security/Web/MemShell/generator/java-memshell-generator/src/java-memshell-generator",
},
"antSword":{
"git_repo_url": "https://github.com/AntSwordProject/antSword.git",
"local_repo_path": PROJECT_BASE_DIR / "Security/Web/webshell/manager/AntSword/App/antSword",
},
"marshalsec":{
"git_repo_url": "https://github.com/mbechler/marshalsec.git",
"local_repo_path": PROJECT_BASE_DIR / "Security/Web/Unmarshall/marshalsec/src/marshalsec",
}
}


def sync_git_repo(
git_repo_name: str, git_repo_url: str, local_repo_path: Path, http_proxy: str = None
) -> None:
"""同步预定义的Git仓库到本地"""
# 首先检查本地仓库路径是否存在, 存在则结束
if local_repo_path.exists():
logger.info(f"本地仓库已存在: {local_repo_path}")
return
if http_proxy:
os.environ["http_proxy"] = http_proxy
os.environ["https_proxy"] = http_proxy

# 本地仓库不存在, 克隆仓库
logger.info(f"开始克隆仓库: {git_repo_name}{local_repo_path} ......")
git.Repo.clone_from(url=git_repo_url, to_path=local_repo_path)
if local_repo_path.exists():
logger.info(f"克隆仓库成功: {git_repo_name}")
else:
logger.error(f"克隆仓库失败: {git_repo_name}")


def sync_git_repos(git_repo_dict: dict=GIT_REPO_DICT, http_proxy: str = None) -> None:
"""同步多个Git仓库"""
logger.info("开始同步Git仓库 ......")
for git_repo_name, git_repo_info in git_repo_dict.items():
sync_git_repo(
git_repo_name=git_repo_name,
git_repo_url=git_repo_info["git_repo_url"],
local_repo_path=git_repo_info["local_repo_path"],
http_proxy=http_proxy,
)
logger.info("Git仓库同步完成")

0 comments on commit 323d437

Please sign in to comment.