source: other-projects/nightly-tasks/snapshot/trunk/lib.pl@ 21797

Last change on this file since 21797 was 21797, checked in by oranfry, 14 years ago

imrpoved cross-platform compatibility, stopped using compression for upload, upload logs even if products dont exist and fixed log names to include OS

File size: 3.0 KB
Line 
1sub get_date {
2 local ($sec,$min,$hour,$mday,$mon,$year,$wday,$yday,$isdst) = localtime(time);
3 local $day = $mday;
4 local $month = $mon+1;
5 local $year = $year+1900;
6 if ( length $month == 1 ) {
7 $month = join( "", "0", $month);
8 }
9 if ( length $day== 1 ) {
10 $day = join( "", "0", $day );
11 }
12 local $date = join( ".", $year,$month,$day );
13 return $date;
14}
15
16sub gen_snapshot_id {
17 if ( exists $_[0] && exists $_[1] ) {
18 return $_[0] . get_date() . $_[1];
19 }
20
21 if ( exists $_[0] ) {
22 return $_[0] . get_date();
23 }
24 return get_date();
25}
26
27sub create {
28
29 die "release_dir not set, cant create\n" unless $release_dir;
30
31 print "about to clean up old snapshots (Ctrl-C to cancel)";
32 local $| = 1;
33 for ( my $i=0; $i<5; $i++ ) {
34 print ".";
35 sleep 1;
36 }
37 $| = 0;
38
39 print "cleaning up previous snapshot\n";
40 local $release_parent = dirname($release_dir);
41 if ( $^O eq "MSWin32" ) {
42 system("rd /q /s \"$release_parent\"");
43 } else {
44 system("rm -rf \"$release_parent\"");
45 }
46
47 print "creating the release dir\n";
48 mkdir $release_parent or die "couldn't create release parent directory\n";
49 mkdir $release_dir or die "couldn't create release directory\n";
50
51 print "changing to the release dir\n";
52 chdir $release_dir;
53
54 #version property
55 print "setting up todays properties\n";
56 `echo version:$snapshot_id> $rk-build.properties`;
57
58 #processor propertylocal $| = 1;
59 if ( $^O eq "darwin" ) {
60 print "setting processor\n";
61 if ( `uname -p` eq "i386" ) {
62 `echo processor:intel>> $rk-build.properties`;
63 } elsif ( `uname -p` eq "powerpc" ) {
64 `echo processor:ppc>> $rk-build.properties`;
65 } else {
66 print "unable to determine processor type, using intel\n";
67 `echo processor:intel>> $rk-build.properties`;
68 }
69 }
70
71 #branch path property
72 if ( $ENV{'branch_path'} ) {
73 `echo branch.path:$ENV{'branch_path'}>> $rk-build.properties`;
74 }
75
76 #server.exe.location
77 if ( exists $ENV{'SERVER_EXE_LOCATION'} ) {
78 `echo server.exe.location:$ENV{'SERVER_EXE_LOCATION'}>> $rk-build.properties`;
79 }
80
81 print "creating the snapshot using $rk\n";
82 system( $rk );
83
84}
85
86sub upload {
87 print "uploading files\n";
88
89 my @munges = ();
90 if ( exists $ENV{'munges'} ) {
91 @munges = split(' ', $ENV{'munges'});
92 }
93
94 #copy products to a temporary folder, giving them their new names
95 if ( ! -d "$release_dir/uploads" ) {
96 system( "rm -rf '$release_dir/uploads'" );
97 }
98 mkdir "$release_dir/uploads";
99
100 my @files;
101 if ( -d "$release_dir/products" ) {
102 @files = <$release_dir/products/*>;
103 }
104
105 push( @files, "$release_dir/$rk.out" );
106 for my $file ( @files ) {
107 my $filename = basename($file);
108 #munge
109 for my $m ( @munges ) {
110 $doit="\$filename =~ $m"; eval "$doit";
111 }
112
113 #upload
114 print "Will upload '" . basename($file) . "' to '$filename'\n";
115 system( "cp '$file' '$release_dir/uploads/$filename'" );
116 }
117 my $command = "cd $release_dir/uploads && tar -c * | ";
118 $command .= ($^O eq "MSWin32" ? "putty" : "ssh");
119 $command .= " -i '$ENV{'IDENTITY_FILE'}' nzdl\@puka.cs.waikato.ac.nz";
120 print "$command\n";
121 system("$command");
122}
Note: See TracBrowser for help on using the repository browser.