clone_packages/clone_all_packages.pl
author thomase
Tue, 25 Aug 2009 17:55:56 +0100
changeset 39 759027e1c6b3
parent 38 a1155a089aba
child 40 674034f6180c
permissions -rw-r--r--
Improved robustness of package list location searching.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
     1
#! perl
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
     2
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
     3
# Copyright (c) 2009 Symbian Foundation Ltd
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
     4
# This component and the accompanying materials are made available
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
     5
# under the terms of the License "Eclipse Public License v1.0"
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
     6
# which accompanies this distribution, and is available
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
     7
# at the URL "http://www.eclipse.org/legal/epl-v10.html".
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
     8
#
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
     9
# Initial Contributors:
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
    10
# Symbian Foundation Ltd - initial contribution.
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
    11
# 
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
    12
# Contributors:
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
    13
#
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
    14
# Description:
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
    15
# Perl script to clone or update all of the Foundation MCL repositories
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
    16
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
    17
use strict;
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    18
use Getopt::Long;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    19
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    20
sub Usage($)
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    21
  {
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    22
  my ($msg) = @_;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    23
  
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    24
  print "$msg\n\n" if ($msg ne "");
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    25
  
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    26
	print <<'EOF';
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    27
clone_all_repositories - simple script for cloning Symbian repository tree
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    28
	
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    29
This script will clone repositories, or pull changes into a previously
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    30
cloned repository. The script will prompt for your username and
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    31
password, which will be needed to access the SFL repositories, or you can
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    32
supply them with command line arguments.
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    33
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    34
Important: 
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    35
  This script uses https access to the repositories, so the username and
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    36
  password will be stored as cleartext in the .hg/hgrc file for each repository.
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    37
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    38
Used with the "-mirror" option, the script will copy both MCL and FCL
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    39
repositories into the same directory layout as the Symbian website, and will
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    40
use the Mercurial "--noupdate" option when cloning.
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    41
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    42
Options:
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    43
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    44
-username      username at the Symbian website
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    45
-password      password to go with username
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    46
-mirror        create a "mirror" of the Symbian repository tree
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    47
-retries       number of times to retry a failed operation (default 1)
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    48
-verbose       print the underlying "hg" commands before executing them
16
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    49
-n             do nothing - don't actually execute the commands
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    50
-help          print this help information
16
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    51
-exec          execute command on each repository
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    52
-filter <RE>   only process repository paths matching regular expression <RE>
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    53
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    54
The -exec option processes the rest of the command line, treating it as
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    55
a command to apply to each repository in turn. Some keywords are expanded
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    56
to repository-specific values, and "hg" is always expanded to "hg -R %REPO%"
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    57
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    58
%REPO%         relative path to the repository
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    59
%WREPO%        relative path to repository, with Windows path separators
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    60
%URL%          URL of the master repository
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    61
%PUSHURL%      URL suitable for pushing (always includes username & password)
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    62
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    63
It's often useful to use "--" to separate the exec command from the options
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    64
to this script, e.g. "-exec -- hg update -C tip"
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    65
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    66
EOF
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    67
  exit (1);  
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    68
  }
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
    69
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
    70
my @clone_options = (); # use ("--noupdate") to clone without extracting the source
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
    71
my @pull_options  = (); # use ("--rebase") to rebase your changes when pulling
8
2184cc44590a Clone from developer.symbian.org (Bug 79) and use https for SFL packages
William Roberts <williamr@symbian.org>
parents: 6
diff changeset
    72
my $hostname = "developer.symbian.org";
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    73
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    74
my $username = "";
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    75
my $password = "";
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
    76
my $mirror = 0; # set to 1 if you want to mirror the repository structure
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
    77
my $retries = 1;  # number of times to retry problem repos
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    78
my $verbose = 0;  # turn on more tracing
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    79
my $do_nothing = 0; # print the hg commands, don't actually do them
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    80
my $help = 0;
16
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    81
my $exec = 0;
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
    82
my $filter = "";
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    83
39
759027e1c6b3 Improved robustness of package list location searching.
thomase
parents: 38
diff changeset
    84
# Extract the path location of the program and locate package list files
759027e1c6b3 Improved robustness of package list location searching.
thomase
parents: 38
diff changeset
    85
my $program_path = $0;
759027e1c6b3 Improved robustness of package list location searching.
thomase
parents: 38
diff changeset
    86
$program_path =~ s#(^.*\\)[^\\]+$#$1#;
759027e1c6b3 Improved robustness of package list location searching.
thomase
parents: 38
diff changeset
    87
my $sf_pkg_list_file = $program_path."sf_mcl_packages.txt";
759027e1c6b3 Improved robustness of package list location searching.
thomase
parents: 38
diff changeset
    88
