Skip to content

Commit d04e609

Browse files
committed
Merge branch 'master' of github.com:epitron/upm
2 parents 12895be + b5be568 commit d04e609

File tree

4 files changed

+124
-21
lines changed

4 files changed

+124
-21
lines changed

TODO.md

+8-2
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,8 @@
11
# TODO
22

33
## UI
4-
* fzf
5-
* search
4+
* fzf/pick
5+
* scrapers for web-based search engines (especially for "files in packages")
66

77
## Options
88
* Proper option/command parser
@@ -11,9 +11,15 @@
1111
## DSL
1212
* Call commands from within other commands, or specify dependencies (eg: command "install", "pkg install", depends: "update" )
1313
* DSL setting defaults (eg: cache_dir "\~/.cache/upm")
14+
* Some commands require special packages (eg: "command 'locate', depends: 'pkgfile'") which have their own syncable databases
15+
|_ offer to install these dependencies (and sync them (periodically))
16+
|_ web-based search is even nicer
17+
* Page multi-commands (eg: 'args.each { run ..., paged: true }' should all output to the same pager)
18+
|_ 'run ..., pager: IO'? will that break grep?
1419

1520
## Performance
1621
* RPi2 is very clunky
22+
|_ rewrite in... C? rust? go? lua?
1723

1824
## A language for letting programs specify and auto-install dependencies
1925
* A DSL for specifying dependencies (eg: `upm py:spotdl rb:epitools pkg:wget docker:aria2c`)

lib/upm/tool.rb

+17-13
Original file line numberDiff line numberDiff line change
@@ -22,29 +22,32 @@ class Tool
2222
"install" => "install a package",
2323
"remove/uninstall" => "remove a package",
2424
"search" => "search packages",
25+
"update/sync" => "retrieve the latest package list or manifest",
26+
"upgrade" => "update package list and install updates",
2527
"search-sources" => "search package source (for use with 'build' command)",
26-
"build" => "build a package from source and install it",
2728
"list" => "list installed packages (or search their names if extra arguments are supplied)",
28-
"selection" => "list manually installed packages", # this should probably be a `list` option ("upm list --manually-added" or smth (would be nice: rewrite in go and use ipfs' arg parsing library))
2929
"files" => "list files in a package",
30-
"info" => "show metadata about a package",
31-
"update/sync" => "retrieve the latest package list or manifest",
32-
"upgrade" => "update package list and install updates",
30+
"info/show" => "show metadata about a package",
31+
"rdeps/depends" => "reverse dependencies (which packages depend on this package?)",
32+
"locate" => "search contents of packages (local or remote)",
3333
"selfupdate" => "update the package manager",
3434
"download" => "download package list and updates, but don't insatall them",
35+
"build" => "build a package from source and install it",
36+
"selection/manual" => "list manually installed packages", # this should probably be a `list` option ("upm list --manually-added" or smth (would be nice: rewrite in go and use ipfs' arg parsing library))
3537
"pin" => "pinning a package means it won't be automatically upgraded",
3638
"rollback" => "revert to an earlier version of a package (including its dependencies)",
3739
"verify/check" => "verify the integrity of packages' files on the filesystem",
3840
"repair" => "fix corrupted packages",
39-
"audit/vuln" => "show known vulnerabilities in installed packages",
41+
"audit/vulns" => "show known vulnerabilities in installed packages",
4042
"log" => "show history of package installs",
4143
"packagers" => "detect installed package managers, and pick which ones upm should wrap",
4244
"clean" => "clear out the local package cache",
45+
"orphans" => "dependencies which are no longer needed",
4346
"monitor" => "ad-hoc package manager for custom installations (like instmon)",
4447
"keys" => "keyrings and package authentication",
4548
"default" => "configure the action to take when no arguments are passed to 'upm' (defaults to 'os:update')",
4649
"stats" => "show statistics about package database(s)",
47-
"mirrors/sources/channels" => "manage subscriptions to remote repositories/mirrors/channels",
50+
"repos/mirrors/sources/channels" => "manage subscriptions to remote repositories/mirrors/channels",
4851
}
4952

5053
ALIASES = {
@@ -56,16 +59,17 @@ class Tool
5659
"r" => "remove",
5760
"m" => "mirrors",
5861
"file" => "files",
59-
"sync" => "update",
60-
"sources" => "mirrors",
61-
"channels" => "mirrors",
62-
"show" => "info",
6362
"vuln" => "audit",
64-
"vulns" => "audit",
65-
"check" => "verify",
6663
"source-search" => "search-sources",
6764
}
6865

66+
COMMAND_HELP.keys.each do |key|
67+
cmd, *alts = key.split("/")
68+
alts.each do |alt|
69+
ALIASES[alt] = cmd
70+
end
71+
end
72+
6973
def initialize(name, &block)
7074
@name = name
7175

lib/upm/tools/pacman.rb

+36-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
UPM::Tool.new "pacman" do
2-
32
os "arch"
43

