debiancn / repo

Debian CN Community Repo
230 stars 16 forks source link

RFC: 以后每次更新仓库的话,在这儿记录一下对应的操作 #174

Open Yanhao opened 5 years ago

Yanhao commented 5 years ago

对仓库的操作主要有:

标题格式为:[U|R|N]: package version IN codename BY login_user_name U,R,N分别对应update,remove,new login_user_name是repo.debiancn.org上的登录名。

比如:

U: atom 1.34.0 IN buster BY moyanhao

如果有进一步的描述可以写在正文里,没有就算了。

我会每个月做一个整理,发一个统计出来,当做 repo.debiancn.org 新闻的一部分

@hosiet @yangfl @alim0x @cdluminate

yangfl commented 5 years ago

🌝👎哪有那么多空闲时间比比这些,没有自动化工具一律差评

cdluminate commented 5 years ago

给 aptly/reprepro 写个包装脚本,记录每次命令。日志本身就可以作为你想要的新闻。

cdluminate commented 5 years ago

今天tg里不也提到的divert功能,就很适合干这种事情。把 /usr/bin/aptly divert到 /usr/bin/aptly.real ,然后 /usr/bin/aptly 放包装脚本

Yanhao commented 5 years ago

@yangfl 🌝自动化工具这么好写的吗。 @cdluminate 这样吗?感觉错误不好处理。

#!/usr/bin/env python3
# -*- encoding: utf-8 -*-

import os
import sys
import pwd
import subprocess
import debian.debfile
import logging

class AptlyWrapper:
    def __init__(self):
        logging.basicConfig(level=logging.INFO,
                            file='/home/repo/repo.log',
                            format='%(asctime)s : %(message)s')

        self.subcommand = None
        self.username = None
        self.operation = None
        self.codename = None
        self.packages = list()
        self.arg_parse(sys.argv)

        with open('/proc/self/loginuid') as f:
            loginuid = int(f.read().strip())
            p = pwd.getpwuid(loginuid)
            self.username = p.pw_name

    def arg_parse(self, args):
        def do_parse(args):
            for i, v in enumerate(args):
                if v.strip()[0] != '-':
                    yield v.strip()

        parser = do_parse(args[1:])

        self.subcommand = next(parser)
        if self.subcommand != 'repo':
            return

        self.operation = next(parser)
        self.codename = next(parser)

        packages = list()
        for i in reversed(args):
            if i.strip()[0] != '-' and i[-4:] == '.deb':
                packages.append(i.strip())
            else:
                break

        try:
            for i in packages:
                dpc = debian.debfile.DebFile(i).control.debcontrol()
                self.packages.append((dpc['Package'], dpc['Version']))
        except Exception:
            pass

    def run(self):
        status = subprocess.run(sys.argv)
# 这个地方的错误不好处理
        if self.subcommand != 'repo' or self.operation not in ['add', 'remove']:
            return

        logging.info('Run command line: %s', " ".join(sys.argv))
        logging.info('Return value: %d', status.check_returncode())
        for i in self.packages:
            logging.info('%s: %s %s IN %s BY %s',
                         self.operation, i[0], i[1],
                         self.codename, self.username)

if __name__ == '__main__':
    AptlyWrapper().run()
yangfl commented 5 years ago

🌝你是不是忘了auto_upload.sh了