wmcdplay: Centralize version number.
[dockapps.git] / update-dockapps.pl
blob015e1666ddbf25330b947844e457a0cf40d60495
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 # url = (use archive.org copy if original homepage no longer exists)
39 # dockapps = (currently unused; id number from dockapps.windowmaker.org)
40 # category = (category from dockapps.windowmaker.org)
42 # After generating a new dockapps.db, submit a patch for the whome git repo
43 # to wmaker-dev@lists.windowmaker.org.
45 use warnings;
46 use strict;
47 use Git::Repository;
48 use POSIX;
49 use Debian::Dpkg::Version;
51 open DB, "dockapps.db.in" or die $!;
52 my $db = do { local $/; <DB> };
53 close DB;
55 my $r = Git::Repository->new();
56 my @tags = $r->run("tag");
57 my %dockapps;
59 # If any earlier versions of a dockapp had an alternate name, e.g. a name change
60 # or a fork which has since been blessed, add it to this hash as 'alt' =>
61 # 'main'. The alternate should still have its own entry in dockapps.db.in.
62 my %alts = (
63 'wmacpi-ng' => 'wmacpi'
66 foreach my $tag (@tags) {
67 $tag =~ /([\w\-+.]+)-([\w.]+)/;
68 my $dockapp = $1;
69 my $version = $2;
70 my $ls = $r->run("ls-tree", $tag, $dockapp);
71 #for older tags from before directory renaming
72 if (!$ls) {
73 $ls = $r->run("ls-tree", $tag, $tag);
75 #for wmfemon_1
76 if (!$ls) {
77 $ls = $r->run("ls-tree", $tag, "$dockapp" . "_$version");
79 #for alts
80 if (!$ls) {
81 $ls = $r->run("ls-tree", $tag, $alts{$dockapp});
83 my $sha1 = (split(/\s/, $ls))[2];
84 $dockapps{$dockapp}{$version} = $sha1;
87 foreach my $dockapp (keys %dockapps) {
88 if (grep {$_ eq $dockapp} keys %alts) {
89 next;
91 my $latest_version = (sort by_version keys %{$dockapps{$dockapp}})[-1];
92 if ($r->run("diff", "$dockapp-$latest_version", "HEAD", "--", $dockapp)) {
93 my $commit = $r->run("log", "-1",
94 "--pretty=format:%H", "--", $dockapp);
95 my $date = strftime("%Y%m%d", localtime($r->run("log", "-1",
96 "--pretty=format:%ct", "--", $dockapp)));
97 #throw out dockapps whose last commit was stripping version names from dirs
98 unless ($commit eq "eea379d83350ced6166099ebc8f41ff4e3fa1f42") {
99 my $ls = $r->run("ls-tree", $commit, $dockapp);
100 if (!$ls) {
101 $ls = $r->run("ls-tree", $commit,
102 "$dockapp-$latest_version");
104 my $sha1 = (split(/\s/, $ls))[2];
105 $dockapps{$dockapp}{"$latest_version+$date"} = $sha1;
111 foreach my $dockapp (keys %dockapps) {
112 my $versions = "";
113 foreach my $version (reverse sort by_version keys %{$dockapps{$dockapp}}) {
114 $versions .= "version-$version = " .
115 $dockapps{$dockapp}{$version} . "\n";
117 my $search = quotemeta "[$dockapp]\n";
118 $db =~ s/$search/[$dockapp]\n$versions/;
121 open DB, ">dockapps.db" or die $!;
122 print DB $db;
123 close DB;
125 sub by_version {
126 (my $left = $a) =~ s/(a|b|rc)/~$1/;
127 (my $right = $b) =~ s/(a|b|rc)/~$1/;
128 Debian::Dpkg::Version->new($left) <=>
129 Debian::Dpkg::Version->new($right);