You are not logged in.

#1 2014-12-21 05:30:07

GreenRaccoon23
Member
Registered: 2014-09-27
Posts: 33

How to Return List of Packages from Pacman/Yaourt Search

----EDIT----
Changed the name of the script from pacsearch to pacdot.

Apparently yaourt -Ssaq does this, so this script isn't as necessary as I thought. hmm Although, I still find using pacdot -w to open the results in a text document helpful.
----/EDIT----

This isn't a question; it's a script I wrote. I thought someone else might find this useful.

I keep finding myself searching with pacman or yaourt and wishing I could get just the package names, not all of the extra stuff. For example, I'd love to be able to run yaourt -Sa $(yaourt -Ssa package). It doesn't seem like pacman and yaourt have an option for this (not that I can tell, at least), so I wrote a python script to do it. Copy it if you'd like. You can name it what you want, but I'll refer to it as pacdot.py.

pacdot.py package will be like yaourt -Ssa package but only list the package names.

I added a few extra options:

  • pacdot.py -o package will only list results from the official Arch repositories, not the AUR.

  • pacdot.py -i package will install all the found packages. If you've ever thought about running something like yaourt -Sa $(yaourt -Ssa package), that's what this command does.

  • pacdot.py -w package will:

    • Create a file called 'the-package-you-searched.txt',

    • Write an example command that would install the found packages,
      (yaourt -Sa all-of-the-results),

    • Write each result on a new line, and

    • Open the file for you (with your default text editor).

Here's the code:

#!/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()

Last edited by GreenRaccoon23 (2014-12-22 19:17:37)

Offline

#2 2014-12-21 05:48:37

jasonwryan
Anarchist
From: .nz
Registered: 2009-05-09
Posts: 30,426
Website

Re: How to Return List of Packages from Pacman/Yaourt Search

pacseach is a script packaged with pacman, you should change the name to avoid a collision.

This does the same thing, AFAICT:

pacsearch pulse | awk -F/ '{print $2}'

Arch + dwm   •   Mercurial repos  •   Surfraw

Registered Linux User #482438

Offline

#3 2014-12-21 08:19:45

karol
Archivist
Registered: 2009-05-06
Posts: 25,440

Re: How to Return List of Packages from Pacman/Yaourt Search

expac works only with official and unofficial repos, not with the AUR, but it's very nice.


Adding  '-q' should help, grep to weed out false positives.

yaourt -Sa $(yaourt -Ssaq pulse)

works, but

$ yaourt -Sa $(yaourt -Ssaq chrome)
resolving dependencies...
looking for inter-conflicts...
warning: removing 'chromium' from target list because it conflicts with 'chromium-no-sse2'
error: unresolvable package conflicts detected
error: failed to prepare transaction (conflicting dependencies)
:: chromium-no-sse2 and chromium-scroll-pixelGs are in conflict

so at least

$ yaourt -Sa $(yaourt -Ssaq chrome|grep google)

is needed.



Edit: Also:

$ LC_ALL=C TZ=GMT0 diff -Naur /usr/bin/pacsearch /usr/local/bin/pacsearch
--- /usr/bin/pacsearch  2014-11-21 11:20:37.000000000 +0000
+++ /usr/local/bin/pacsearch    2014-12-21 08:21:14.758856006 +0000
@@ -84,7 +84,7 @@

 my %allpkgs = ();

-my $syncout = `pacman -Ss '@ARGV'`;
+my $syncout = `pacman -Ssq '@ARGV'`;
 # split each sync search entry into its own array entry
 my @syncpkgs = split(/\n^(?=\w)/m, $syncout);
 # remove the extra \n from the last desc entry
@@ -110,7 +110,7 @@
        $allpkgs{$pkgfields[1]} = [ @pkgfields ];
 }

-my $queryout = `pacman -Qs '@ARGV'`;
+my $queryout = `pacman -Qqs '@ARGV'`;
 # split each querysearch entry into its own array entry
 my @querypkgs = split(/\n^(?=\w)/m, $queryout);
 # remove the extra \n from the last desc entry
$ /usr/local/bin/pacsearch pulse
libpulse
pulseaudio
libao
libcanberra-pulse
libpulse
paprefs
pavucontrol
pulseaudio
pulseaudio-alsa
floyd
libcec
mate-media-pulseaudio
mate-settings-daemon-pulseaudio
ponymix
projectm-pulseaudio

Although why not simply use pacman or expac?

Last edited by karol (2014-12-21 08:26:48)

Offline

#4 2014-12-22 19:05:18

GreenRaccoon23
Member
Registered: 2014-09-27
Posts: 33

Re: How to Return List of Packages from Pacman/Yaourt Search

jasonwryan wrote:

pacseach is a script packaged with pacman, you should change the name to avoid a collision.

This does the same thing, AFAICT:

pacsearch pulse | awk -F/ '{print $2}'

Well look at that! There is a pacsearch script in '/bin'!

karol wrote:

expac works only with official and unofficial repos, not with the AUR, but it's very nice.


Adding  '-q' should help, grep to weed out false positives.

yaourt -Sa $(yaourt -Ssaq pulse)

works, but

$ yaourt -Sa $(yaourt -Ssaq chrome)
resolving dependencies...
looking for inter-conflicts...
warning: removing 'chromium' from target list because it conflicts with 'chromium-no-sse2'
error: unresolvable package conflicts detected
error: failed to prepare transaction (conflicting dependencies)
:: chromium-no-sse2 and chromium-scroll-pixelGs are in conflict

so at least

$ yaourt -Sa $(yaourt -Ssaq chrome|grep google)

is needed.



Edit: Also:

$ LC_ALL=C TZ=GMT0 diff -Naur /usr/bin/pacsearch /usr/local/bin/pacsearch
...
$ /usr/local/bin/pacsearch pulse
libpulse
...

Although why not simply use pacman or expac?

I've never noticed that -q argument before. hmm I'm not sure how I missed it. That's much easier.

Last edited by GreenRaccoon23 (2014-12-22 19:06:44)

Offline

Board footer

Powered by FluxBB