mvhub-dev team mailing list archive
-
mvhub-dev team
-
Mailing list archive
-
Message #00225
[Branch ~mvhub-commit/mvhub/trunk] Rev 391: merged update_mv_developer_home_dir
Merge authors:
Lee Goodrich (leegoodrich)
Related merge proposals:
https://code.launchpad.net/~leegoodrich/mvhub/update_mv_developer_home_dir/+merge/26343
proposed by: Dan MacNeil (omacneil)
review: Approve - Dan MacNeil (omacneil)
------------------------------------------------------------
revno: 391 [merge]
committer: Dan MacNeil <dan@xxxxxxxxxx>
branch nick: trunk
timestamp: Fri 2010-05-28 19:55:57 -0400
message:
merged update_mv_developer_home_dir
added:
lib-mvhub/t/Utils/Setup/
lib-mvhub/t/Utils/Setup/get_dev_home_dirs.t
lib-mvhub/t/Utils/Setup/get_dev_home_files.t
lib-mvhub/t/Utils/Setup/make_dev_home_files.t
modified:
app-mvhub/project-tools/bin/mv_update_development
app-mvhub/project-tools/bin/mv_update_production
app-mvhub/project-tools/bin/mv_update_staging
lib-mvhub/lib/MVHub/Utils/Setup.pm
--
lp:mvhub
https://code.launchpad.net/~mvhub-commit/mvhub/trunk
Your team MVHub Developers is subscribed to branch lp:mvhub.
To unsubscribe from this branch go to https://code.launchpad.net/~mvhub-commit/mvhub/trunk/+edit-subscription
=== modified file 'app-mvhub/project-tools/bin/mv_update_development'
--- app-mvhub/project-tools/bin/mv_update_development 2010-05-20 18:03:55 +0000
+++ app-mvhub/project-tools/bin/mv_update_development 2010-05-28 18:56:18 +0000
@@ -20,19 +20,20 @@
use MVHub::Utils::Setup;
my @ALLOWED_HOSTS = qw/ brave cricket /;
-my @WEBSITE_CODES = @MVHub::Utils::Setup::SITE_CODES;
+my @WEBSITE_CODES = @MVHub::Utils::Setup::SITE_CODES;
{ # main
- my $interactive = 0;
- my $usage = 0;
- my $hostname = `hostname`;
+ my $interactive = 0;
+ my $usage = 0;
+ my $hostname = `hostname`;
chomp $hostname;
-
- Getopt::Long::GetOptions( 'prompt' => \$interactive,
- 'help|?' => \$usage )
- or die "GetOptions failed";
-
- if ( $usage ) {
+
+ Getopt::Long::GetOptions(
+ 'prompt' => \$interactive,
+ 'help|?' => \$usage
+ ) or die "GetOptions failed";
+
+ if ($usage) {
print usage();
exit 0;
}
@@ -47,43 +48,68 @@
system('clear');
- my $base_dir = $cfg->param('BASE.dir');
- my @dirs = MVHub::Utils::Setup::get_dirs_with( "$base_dir", $USERNAME );
-
my $prompt = "Create $USERNAME directory structure? (Y/N):";
if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::make_dirs_from( $USERNAME, \@dirs );
- }
-
- $prompt = "Update config files for $USERNAME? (Y/N):";
- if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::make_config_files_for( $USERNAME, $cfg, @WEBSITE_CODES );
- $cfg = MVHub::Utils::ConfigSimple::create_config_from( $ENV{MV_CONFIG_FILE} );
-
- }
-
- $prompt = "DESTROY and reload databases for $USERNAME (Y/N):";
- if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::make_database_user( $USERNAME, $cfg);
- MVHub::Utils::Setup::make_databases_for( $USERNAME, $cfg, @WEBSITE_CODES );
- MVHub::Utils::Setup::load_test_data_for( $USERNAME, $cfg, @WEBSITE_CODES );
- }
-
- $prompt = "Apply database updates for $USERNAME? (Y/N):";
- if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::apply_database_updates_for( $USERNAME, $cfg, @WEBSITE_CODES );
- }
-
+ print "Creating $USERNAME directory structure...";
+ my $base_dir = $cfg->param('BASE.dir');
+ my @dirs = MVHub::Utils::Setup::get_dirs_with( "$base_dir", $USERNAME );
+ MVHub::Utils::Setup::make_dirs_from( \@dirs );
+ }
+ $prompt = "Create config files in /home/$USERNAME? (Y/N):";
+ if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
+ print "Creating config files in /home/$USERNAME...\n";
+ prompt(
+ "Enter developer email address: ",
+ -default=>"$USERNAME\@thecsl.org" );
+ my $dev_email = $_;
+ prompt( "Enter developer Launchpad username: ",
+ -default=>$USERNAME );
+ my $launchpad_login = $_;
+
+ my @dev_home_dirs = MVHub::Utils::Setup::get_dev_home_dirs($USERNAME);
+ MVHub::Utils::Setup::make_dirs_from( \@dev_home_dirs );
+ my @dev_home_files =
+ MVHub::Utils::Setup::get_dev_home_files( $USERNAME, $dev_email,
+ $launchpad_login );
+ MVHub::Utils::Setup::make_dev_home_files(@dev_home_files);
+ }
+
+ $prompt = "Update config files for $USERNAME? (Y/N):";
+ if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
+ MVHub::Utils::Setup::make_config_files_for( $USERNAME, $cfg,
+ @WEBSITE_CODES );
+ $cfg = MVHub::Utils::ConfigSimple::create_config_from(
+ $ENV{MV_CONFIG_FILE} );
+
+ }
+
+ $prompt = "DESTROY and reload databases for $USERNAME (Y/N):";
+ if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
+ MVHub::Utils::Setup::make_database_user( $USERNAME, $cfg );
+ MVHub::Utils::Setup::make_databases_for( $USERNAME, $cfg,
+ @WEBSITE_CODES );
+ MVHub::Utils::Setup::load_test_data_for( $USERNAME, $cfg,
+ @WEBSITE_CODES );
+ }
+
+ $prompt = "Apply database updates for $USERNAME? (Y/N):";
+ if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
+ MVHub::Utils::Setup::apply_database_updates_for( $USERNAME, $cfg,
+ @WEBSITE_CODES );
+ }
+
if ( defined $ENV{SUDO_USER} ) {
foreach my $prefix (@WEBSITE_CODES) {
- $prompt = "Add $prefix entries for $USERNAME into DNS and Apache? (Y/N):";
- if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::add_dns( $USERNAME, $prefix );
- MVHub::Utils::Setup::add_apache_config( $USERNAME, $prefix );
- }
+ $prompt =
+ "Add $prefix entries for $USERNAME into DNS and Apache? (Y/N):";
+ if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
+ MVHub::Utils::Setup::add_dns( $USERNAME, $prefix );
+ MVHub::Utils::Setup::add_apache_config( $USERNAME, $prefix );
+ }
}
}
}
+
sub die_if_bad_env_for {
my $username = shift or croak 'missing parameter $username\n';
my $msg = '';
=== modified file 'app-mvhub/project-tools/bin/mv_update_production'
--- app-mvhub/project-tools/bin/mv_update_production 2010-05-21 19:52:52 +0000
+++ app-mvhub/project-tools/bin/mv_update_production 2010-05-28 18:56:18 +0000
@@ -60,7 +60,7 @@
my $prompt = "Create $USERNAME directory structure? (Y/N):";
if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::make_dirs_from( $USERNAME, \@dirs );
+ MVHub::Utils::Setup::make_dirs_from( \@dirs );
}
$prompt = "Update config files for $USERNAME? (Y/N):";
=== modified file 'app-mvhub/project-tools/bin/mv_update_staging'
--- app-mvhub/project-tools/bin/mv_update_staging 2010-05-21 19:52:52 +0000
+++ app-mvhub/project-tools/bin/mv_update_staging 2010-05-28 18:56:18 +0000
@@ -60,7 +60,7 @@
my $prompt = "Recreate $USERNAME directory structure? (Y/N):";
if ( !($interactive) || IO::Prompt::prompt( $prompt, -YN ) ) {
- MVHub::Utils::Setup::make_dirs_from( $USERNAME, \@dirs );
+ MVHub::Utils::Setup::make_dirs_from( \@dirs );
}
$prompt = "Update config files? (Y/N):";
=== modified file 'lib-mvhub/lib/MVHub/Utils/Setup.pm'
--- lib-mvhub/lib/MVHub/Utils/Setup.pm 2010-05-28 21:15:51 +0000
+++ lib-mvhub/lib/MVHub/Utils/Setup.pm 2010-05-28 21:22:22 +0000
@@ -17,11 +17,14 @@
@SITE_CODES
add_apache_config
add_dns
+ get_dev_home_dirs
+ get_dev_home_files
get_production_data
get_testing_data
make_config_files_for
make_database_user
make_databases_for
+ make_dev_home_files
make_dirs_from
load_production_data
load_test_data_for
@@ -584,6 +587,82 @@
}
}
+sub get_dev_home_dirs {
+ my $username = shift or croak 'missing param: $username';
+ my @dirs = (
+ { dir => "/home/$username/.bazaar",
+ owner => "$username",
+ group => "$username",
+ permissions => 'u=rwx,g=rwx,o=rx',
+ },
+ { dir => "/home/$username/.ssh",
+ owner => "$username",
+ group => "$username",
+ permissions => 'u=rwx,g=,o=',
+ }
+ );
+ return @dirs;
+}
+
+sub get_dev_home_files {
+ my $username = shift or croak 'missing param: $username';
+ my $email_address = shift or croak 'missing param: $email_address';
+ my $launchpad_login = shift or croak 'missing param: $launchpad_login';
+
+ my $result = ( getpwnam("$username") )[6];
+ croak "$username not a valid username\n" if !( defined $result );
+ my $name = ( split ",", $result )[0];
+
+ my @files = (
+ { dest => "/home/$username/.bazaar/bazaar.conf",
+ owner => "$username",
+ group => "$username",
+ permissions => 'u=rw,g=rw,o=r',
+ contents => <<"CONTENT",
+[DEFAULT]
+email = $name <$email_address>
+launchpad_username = $launchpad_login
+mail_client = mutt
+
+[ALIASES]
+recentlog = log -r-20..-1 --short --forward
+ll = log -r-10..-1 --line --forward
+CONTENT
+ },
+ { dest => "/home/$username/.bazaar/locations.conf",
+ owner => "$username",
+ group => "$username",
+ permissions => 'u=rw,g=rw,o=r',
+ contents => <<"CONTENT",
+[/var/www/mvhub/$username/source-code]
+push_location = lp:~$launchpad_login/mvhub/
+push_location:policy = appendpath
+public_branch = lp:~$launchpad_login/mvhub/
+public_branch:policy = appendpath
+submit_to = merge\@code.launchpad.net
+submit_branch = lp:mvhub
+
+[/var/www/mvhub/$username/source-code/trunk]
+push_location = lp:mvhub/trunk
+public_branch = lp:mvhub/trunk
+CONTENT
+ },
+ { dest => "/home/$username/.ssh/config",
+ owner => "$username",
+ group => "$username",
+ permissions => 'u=rwx,g=,o=',
+ contents => <<'CONTENT',
+Host bazaar.launchpad.net
+IdentityFile ~/.ssh/id_rsa_launchpad
+
+Host *
+IdentityFile ~/.ssh/id_rsa
+CONTENT
+ }
+ );
+ return @files;
+}
+
sub make_database_user {
my $username = shift or croak 'missing parameter: $username';
my $cfg = shift or croak 'missing parameter: $cfg';
@@ -642,12 +721,28 @@
print "done\n";
}
+sub make_dev_home_files {
+ my @files = @_;
+ croak 'missing param: @files' if !( scalar @files );
+ foreach my $file_href (@files) {
+ if ( -e $file_href->{dest} ) {
+ $file_href->{dest} = "$file_href->{dest}.default";
+ }
+ open FILE, ">$file_href->{dest}" or croak "open FILE failed: $!";
+ print FILE $file_href->{contents};
+ close FILE or croak "close FILE failed: $!";
+ my $chown_cmd
+ = "chown $file_href->{owner}:$file_href->{group} $file_href->{dest}";
+ my $chmod_cmd = "chmod $file_href->{permissions} $file_href->{dest}";
+ _do_or_die($chown_cmd);
+ _do_or_die($chmod_cmd);
+ }
+}
+
sub make_dirs_from {
- my $username = shift or croak 'missing param: $username';
- my $dir_hrefs_href = shift or croak 'missing param: $dir_hrefs_href';
- my @dir_hrefs = @$dir_hrefs_href;
+ my $dir_aref_hrefs = shift or croak 'missing param: $dir_hrefs_href';
+ my @dir_hrefs = @$dir_aref_hrefs;
- print "Updating $username directory structure...";
foreach my $dir_href (@dir_hrefs) {
my $mkdir_cmd = "mkdir -p $dir_href->{dir}";
my $chown_cmd
=== added directory 'lib-mvhub/t/Utils/Setup'
=== added file 'lib-mvhub/t/Utils/Setup/get_dev_home_dirs.t'
--- lib-mvhub/t/Utils/Setup/get_dev_home_dirs.t 1970-01-01 00:00:00 +0000
+++ lib-mvhub/t/Utils/Setup/get_dev_home_dirs.t 2010-05-28 19:05:24 +0000
@@ -0,0 +1,22 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 2 + 1; # + 1 for no warnings
+use Test::NoWarnings;
+use Test::Exception;
+
+use MVHub::Utils::Setup;
+
+my $test_message;
+###
+$test_message = 'dies with no username';
+###
+dies_ok { MVHub::Utils::Setup::get_dev_home_dirs() } $test_message;
+
+###
+$test_message = 'lives ok';
+###
+my $username = 'test';
+lives_ok { MVHub::Utils::Setup::get_dev_home_dirs($username) } $test_message;
=== added file 'lib-mvhub/t/Utils/Setup/get_dev_home_files.t'
--- lib-mvhub/t/Utils/Setup/get_dev_home_files.t 1970-01-01 00:00:00 +0000
+++ lib-mvhub/t/Utils/Setup/get_dev_home_files.t 2010-05-28 19:05:24 +0000
@@ -0,0 +1,48 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use Test::More tests => 5 + 1; # + 1 for NoWarnings
+use Test::NoWarnings;
+use Test::Exception;
+
+use MVHub::Utils::Setup;
+
+my $test_message;
+###
+$test_message = 'dies with no username';
+###
+dies_ok { MVHub::Utils::Setup::get_dev_home_files() } $test_message;
+
+###
+$test_message = 'dies with no email_address';
+###
+dies_ok { MVHub::Utils::Setup::get_dev_home_files('test') } $test_message;
+
+###
+$test_message = 'dies with no launchpad_login';
+###
+dies_ok {
+ MVHub::Utils::Setup::get_dev_home_files( 'test', 'test@xxxxxxxxxxxxxx' );
+}
+$test_message;
+
+###
+$test_message = 'dies with invalid username';
+###
+dies_ok {
+ MVHub::Utils::Setup::get_dev_home_files( 'test', 'test@xxxxxxxxxxxxxx',
+ 'test_lp' );
+}
+$test_message;
+
+###
+$test_message = 'lives with valid username';
+###
+lives_ok {
+ MVHub::Utils::Setup::get_dev_home_files( 'omacneil',
+ 'test@xxxxxxxxxxxxxx', 'test_lp' );
+}
+$test_message;
+
=== added file 'lib-mvhub/t/Utils/Setup/make_dev_home_files.t'
--- lib-mvhub/t/Utils/Setup/make_dev_home_files.t 1970-01-01 00:00:00 +0000
+++ lib-mvhub/t/Utils/Setup/make_dev_home_files.t 2010-05-28 19:05:24 +0000
@@ -0,0 +1,67 @@
+#!/usr/bin/perl
+
+use strict;
+use warnings;
+
+use English '-no_match_vars';
+
+use Test::More tests => 6 + 1; # + 1 for NoWarnings
+use Test::NoWarnings;
+use Test::Exception;
+
+use MVHub::Utils::Setup;
+
+my $test_message;
+###
+$test_message = 'dies when not passed in array';
+###
+dies_ok { MVHub::Utils::Setup::make_dev_home_files() } $test_message;
+
+###
+$test_message = 'dies when passed invalid array';
+###
+my @test_data = ();
+dies_ok { MVHub::Utils::Setup::make_dev_home_files(@test_data) }
+$test_message;
+
+###
+$test_message = 'dies when passed array with invalid file path';
+###
+@test_data = ( { dest => '/this/is/a/bad/path' } );
+dies_ok { MVHub::Utils::Setup::make_dev_home_files(@test_data) }
+$test_message;
+
+###
+$test_message = 'lives when passed valid array';
+###
+my $group_id = ( split ' ', $GID )[0];
+@test_data = (
+ { dest => "/tmp/make_dev_home_files_t_$PID.txt",
+ owner => $UID,
+ group => $group_id,
+ permissions => 'u=rwx,g=rwx,o=rx',
+ contents => <<"CONTENT",
+This is a test file created by make_dev_home_files.t. You can delete it.
+CONTENT
+ },
+);
+lives_ok { MVHub::Utils::Setup::make_dev_home_files(@test_data) }
+$test_message;
+
+###
+$test_message = 'test file created correctly';
+###
+open FILE, "<$test_data[0]->{dest}";
+my $line = <FILE>;
+close FILE;
+is( $line, $test_data[0]->{contents}, $test_message );
+
+###
+$test_message = 'Backup created when file already exists';
+###
+my $original_file = $test_data[0]->{dest};
+MVHub::Utils::Setup::make_dev_home_files(@test_data);
+ok( ( -e "$test_data[0]->{dest}" ), $test_message );
+
+unlink $original_file;
+unlink $test_data[0]->{dest};