如何整理gentoo系统上的.keywords文件?


10

gentoo stable通过在关键字列表中添加具有以下语法的行,可以选择系统上的测试程序包:

cat /etc/portage/package.keywords

=dev-python/ipython-0.13.2 ~amd64
# and many lines later
=dev-python/ipython-0.14.1 ~amd64
# and many lines later
>=dev-python/ipython-0.13.4 ~amd64

该文件将在一段时间内增长,迟早将不记得哪些行已过时。

如何不时使用脚本整理列表?

一行应该被删除,

  • 如果测试版本已经稳定
  • > =用于同一包
  • =用于具有较小版本号的相同软件包

如果您仍在观看,请参阅我的答案。
eyoung100

Answers:



3

我写了一个小的python脚本来解决这个问题。该逻辑查看文件中的每一行,package.accept_keywords并且仅作用于以=或开头的行<=。这些行具有最大绑定版本,因此我们可以检查是否需要它们。没有限定符或a >=的行将保持原样,因为我们不知道它们是否已过时。

然后解析我们关心的行,并检查软件包的安装版本。如果安装的版本比关键字的版本新,或者根本不再安装,则认为该关键字已过时。如果已安装的软件包与关键字版本是同一版本,则将检查已安装的软件包以查看其是否仍是关键字。如果已稳定,则该线已过时,否则将保留。

#!/bin/env python

import re
import portage

vartree = portage.db[portage.root]['vartree']

with open('/etc/portage/package.accept_keywords') as f:
    for x in f:
        # eat newline
        x = x.rstrip()
        # we only want lines with a bounded max version
        if re.match('^(=|<=)',x):
            # get the package cpv atom -- strip the =|<= and the trailing keyword(s)
            cpv_masked = re.sub('[<=]','',x.split(' ',1)[0])
            cat, pkg, ver, rev = portage.catpkgsplit(cpv_masked)
            # get cpv for all installed versions of the package
            cpv_installed = vartree.dep_match(cat+'/'+pkg)
            for cpv in cpv_installed:
                cmp = portage.pkgcmp(portage.pkgsplit(cpv), portage.pkgsplit(cpv_masked))
                # if the installed version is not newer than the masked version
                if (cmp <= 0):
                    # check if this version is still keyworded
                    cpv_keywords = vartree.dbapi.aux_get(cpv, ['KEYWORDS'])
                    # keep keyword if the package has no keywords (**)
                    if not cpv_keywords[0]:
                        print(x)
                        break
                    # check if the installed package is still keyworded
                    for cpv_keyword in cpv_keywords[0].split(' '):
                        if cpv_masked_keyword == cpv_keyword:
                            # it is, keep the atom and move on to the next one
                            print(x)
                            break                    
        else:
            # keep atoms that have an unbounded max version
            print(x)

这将把新的关键字文件打印为标准输出。 注意:请勿将输出重定向回,/etc/portage/package.accept_keywords否则将破坏文件并丢失所有内容。

这对于清理关键字文件和其他问题大有帮助,对文件进行排序,然后检查同一包的多行内容将有助于解决剩下的大部分问题。


1

您知道可以转换目录中的package。*文件,对吗?

然后,您可以将原子组织成几个文件,例如,在我的系统中,我得到了以下内容(嗯,不是,我现在不在我的笔记本电脑上。但是,您想出了办法):

/etc/portage/package.keywords:
  package.keywords
  qt5.keywords
  xfce.keywords

/etc/portage/package.use:
  package.use
  qt5.use
  xfce.use

等等

我发现这对帮助我更新文件非常有用。


0

添加到Ikraav的答案:

使用之后eix -tT,删除比较运算符和软件包版本号。您的文件也可以写成:

dev-python/ipython ~amd64
# and many lines later
package-cat/package ~arch

这将保证你总是会得到的测试版本dev-python/ipythonpackage-cat/package


~amd64在我的问题可能会被误导。版本号应保持不变。我不希望总是获得最新版本,而是找到多余的行。
乔纳斯·斯坦

使用没有版本的软件包将删除重复的条目。考虑软件包A需要> =软件包C版本1.0.0,而软件包B需要C版本1.0.1。实际上,任何大于1的版本都满足程序包A和B,并且如果〜arch中所有> 1.0.0的版本都在版本中,则版本号无关。解决此问题的唯一其他方法是屏蔽Portage C的所有版本,然后在可移植世界更新后取消屏蔽最大的Version。
eyoung100 2014年

我是老学校,我手动编辑了我的所有Portage配置文件,主要是因为我在Portage自动完成之前已经学会了如何做。重复的原因是因为当新版本取代旧版本时,portage不会删除该行。
eyoung100 2014年

0

这是一个小脚本,用于过滤/etc/portage/package.*文件中不再安装的条目。此外,它还会删除所有已删除条目正上方的注释行。(例如,通过自动unmask生成)。如果注释用空白行分隔,则只会删除较低的注释。该脚本不会删除重复的条目。

请注意,需要安装portage-utils,并且必须激活postsync钩子/etc/portage/postsync.d/q-reinitialize才能使此脚本正常工作。

#!/usr/bin/env python3

