-
Notifications
You must be signed in to change notification settings - Fork 0
/
lint.pl
executable file
·183 lines (151 loc) · 4.45 KB
/
lint.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
#!/usr/bin/env perl
# Various checks for urls.opml file.
use strict;
use warnings;
use diagnostics;
use autodie;
use File::Basename;
use Term::ANSIColor qw(:constants);
use Getopt::Long qw(:config gnu_compat no_ignore_case bundling);
my $PROGRAM = basename $0;
my $VERSION = '0.1';
######################################################################
my @obsolete_packages = qw(
autoconf-2.13
fuse2
gnome-icon-theme
gtk-engine-bluecurve
gtk-engine-clearlooks
gtk-engine-crux
gtk-engine-hc
gtk-engine-redmond95
gtk-engines
hcxtools3
ktsuss
librsvg-compat
libxcrypt2.4
mdk3
moc-eqsets
newsboat213
notification-daemon
pango-compat
pm-utils
py-cairo
py-gobject-compat
python
shared-mime-info
smtp-user-enum
tnscmd10g
xorg-libxfont
xorg-xf86-input-keyboard
);
my @internal_packages = qw(
xorg
filesystem
);
######################################################################
my %feed;
my %internal = map { $_ => 1 } @internal_packages;
my %obsolete = map { $_ => 1 } @obsolete_packages;
my %repo = map { chomp; $_ => 1 } qx(pkgman printf "%n\n");
######################################################################
sub load_feeds {
open my $fh, 'urls.opml';
while (<$fh>) {
next unless m{
\s*
<outline\s+
text="(?<title>.*?)\s+@.*?"\s+
xmlUrl=".*"\s+
category="(?:core|system|xorg|desktop|stuff|games)"/>
}xsm;
for my $pkg (split /\//, $+{title}) {
$feed{ $pkg }++;
}
}
close $fh;
}
sub print_missing {
print <<EOF;
The following repo packages have no RSS/Atom feeds:
===================================================
EOF
for (sort keys %repo) {
next if exists $feed{ $_ };
my $pkgsrcpath = qx(pkgman path $_);
chomp $pkgsrcpath;
if ($obsolete{ $_ }) {
print "[x] \e[9m$pkgsrcpath\e[0m \e[3m(obsolete)\e[0m\n";
} elsif ($internal{ $_ }) {
print "[v] \e[9m$pkgsrcpath\e[0m \e[3m(internal)\e[0m\n";
} else {
print "[ ] $pkgsrcpath\n";
}
}
}
sub print_redundant {
print <<EOF;
The following RSS/Atom feeds in urls.opml are redundant:
========================================================
EOF
for (sort keys %feed) {
print "$_\n" unless exists $repo{ $_ };
}
}
sub print_typos {
print <<EOF;
The following typos was found in urls.opml:
===========================================
EOF
open my $fh, '<', 'urls.opml';
my $lineno = 0;
for (<$fh>) {
$lineno++;
next unless /^\s*<outline/;
next if /^\s*<outline text="\(New headlines\)" xmlUrl="smartfeed:\/newitems"\/>$/;
print "malformed line at $lineno: $_\n"
unless m/^\s*<outline text=".*?" xmlUrl=".*?" category="(?:core|system|xorg|desktop|stuff|games|dev)"\/>$/;
print "wrong github fetching (use curl) at $lineno: $_\n"
if m/xmlUrl="https:\/\/github.com\/.*.atom"/;
print "malformed curl request qt $lineno: $_\n"
if m/xmlUrl="exec:\s*curl/ && !m/xmlUrl="exec:curl -H 'Accept: application\/atom\+xml' https?:\/\/.*?"/;
}
close $fh;
}
# ====================================================================
sub print_version {
print "$PROGRAM $VERSION\n";
}
sub print_help {
print <<EOF;
Usage: $PROGRAM [OPTION...]
Lint RSS/Atom feeds.
-m, --missing check for packages that have no feeds in urls.opml
-r, --redundant check for redundant feeds in urls.opml
-t, --typos check urls.opml for typos
-v, --version print version and exit
-h, --help print help and exit
EOF
}
# ====================================================================
sub main {
GetOptions(
"m|missing" => \my $opt_missing,
"r|redundant" => \my $opt_redundant,
"t|typos" => \my $opt_typos,
"v|version" => \my $opt_version,
"h|help" => \my $opt_help,
) or die "Try '$PROGRAM --help' for more information.\n";
print_version() and exit if $opt_version;
print_help() and exit if $opt_help;
print_help() and exit
unless $opt_missing or $opt_redundant or $opt_typos;
print_typos() if $opt_typos;
load_feeds();
print_missing() if $opt_missing;
print_redundant() if $opt_redundant;
}
main() if not caller();
1;
# vim: sw=4 ts=4 sts=4 et cc=72 tw=70
# End of file.