54
bin = ["pacman", "--color=always"]
@@ -17,6 +16,7 @@
1716
command "audit", "arch-audit", paged: true
1817
command "files", [*bin, "-Ql"], paged: true
1918
command "search", [*bin, "-Ss"], paged: true, highlight: true
19+
command "locate", ["pkgfile", "-r"], paged: true
2020

2121
command "info" do |args|
2222
run(*bin, "-Qi", *args, paged: true) || run(*bin, "-Si", *args, paged: true)
@@ -106,4 +106,39 @@ def to_s
106106

107107
end
108108

109+
command "rdeps" do |args|
110+
packages_that_depend_on = proc do |package|
111+
result = []
112+
113+
# [`pacman -Sii #{package}`, `pacman -Qi #{package}`].each do |output|
114+
[`pacman -Sii #{package}`].each do |output|
115+
output.each_line do |l|
116+
if l =~ /Required By\s+: (.+)/
117+
result += $1.strip.split unless $1["None"]
118+
break
119+
end
120+
end
121+
end
122+
123+
result
124+
end
125+
126+
args.each do |package|
127+
puts "<8>=== <14>#{package} <8>============".colorize
128+
puts
129+
130+
packages = packages_that_depend_on.call package
131+
132+
if packages.empty?
133+
puts " <12>None".colorize
134+
else
135+
run "pacman", "-Ss", "^(#{packages.join '|'})$" # upstream packages
136+
run "pacman", "-Qs", "^(#{packages.join '|'})$" # packages that are only installed locally
137+
end
138+
139+
puts
140+
end
141+
end
109142
end
143+
144+

lib/upm/tools/xbps.rb

+63-5
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,24 @@
44

55
identifying_binary "xbps-install"
66

7-
command "install", "xbps-install", root: true
8-
command "update", "xbps-install -S", root: true
9-
command "upgrade", "xbps-install -Su", root: true
10-
command "files", "xbps-query -f", paged: true
11-
command "selection", "xbps-query -m"
7+
command "install", "xbps-install", root: true
8+
command "remove", "xbps-remove", root: true
9+
command "update", "xbps-install -S", root: true
10+
command "upgrade", "xbps-install -Su", root: true
11+
command "files", "xbps-query -f", paged: true
12+
command "locate", "xlocate", paged: true
13+
command "selection", "xbps-query -m", paged: true
14+
command "rdeps", "xbps-query -R -X", paged: true
15+
command "orphans", "xbps-query -O", paged: true
16+
17+
command "info" do |args|
18+
args.each do |arg|
19+
unless run("xbps-query", "-S", arg)
20+
run("xbps-query", "-R", "-S", arg)
21+
end
22+
puts
23+
end
24+
end
1225

1326
command "search" do |args|
1427
query = args.join(".*")
@@ -24,4 +37,49 @@
2437
end
2538
end
2639

40+
41+
42+
class XBPSPackage < Struct.new(:name, :version, :date)
43+
def self.from_line(line)
44+
# zd1211-firmware-1.5_3: 2021-09-01 15:22 UTC
45+
if line =~ /^([\w\-]+)-([\d\.]+_\d+): (.+)$/
46+
name, version, date = $1, $2, $3
47+
date = DateTime.parse($3)
48+
new(name, version, date)
49+
else
50+
nil
51+
end
52+
end
53+
54+
def to_s
55+
"[#{date.strftime("%Y-%m-%d %H:%M:%S")}] #{name} #{version}"
56+
end
57+
end
58+
59+
command "log" do |args|
60+
fakedata = %{
61+
xset-1.2.4_1: 2021-11-05 15:03 UTC
62+
xsetroot-1.1.2_1: 2021-11-05 15:03 UTC
63+
xtools-0.63_1: 2021-11-05 16:36 UTC
64+
xtrans-1.4.0_2: 2021-11-05 15:26 UTC
65+
xvidcore-1.3.7_1: 2021-11-05 16:45 UTC
66+
xvinfo-1.1.4_2: 2021-11-05 15:03 UTC
67+
xwd-1.0.8_1: 2021-11-05 15:03 UTC
68+
xwininfo-1.1.5_1: 2021-11-05 15:03 UTC
69+
xwud-1.0.5_1: 2021-11-05 15:03 UTC
70+
xz-5.2.5_2: 2021-11-05 15:12 UTC
71+
zd1211-firmware-1.5_3: 2021-09-01 15:22 UTC
72+
zip-3.0_6: 2021-11-05 17:45 UTC
73+
zlib-1.2.11_4: 2021-09-01 14:14 UTC
74+
zlib-devel-1.2.11_4: 2021-11-05 15:26 UTC
75+
}
76+
77+
data = IO.popen(["xbps-query", "-p", "install-date", "-s", ""], &:read)
78+
packages = data.each_line.map do |line|
79+
XBPSPackage.from_line(line.strip)
80+
end.compact
81+
packages.sort_by!(&:date)
82+
packages.each { |pkg| puts pkg }
83+
end
2784
end
85+

0 commit comments

Comments
 (0)