# upstream-observer **Repository Path**: oepkgs/upstream-observer ## Basic Information - **Project Name**: upstream-observer - **Description**: No description available - **Primary Language**: Unknown - **License**: MulanPSL-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 1 - **Created**: 2023-07-06 - **Last Updated**: 2023-10-30 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # Upstream Observer 软件包上游状态监控工具 ## 基础配置 所有主要配置存放在 config.toml 中,先将 config.toml.example 复制为 config.toml,然后根据需要修改配置。 ```bash cp config.toml.example config.toml ``` ### 配置文件样例及说明 ```toml [Gitee] token = "" org = "src-oepkgs" branch = "openEuler-22.03-LTS" [GitHub] token = "" [GitlabTokens] "gitlab.gnome.org" = "" ``` `[Gitee]` 部分为必选配置,org 对应目标组织,branch 对应目标分支。 上面的配置对应抓取 src-oepkgs 组织下所有仓库的 openEuler-22.03-LTS 分支下的 spec 文件。 Gitee 若不配置 Token,每小时的 API 请求量大约在 100 次左右,所以建议配置 Token。 `[GitHub]` 部分为可选配置。 Github 若不配置 Token,每小时的 API 请求量为 60 次,所以建议配置 Token。 `[GitlabTokens]` 部分为必选配置。 Gitlab 的仓库信息 API 需要 Token,所以必须配置。 同时,仅在此处配置了 Token 的 Gitlab 仓库才会被抓取。 例如,上面的配置对应通过 Gitlab API 抓取 gitlab.gnome.org 对应的仓库信息。 ## 执行过程 程序执行的主要过程如下: 1. 从 Gitee 抓取指定组织下的仓库列表 2. 从所有仓库的指定分支中抓取 spec 文件 3. 从 spec 文件中解析 URL、Source、版本号 4. 从上游抓取对应的数据 5. 从 Github 与 ArchLinux 的仓库中搜索对应的数据 6. 数据导出 其中,大部分上游的 API 限额在 1 秒/次,当数据量较大时,单次数据抓取耗时的总时间可能会持续数十个小时,建议在服务器上运行。 ## GUI 与 CLI 本项目提供了两种运行方式,GUI 与 CLI。 ### CLI 模式 若使用 CLI 模式,可以直接运行 `python3 main.py -a`,会自动执行抓取、解析、导出的过程。 更多的运行参数可以通过 `python3 main.py -h` 查看。 ### GUI 模式 若使用 GUI 模式,可以运行 `python3 ui.py`,在加载完成后会自动打开 `http://localhost:8080`。 可以点击按钮实现对应的功能。 如果需要修改运行的端口,可以修改程序最后 `ui.run()` 语句中的 `port=` 部分。 无论哪种运行方式,都需要按照以下流程串行进行: - 获取仓库列表 - 下载、解析 spec 文件 - 抓取、搜索(可选) 上游数据 - 数据导出 ## 关于 PyRPM [PyRPM](https://github.com/bkircher/python-rpm-spec) 是一个 Python 实现的 RPM 包解析工具,可以解析 RPM 包的文件列表、依赖关系等信息。 本项目中使用 PyRPM 实现对 spec 文件的解析。 其中极个别 spec 文件中出现了宏递归定义的情况,会导致宏展开出现死循环,因此需要修改库中的 spec.py 文件,将宏展开的次数限制在 20 次以内。 ```diff @@ -555,7 +555,11 @@ def replace_macros(string: str, spec: Spec) -> str: + count = 0 while True: + count = count + 1 + if count > 20: + raise RuntimeError("Too many macro expansions") ret = re.sub(_macro_pattern, get_replacement_string, string) if ret != string: string = ret ``` 截止本项目结项前,上游已经有人发起了 PR,但还未合并。