my $sftools_pkg_list_file = $program_path."sftools_mcl_packages.txt";
759027e1c6b3 Improved robustness of package list location searching.
thomase
parents: 38
diff changeset
    89
my $other_pkg_list_file = $program_path."other_packages.txt";
38
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
    90
39
759027e1c6b3 Improved robustness of package list location searching.
thomase
parents: 38
diff changeset
    91
# Analyse the rest of command-line parameters
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    92
if (!GetOptions(
13
dda0176e838b Fix mistake in -password and -username options, tweak the (doomed) sfl repository screen scraping
William Roberts <williamr@symbian.org>
parents: 12
diff changeset
    93
    "u|username=s" => \$username,
dda0176e838b Fix mistake in -password and -username options, tweak the (doomed) sfl repository screen scraping
William Roberts <williamr@symbian.org>
parents: 12
diff changeset
    94
    "p|password=s" => \$password,
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    95
    "m|mirror" => \$mirror, 
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    96
    "r|retries=i" => \$retries,
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    97
    "v|verbose" => \$verbose,
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    98
    "n" => \$do_nothing,
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
    99
    "h|help" => \$help,
16
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   100
    "e|exec" => \$exec,
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   101
    "f|filter=s" => \$filter,
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   102
    ))
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   103
  {
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   104
  Usage("Invalid argument");
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   105
  }
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   106
  
16
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   107
Usage("Too many arguments") if (scalar @ARGV > 0 && !$exec);
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   108
Usage("Too few arguments for -exec") if (scalar @ARGV == 0 && $exec);
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   109
Usage("") if ($help);
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   110
38
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   111
open  SF_PKG_LIST, "<$sf_pkg_list_file" or die "Can't open $sf_pkg_list_file\n";
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   112
open  SFTOOLS_PKG_LIST, "<$sftools_pkg_list_file" or die "Can't open $sftools_pkg_list_file\n";
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   113
open  OTHER_PKG_LIST, "<$other_pkg_list_file" or die "Can't open $other_pkg_list_file\n";
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   114
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   115
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   116
# Important: This script uses http access to the repositories, so
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   117
# the username and password will be stored as cleartext in the
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   118
# .hg/hgrc file in each repository.
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   119
16
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   120
my $needs_id = 1; # assumed necessary for clone/pull
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   121
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   122
my @exec_cmd = @ARGV;
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   123
if ($exec)
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   124
  {
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   125
  if ($exec_cmd[0] eq "hg")
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   126
    {
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   127
    shift @exec_cmd;
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   128
    unshift @exec_cmd, "hg", "-R", "%REPO%";
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   129
    }
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   130
  if ($verbose)
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   131
    {
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   132
    print "* Exec template = >", join("<,>", @exec_cmd), "<\n";
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   133
    }
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   134
  $needs_id = grep /URL%/,@exec_cmd; # only need id if using %URL% or %PUSHURL%
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   135
  }
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   136
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   137
if ($needs_id && $username eq "" )
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   138
  {
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   139
  print "Username: ";
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   140
  $username = <STDIN>;
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   141
  chomp $username;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   142
  }
