update-dockapps.pl: Correctly sort alpha, beta, and release candidate versions.
[dockapps.git] / update-dockapps.pl
blob65caa1b2e85f41c7f574537e2a2bd588f5668bed
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 foreach my $tag (@tags) {
60 $tag =~ /([\w\-+.]+)-([\w.]+)/;
61 my $dockapp = $1;
62 my $version = $2;
63 my $ls = $r->run("ls-tree", $tag, $dockapp);
64 #for older tags from before directory renaming
65 if (!$ls) {
66 $ls = $r->run("ls-tree", $tag, $tag);
68 #for wmfemon_1
69 if (!$ls) {
70 $ls = $r->run("ls-tree", $tag, "$dockapp" . "_$version");
72 my $sha1 = (split(/\s/, $ls))[2];
73 $dockapps{$dockapp}{$version} = $sha1;
76 foreach my $dockapp (keys %dockapps) {
77 my $latest_version = (sort by_version keys $dockapps{$dockapp})[-1];
78 if ($r->run("diff", "$dockapp-$latest_version", "HEAD", $dockapp)) {
79 my $commit = $r->run("log", "-1",
80 "--pretty=format:%H", $dockapp);
81 my $date = strftime("%Y%m%d", localtime($r->run("log", "-1",
82 "--pretty=format:%ct", $dockapp)));
83 #throw out dockapps whose last commit was stripping version names from dirs
84 unless ($commit eq "eea379d83350ced6166099ebc8f41ff4e3fa1f42") {
85 my $ls = $r->run("ls-tree", $commit, $dockapp);
86 if (!$ls) {
87 $ls = $r->run("ls-tree", $commit,
88 "$dockapp-$latest_version");
90 my $sha1 = (split(/\s/, $ls))[2];
91 $dockapps{$dockapp}{"$latest_version+$date"} = $sha1;
97 foreach my $dockapp (keys %dockapps) {
98 my $versions = "";
99 foreach my $version (reverse sort by_version keys $dockapps{$dockapp}) {
100 $versions .= "version-$version = " .
101 $dockapps{$dockapp}{$version} . "\n";
103 my $search = quotemeta "[$dockapp]\n";
104 $db =~ s/$search/[$dockapp]\n$versions/;
107 open DB, ">dockapps.db" or die $!;
108 print DB $db;
109 close DB;
111 sub by_version {
112 (my $left = $a) =~ s/(a|b|rc)/~$1/;
113 (my $right = $b) =~ s/(a|b|rc)/~$1/;
114 Debian::Dpkg::Version->new($left) <=>
115 Debian::Dpkg::Version->new($right);