编辑--编辑--
将脚本的名称从pacsearch更改为pacdot。
显然,yaourt -Ssaq是这样做的,所以这个脚本没有我想的那么必要。尽管如此,我仍然发现使用pacdot -w打开文本文档中的结果很有帮助。
-编辑
这不是个问题,但我想其他人可能会觉得这很有用。有人可能最终会出现堆栈溢出,试图找到这样的解决方案。
在searching上,我不断地搜索pacman或yaourt,希望我能得到包名,而不是所有额外的东西。例如,我希望能够运行yaourt -Sa $(yaourt -Ssa package)。奇怪的是,pacman和yaourt似乎没有这个选项(至少据我所知),所以我编写了一个python脚本。如果你想抄的话。您可以将它命名为您想要的名称,但我将它称为pacdot.py。
pacdot.py package将与yaourt -Ssa package类似,但只列出包名。
我增加了一些额外的选项:
pacdot.py -o package只会列出官方拱形存储库的结果,而不是8月的结果。pacdot.py -i package将安装所有找到的软件包。如果您曾经考虑过运行类似于yaourt -Sa $(yaourt -Ssa package)的东西,那么这个命令就是这样做的。pacdot.py -w package将:1. Create a file called 'the-package-you-searched.txt',
2. Write an example command that would install the found packages,
(yaourt -Sa all-of-the-results),
3. Write each result on a new line, and
4. Open the file for you (with your default text editor). 下面是代码:
#!/bin/python3
import argparse
import re
from subprocess import Popen, PIPE, call
from collections import deque
desc = ''.join(('Search the official Arch and AUR databases ',
'and return package names only. ',
'e.g.: `pacdot.py arch` will return "arch", ',
'whereas `$ yaourt -Ssa arch` will return ',
'"community/arch 1.3.5-10',
' A modern and remarkable revision control system."'
))
parser = argparse.ArgumentParser(description=desc)
parser.add_argument('package',
help='Package to search with pacman')
parser.add_argument('-o', '--official', action='store_true',
help='Search official repositories only, not the AUR')
parser.add_argument('-i', '--install', action='store_true',
help='Install found packages')
parser.add_argument('-w', '--write', action='store_true',
help='Write to file')
#Set args strings.
args = parser.parse_args()
pkg = args.package
official_only = args.official
install = args.install
write = args.write
# Do yaourt search.
package_search = Popen(['yaourt', '-Ssa', '%s' % pkg], stdout=PIPE).communicate()
# Put each found package into a list.
package_titles_descs = str(package_search[0]).split('\\n')
# Strip off the packages descriptions.
package_titles = [package_titles_descs[i]
for i in range(0, len(package_titles_descs), 2)]
# Remove empty item in list.
del(package_titles[-1])
# Make a separate list of the non-aur packages.
package_titles_official = deque(package_titles)
[package_titles_official.remove(p)
for p in package_titles if p.startswith('aur')]
# Strip off extra stuff like repository names and version numbers.
packages_all = [re.sub('([^/]+)/([^\s]+) (.*)',
r'\2', str(p))
for p in package_titles]
packages_official = [re.sub('([^/]+)/([^\s]+) (.*)',
r'\2', str(p))
for p in package_titles_official]
# Mark the aur packages.
# (Not needed, just in case you want to modify this script.)
#packages_aur = packages_all[len(packages_official):]
# Set target packages to 'all' or 'official repos only'
# based on argparse arguments.
if official_only:
packages = packages_official
else:
packages = packages_all
# Print the good stuff.
for p in packages:
print(p)
if write:
# Write results to file.
filename = ''.join((pkg, '.txt'))
with open(filename, 'a') as f:
print(''.join(('Yaourt search for "', pkg, '"\n')), file=f)
print('To install:', file=f)
packages_string = ' '.join(packages)
print(' '.join(('yaourt -Sa', packages_string)), file=f)
print('\nPackage list:', file=f)
for p in packages:
print(p, file=f)
# Open file.
call(('xdg-open', filename))
if install:
# Install packages with yaourt.
for p in packages:
print(''.join(('\n\033[1;32m==> ', '\033[1;37m', p,
'\033[0m')))
Popen(['yaourt', '-Sa', '%s' % p]).communicate()发布于 2014-12-21 08:28:34
你刚刚重新发明了轮子。pacman、packer和yaourt都有-q标志。
例如:
yaourt -Ssq coreutils结果:
coreutils
busybox-coreutils
coreutils-git
coreutils-icp
coreutils-selinux
coreutils-static
cv
cv-git
ecp
gnu2busybox-coreutils
gnu2plan9-coreutils
gnu2posix2001-coreutils
gnu2sysv-coreutils
gnu2ucb-coreutils
policycoreutils
selinux-usr-policycoreutils-old
smack-coreutils
xml-coreutilshttps://stackoverflow.com/questions/27586964
复制相似问题