16
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   143
if ($needs_id && $password eq "" )
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   144
  {
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   145
  print "Password: ";
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   146
  $password = <STDIN>;
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   147
  chomp $password;
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   148
  }
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   149
38
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   150
my @sf_packages;
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   151
foreach my $pkg (<SF_PKG_LIST>)
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   152
{
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   153
	if ($pkg =~ s#^https://[^/]+/##)
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   154
	{
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   155
		chomp($pkg);
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   156
		push @sf_packages, $pkg;
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   157
	}
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   158
}
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   159
38
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   160
my @sftools_packages;
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   161
foreach my $pkg (<SFTOOLS_PKG_LIST>)
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   162
{
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   163
	if ($pkg =~ s#^https://[^/]+/##)
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   164
	{
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   165
		chomp($pkg);
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   166
		push @sftools_packages, $pkg;
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   167
	}
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   168
}
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   169
38
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   170
my @other_repos;
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   171
foreach my $pkg (<OTHER_PKG_LIST>)
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   172
{
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   173
	if ($pkg =~ s#^https://[^/]+/##)
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   174
	{
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   175
		chomp($pkg);
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   176
		push @other_repos, $pkg;
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   177
	}
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   178
}
a1155a089aba Updated script to use external lists of repositories managed dynamically by SCM people.
thomase
parents: 37
diff changeset
   179
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   180
31
cf4bd27a8280 Add special case handling for export controlled OSS repositories (currently sf/os/security)
William Roberts <williamr@symbian.org>
parents: 30
diff changeset
   181
my %export_control_special_case = (
cf4bd27a8280 Add special case handling for export controlled OSS repositories (currently sf/os/security)
William Roberts <williamr@symbian.org>
parents: 30
diff changeset
   182
  "oss/MCL/sf/os/security" => 1,
cf4bd27a8280 Add special case handling for export controlled OSS repositories (currently sf/os/security)
William Roberts <williamr@symbian.org>
parents: 30
diff changeset
   183
  "oss/FCL/sf/os/security" => 1,
cf4bd27a8280 Add special case handling for export controlled OSS repositories (currently sf/os/security)
William Roberts <williamr@symbian.org>
parents: 30
diff changeset
   184
  );
cf4bd27a8280 Add special case handling for export controlled OSS repositories (currently sf/os/security)
William Roberts <williamr@symbian.org>
parents: 30
diff changeset
   185
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   186
sub do_system(@)
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   187
  {
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   188
  my (@cmd) = @_;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   189
  
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   190
  if ($verbose)
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   191
    {
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   192
    print "* ", join(" ", @cmd), "\n";
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   193
    }
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   194
  return 0 if ($do_nothing);
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   195
  
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   196
  return system(@cmd);
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   197
  }
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   198
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   199
sub get_repo($)
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   200
  {
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   201
  my ($package) = @_;
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   202
  my @dirs = split /\//, $package;
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   203
  my $license = shift @dirs;
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   204
  my $repotree = shift @dirs; # remove the MCL or FCL repo tree information
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   205
  my $destdir = pop @dirs;  # ignore the package name, because Mercurial will create that
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   206
  
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   207
  if ($mirror)
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   208
    {
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   209
    # Mirror the full directory structure, so put back the license & repotree dirs
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   210
    unshift @dirs, $repotree;
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   211
    unshift @dirs, $license;
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   212
    }
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   213
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   214
  # Ensure the directories already exist as far as the parent of the repository
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   215
  my $path = "";
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   216
  foreach my $dir (@dirs)
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   217
    {
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   218
    $path = ($path eq "") ? $dir : "$path/$dir";
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   219
    if (!-d $path)
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   220
      {
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   221
      mkdir $path;
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   222
      }
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   223
    }
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   224
  
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   225
  $path .= "/$destdir";   # this is where the repository will go
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   226
8
2184cc44590a Clone from developer.symbian.org (Bug 79) and use https for SFL packages
William Roberts <williamr@symbian.org>
parents: 6
diff changeset
   227
  my $repo_url = "https://$username:$password\@$hostname/$package/";
16
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   228
  my $repo_push_url =$repo_url;
31
cf4bd27a8280 Add special case handling for export controlled OSS repositories (currently sf/os/security)
William Roberts <williamr@symbian.org>
parents: 30
diff changeset
   229
  if ($license ne "sfl" && !$export_control_special_case{$package})
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   230
    {
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   231
    # user registration is not required for reading public package repositories
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   232
    $repo_url = "http://developer.symbian.org/$package/";
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   233
    }
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   234
  
16
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   235
  if ($exec)
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   236
    {
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   237
    # iteration functionality - process the keywords
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   238
    my $wpath = $path;
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   239
    $wpath =~ s/\//\\/g;  # win32 path separator
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   240
    my @repo_cmd = ();
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   241
    foreach my $origcmd (@exec_cmd)
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   242
      {
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   243
      my $cmd = $origcmd; # avoid altering the original
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   244
      $cmd =~ s/%REPO%/$path/;
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   245
      $cmd =~ s/%WREPO%/$wpath/;
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   246
      $cmd =~ s/%URL%/$repo_url/;
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   247
      $cmd =~ s/%PUSHURL%/$repo_push_url/;
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   248
      push @repo_cmd, $cmd;
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   249
      }
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   250
    print "Processing $path...\n";
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   251
    return do_system(@repo_cmd);
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   252
    }
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   253
  elsif (-d "$path/.hg")
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   254
    {
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   255
    # The repository already exists, so just do an update
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   256
    
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   257
    print "Updating $destdir from $package...\n";
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   258
    return do_system("hg", "pull", @pull_options, "-R", $path, $repo_url);
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   259
    }
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   260
  else
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   261
    {
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   262
    # Clone the repository
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   263
    
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   264
    print "Cloning $destdir from $package...\n";
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   265
    return do_system("hg", "clone", @clone_options, $repo_url, $path);
6
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   266
    }
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   267
  
c34a018f3291 Re-introduce the clone_all_packages.pl script
William Roberts <williamr@symbian.org>
parents:
diff changeset
   268
  }
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   269
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   270
my @all_packages;
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   271
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   272
@all_packages = (@sf_packages, @sftools_packages, @other_repos);
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   273
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   274
if ($mirror)
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   275
  {
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   276
  push @clone_options, "--noupdate";
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   277
  
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   278
  if (0)
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   279
    {
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   280
    # Prototype code to scrape the repository list from the website
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   281
    # Needs to have extra modules and executables installed to support https
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   282
    # so this would only work for the oss packages at present...
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   283
    
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   284
    # Create a user agent object
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   285
    use LWP::UserAgent;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   286
    use HTTP::Request::Common;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   287
    my $ua = LWP::UserAgent->new;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   288
    $ua->agent("clone_all_packages.pl ");
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   289
  
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   290
    # Request the oss package list
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   291
    my $res = $ua->request(GET "http://$hostname/oss");
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   292
  
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   293
    # Check the outcome of the response
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   294
    if (! $res->is_success) 
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   295
      {
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   296
      print "Failed to read oss package list:\n\t", $res->status_line, "\n";
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   297
      }
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   298
    
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   299
    my @oss_packages = ($res->content =~ m/<td><a href="\/(oss\/[^"]+)\/?">/g);  # umatched "
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   300
    print join ("\n\t",@oss_packages), "\n";
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   301
13
dda0176e838b Fix mistake in -password and -username options, tweak the (doomed) sfl repository screen scraping
William Roberts <williamr@symbian.org>
parents: 12
diff changeset
   302
    # Request the sfl package list
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   303
    $res = $ua->request(GET "https://$username:$password\@$hostname/sfl");
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   304
  
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   305
    # Check the outcome of the response
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   306
    if (! $res->is_success) 
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   307
      {
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   308
      print "Failed to read sfl package list:\n\t", $res->status_line, "\n";
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   309
      }
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   310
    
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   311
    my @sfl_packages = ($res->content =~ m/<td><a href="\/(sfl\/[^"]+)\/?">/g);  # umatched "
13
dda0176e838b Fix mistake in -password and -username options, tweak the (doomed) sfl repository screen scraping
William Roberts <williamr@symbian.org>
parents: 12
diff changeset
   312
    print join ("\n\t",@sfl_packages), "\n";
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   313
    
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   314
    @all_packages = (@sfl_packages, @oss_packages);
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   315
    }
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   316
  else
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   317
    {
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   318
    # Assume that every MCL has a matching FCL
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   319
    my @list_with_fcls = ();
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   320
    foreach my $package (@all_packages)
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   321
      {
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   322
      push @list_with_fcls, $package;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   323
      if ($package =~ /MCL/)
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   324
        {
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   325
        # If mirroring, get the matching FCLs as well as MCLs
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   326
        $package =~ s/MCL/FCL/;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   327
        push @list_with_fcls, $package;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   328
        }
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   329
      }
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   330
    @all_packages = @list_with_fcls;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   331
    }
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   332
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   333
  }
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   334
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   335
my @problem_packages = ();
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   336
my $total_packages = 0;
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   337
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   338
foreach my $package (@all_packages)
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   339
  {
16
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   340
  if ($filter && $package !~ /$filter/)
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   341
    {
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   342
    next; # skip repos which don't match the filter
880bb4a0a72d Add the -exec and -filter options to clone_all_repositories, giving simple "iterator" functionality
William Roberts <williamr@symbian.org>
parents: 13
diff changeset
   343
    }
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   344
  my $err = get_repo($package);
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   345
  $total_packages++;
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   346
  push @problem_packages, $package if ($err); 
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   347
  }
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   348
  
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   349
# retry problem packages
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   350
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   351
my $attempt = 0;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   352
while ($attempt < $retries && scalar @problem_packages) 
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   353
  {
12
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   354
  $attempt++;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   355
  printf "\n\n------------\nRetry attempt %d on %d packages\n",
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   356
    $attempt, scalar @problem_packages;
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   357
  print join("\n", @problem_packages, ""), "\n";
319764718a57 Add proper usage and more options (Bug 80). Add prototype screen-scraping to read repository list.
William Roberts <williamr@symbian.org>
parents: 11
diff changeset
   358
    
11
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   359
  my @list = @problem_packages;
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   360
  @problem_packages = ();
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   361
  foreach my $package (@list)
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   362
    {
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   363
    my $err = get_repo($package);
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   364
    push @problem_packages, $package if ($err); 
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   365
   }
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   366
  }
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   367
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   368
printf "\n------------\nProcessed %d packages, of which %d reported errors\n", 
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   369
  $total_packages, scalar @problem_packages;
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   370
if (scalar @problem_packages)
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   371
  {
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   372
  print join("\n", @problem_packages, "");
ccca32510405 Prompt for username and password (Bug 80), support retries and repo mirroring
William Roberts <williamr@symbian.org>
parents: 8
diff changeset
   373
  }