wmsun: Bump to version 1.05.
[dockapps.git] / update-dockapps.pl
blob124cc3b44422b7429649f2081cc6ca49c5396c69
1 #!/usr/bin/perl
3 # Update http://windowmaker.org/dockapps from git
5 # Copyright 2014 Window Maker Developers Team
6 # <wmaker-dev@lists.windowmaker.org>
8 # This program is free software: you can redistribute it and/or modify
9 # it under the terms of the GNU General Public License as published by
10 # the Free Software Foundation, either version 3 of the License, or
11 # (at your option) any later version.
13 # This program is distributed in the hope that it will be useful,
14 # but WITHOUT ANY WARRANTY; without even the implied warranty of
15 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 # GNU General Public License for more details.
18 # You should have received a copy of the GNU General Public License
19 # along with this program. If not, see <http://www.gnu.org/licenses/>.
21 # DESCRIPTION
23 # After every commit to the dockapps git repository, run this script to
24 # update dockapps/dockapps.db, the plain text config file that stores all
25 # of the information for the dockapps section of windowmaker.org.
27 # The script uses git to determine the version numbers and tarball download
28 # urls. Everything else is pulled in from dockapps.db.in, which is
29 # manually updated.
31 # The format of each dockapp entry in dockapps.db.in is:
33 # [dockapp name]
34 # image = (file name of image; in double quotes and comma-separated if more
35 # than one image)
36 # description = (description, possibly taken from archive.org copy of
37 # dockapps.windowmaker.org; in double quotes)
38 # hosted = (1 if in git repo, 0 if hosted elsewhere, i.e., original maintainer
39 # is still active)
40 # url = (use archive.org copy if original homepage no longer exists)
41 # dockapps = (currently unused; id number from dockapps.windowmaker.org)
42 # category = (category from dockapps.windowmaker.org)
44 # After generating a new dockapps.db, submit a patch for the whome git repo
45 # to wmaker-dev@lists.windowmaker.org.
47 use warnings;
48 use strict;
49 use Git::Repository;
50 use POSIX;
51 use Debian::Dpkg::Version;
53 open DB, "dockapps.db.in" or die $!;
54 my $db = do { local $/; <DB> };
55 close DB;
57 my $r = Git::Repository->new();
58 my @tags = $r->run("tag");
59 my %dockapps;
61 # If any earlier versions of a dockapp had an alternate name, e.g. a name change
62 # or a fork which has since been blessed, add it to this hash as 'alt' =>
63 # 'main'. The alternate should still have its own entry in dockapps.db.in.
64 my %alts = (
65 'wmacpi-ng' => 'wmacpi'
68 foreach my $tag (@tags) {
69 $tag =~ /([\w\-+.]+)-([\w.]+)/;
70 my $dockapp = $1;
71 my $version = $2;
72 my $ls = $r->run("ls-tree", $tag, $dockapp);
73 #for older tags from before directory renaming
74 if (!$ls) {
75 $ls = $r->run("ls-tree", $tag, $tag);
77 #for wmfemon_1
78 if (!$ls) {
79 $ls = $r->run("ls-tree", $tag, "$dockapp" . "_$version");
81 #for alts
82 if (!$ls) {
83 $ls = $r->run("ls-tree", $tag, $alts{$dockapp});
85 my $sha1 = (split(/\s/, $ls))[2];
86 $dockapps{$dockapp}{$version} = $sha1;
89 foreach my $dockapp (keys %dockapps) {
90 if (grep {$_ eq $dockapp} keys %alts) {
91 next;
93 my $latest_version = (sort by_version keys %{$dockapps{$dockapp}})[-1];
94 if ($r->run("diff", "$dockapp-$latest_version", "HEAD", "--", $dockapp)) {
95 my $commit = $r->run("log", "-1",
96 "--pretty=format:%H", "--", $dockapp);
97 my $date = strftime("%Y%m%d", localtime($r->run("log", "-1",
98 "--pretty=format:%ct", "--", $dockapp)));
99 #throw out dockapps whose last commit was stripping version names from dirs
100 unless ($commit eq "eea379d83350ced6166099ebc8f41ff4e3fa1f42") {
101 my $ls = $r->run("ls-tree", $commit, $dockapp);
102 if (!$ls) {
103 $ls = $r->run("ls-tree", $commit,
104 "$dockapp-$latest_version");
106 my $sha1 = (split(/\s/, $ls))[2];
107 $dockapps{$dockapp}{"$latest_version+$date"} = $sha1;
113 foreach my $dockapp (keys %dockapps) {
114 my $versions = "";
115 foreach my $version (reverse sort by_version keys %{$dockapps{$dockapp}}) {
116 $versions .= "version-$version = " .
117 $dockapps{$dockapp}{$version} . "\n";
119 my $search = quotemeta "[$dockapp]\n";
120 $db =~ s/$search/[$dockapp]\n$versions/;
123 open DB, ">dockapps.db" or die $!;
124 print DB $db;
125 close DB;
127 sub by_version {
128 (my $left = $a) =~ s/(a|b|rc)/~$1/;
129 (my $right = $b) =~ s/(a|b|rc)/~$1/;
130 Debian::Dpkg::Version->new($left) <=>
131 Debian::Dpkg::Version->new($right);