[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[tor-commits] [tor-browser-bundle/master] Bug 16551: generate a downloads.json file



commit 3dd1fc4afa36266027a2785a443757b2c6c3d93d
Author: Nicolas Vigier <boklm@xxxxxxxxxxxxxx>
Date:   Fri Aug 21 16:40:03 2015 +0200

    Bug 16551: generate a downloads.json file
---
 gitian/check-prerequisites.sh           |    2 +-
 tools/update-responses/README.md        |    6 ++---
 tools/update-responses/update_responses |   41 +++++++++++++++++++++++++++++++
 3 files changed, 45 insertions(+), 4 deletions(-)

diff --git a/gitian/check-prerequisites.sh b/gitian/check-prerequisites.sh
index 8518ffe..32c9b7b 100755
--- a/gitian/check-prerequisites.sh
+++ b/gitian/check-prerequisites.sh
@@ -60,7 +60,7 @@ else
   exit 1
 fi
 
-update_responses_pkg="libyaml-perl libfile-slurp-perl libxml-writer-perl libio-captureoutput-perl libfile-which-perl libparallel-forkmanager-perl libxml-libxml-perl libwww-perl"
+update_responses_pkg="libyaml-perl libfile-slurp-perl libxml-writer-perl libio-captureoutput-perl libfile-which-perl libparallel-forkmanager-perl libxml-libxml-perl libwww-perl libjson-perl"
 missing_pkg=''
 for pkg in $update_responses_pkg
 do
diff --git a/tools/update-responses/README.md b/tools/update-responses/README.md
index 5fe69a2..5440b0d 100644
--- a/tools/update-responses/README.md
+++ b/tools/update-responses/README.md
@@ -14,7 +14,7 @@ Dependencies
 The following perl modules need to be installed to run the script:
   FindBin YAML File::Slurp Digest::SHA XML::Writer File::Temp
   IO::CaptureOutput File::Which Parallel::ForkManager XML::LibXML
-  LWP
+  LWP JSON
 
 On Debian / Ubuntu you can install them with:
 
@@ -23,7 +23,7 @@ On Debian / Ubuntu you can install them with:
                     libdigest-sha-perl libxml-writer-perl \
                     libio-captureoutput-perl libfile-which-perl \
                     libparallel-forkmanager-perl libxml-libxml-perl \
-                    libwww-perl
+                    libwww-perl libjson-perl
 ```
 
 On Red Hat / Fedora you can install them with:
@@ -31,7 +31,7 @@ On Red Hat / Fedora you can install them with:
 ```
   # for module in FindBin YAML File::Slurp Digest::SHA XML::Writer \
                   File::Temp IO::CaptureOutput File::Which \
-                  Parallel::ForkManager XML::LibXML LWP
+                  Parallel::ForkManager XML::LibXML LWP JSON
     do yum install "perl($module)"; done
 ```
 
diff --git a/tools/update-responses/update_responses b/tools/update-responses/update_responses
index b1b3331..72a19d7 100755
--- a/tools/update-responses/update_responses
+++ b/tools/update-responses/update_responses
@@ -19,6 +19,7 @@ use Parallel::ForkManager;
 use File::Basename;
 use XML::LibXML '1.70';
 use LWP::Simple;
+use JSON;
 
 # Set umask and locale to provide a consistent environment for MAR file
 # generation, etc.
@@ -109,6 +110,32 @@ sub get_version_files {
     $config->{versions}{$version}{files} = $files;
 }
 
+sub get_version_downloads {
+    my ($config, $version) = @_;
+    my $downloads = {};
+    my $vdir = "$releases_dir/$version";
+    opendir(my $d, $vdir) or exit_error "Error opening directory $vdir";
+    foreach my $file (readdir $d) {
+        next unless -f "$vdir/$file";
+        my ($os, $lang);
+        if ($file =~ m/^TorBrowser-$version-osx64_(.+).dmg$/) {
+            ($os, $lang) = ('osx64', $1);
+        } elsif ($file =~ m/^tor-browser-(linux32|linux64)-${version}_(.+).tar.xz$/) {
+            ($os, $lang) = ($1, $2);
+        } elsif ($file =~ m/^torbrowser-install-${version}_(.+).exe$/) {
+            ($os, $lang) = ('win32', $1);
+        } else {
+            next;
+        }
+        $downloads->{$os}{$lang} = {
+            binary => "$config->{versions}{$version}{download_url}/$file",
+            sig => "$config->{versions}{$version}{download_url}/$file.asc",
+        };
+    }
+    closedir $d;
+    $config->{versions}{$version}{downloads} = $downloads;
+}
+
 sub extract_mar {
     my ($mar_file, $dest_dir) = @_;
     my $old_cwd = getcwd;
@@ -301,6 +328,19 @@ sub write_htaccess {
     }
 }
 
+sub write_downloads_json {
+    my ($config, @channels) = @_;
+    @channels = keys %{$config->{channels}} unless @channels;
+    foreach my $channel (@channels) {
+        my $version = $config->{channels}{$channel};
+        my $data = {
+            version => $version,
+            downloads => get_version_downloads($config, $version),
+        };
+        write_htdocs($channel, 'downloads.json', encode_json($data));
+    }
+}
+
 sub check_deps {
     foreach my $bin (qw(bunzip2 mar mbsdiff make_incremental_update.sh)) {
         exit_error "Cannot find $bin in PATH" unless which($bin);
@@ -501,6 +541,7 @@ my %actions = (
         }
         write_responses($config, @channels);
         write_htaccess($config, @channels);
+        write_downloads_json($config, @channels);
         clean_htdocs(@channels);
     },
     gen_incrementals => sub {

_______________________________________________
tor-commits mailing list
tor-commits@xxxxxxxxxxxxxxxxxxxx
https://lists.torproject.org/cgi-bin/mailman/listinfo/tor-commits