import argparse
import sys
import os
from subprocess import call
import contextlib

if __name__ != '__main__':
    raise Exception("ust be used as a main module with a parameter as the input file")

parser = argparse.ArgumentParser(description="cleanup /etc/portage/package.* files")
parser.add_argument("infile", help="an input file to clean")
parser.add_argument("--out", dest="outfile", help="the output is written to this file. if not specified, the output is written to stdout.")
parser.add_argument("--inplace", action='store_true', help="overwrite the in file. if specified, --out is ignored.")

args = parser.parse_args()

def checkInstalled(package):
    with open(os.devnull, 'w') as devnull:
        status = call('qlist -IC "' + str(package.split()[0].strip()) + '"', shell=True, stdout=devnull)
        return status == 0

@contextlib.contextmanager
def getOutFile(args):
    if args.inplace:
        fh = open(args.infile, 'w')
    elif args.outfile != None:
        fh = open(args.outfile, 'w')
    else:
        fh = sys.stdout
    try:
        yield fh
    finally:
        if fh is not sys.stdout:
            fh.close()

commentBuffer = []
lines = []

with open(args.infile, 'r') as f:
    lines = f.readlines()

with getOutFile(args) as out:
    for line in lines: 
        if line.lstrip().startswith("#"):
            commentBuffer.append(line)
        else:
            if line.strip() == "" or checkInstalled(line):
                if  commentBuffer:
                    out.write("".join(commentBuffer))
                out.write(line)
            commentBuffer = []

0

到目前为止,该app-portage/eix软件包提供了一个名为eix-test-obsolete便捷工具。来自的简短描述eix-test-obsolete -h

Usage: eix-test-obsolete [options] detail|brief|quick
  This is a wrapper script for eix (eix 0.33.5).

It calls eix -tTc several times with various variable settings in order to
display missing packages or packages with obsolete entries in
/etc/portage/package.* in a more organized manner than eix -tTc would do alone.

它很好地概述了/etc/portage/package.*文件中的所有冗余条目。我个人唯一缺少的是有关确切文件和行的信息,这些文件和行定义了冗余的unmask / use / accept / every。但是,grep -nr在这种情况下有帮助。

$ eix-test-obsolete -c
No non-matching entries in /etc/portage/package.keywords
No non-matching entries in /etc/portage/package.accept_keywords
No non-matching entries in /etc/portage/package.mask
No non-matching entries in /etc/portage/package.unmask
No non-matching or empty entries in /etc/portage/package.use
No non-matching or empty entries in /etc/portage/package.env
No non-matching or empty entries in /etc/portage/package.license
No non-matching or empty entries in /etc/portage/package.accept_restrict
No non-matching or empty entries in /etc/portage/package.cflags
The names of all installed packages are in the database.

Redundant in /etc/portage/package.{,accept_}keywords:

... considered as REDUNDANT_IF_NO_CHANGE
[I] app-accessibility/at-spi2-core (2.26.2(2)@11/30/2018): D-Bus accessibility specifications and registration daemon
[I] app-emulation/runc (1.0.0_rc5_p20180509@11/29/2018): runc container cli tools
[N] app-emulation/wine-staging ((~)3.21(3.21)): Free implementation of Windows(tm) on Unix, with Wine-Staging patchset
[I] sys-process/tini (0.18.0@11/29/2018): A tiny but valid init for containers
[1] "go-overlay" /var/db/repos/go-overlay

Found 4 matches


Not installed but in /etc/portage/package.{,accept_}keywords:
[N] app-emulation/wine-staging ((~)3.21(3.21)): Free implementation of Windows(tm) on Unix, with Wine-Staging patchset

No  redundant  entries in /etc/portage/package.mask
No uninstalled entries in /etc/portage/package.mask
No  redundant  entries in /etc/portage/package.unmask
No uninstalled entries in /etc/portage/package.unmask
Skipping check:  redundant  entries in /etc/portage/package.use
Skipping check: uninstalled entries in /etc/portage/package.use
Skipping check:  redundant  entries in /etc/portage/package.env
Skipping check: uninstalled entries in /etc/portage/package.env
No  redundant  entries in /etc/portage/package.license
No uninstalled entries in /etc/portage/package.license
No  redundant  entries in /etc/portage/package.accept_restrict
No uninstalled entries in /etc/portage/package.accept_restrict
Skipping check:  redundant  entries in /etc/portage/package.cflags
Skipping check: uninstalled entries in /etc/portage/package.cflags

Installed packages with a version not in the database (or masked):
[U] www-client/firefox (60.3.0-r1@12/01/2018 -> 60.4.0^d): Firefox Web Browser

-1

从开始eix -tT。安装app-portage/eix即可。


我不明白eix -tT如何解决这个问题。您能再解释一下吗?
乔纳斯·斯坦

我认为您必须粘贴一些输出并指向您不了解的零件的行号。
lkraav 2014年

我希望有更多信息。这导致“提示和技巧”,并且指向原始博客文章的链接已失效。这会有所帮助。该软件包最近处于活动状态。主页链接指向eix.berlios.de,但这不存在。该在线手册(哪里有所有选项)在哪里?
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.