line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::OpenSVN; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
152744
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
39
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
30
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
4151
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
127323
|
|
|
1
|
|
|
|
|
31
|
|
7
|
1
|
|
|
1
|
|
924
|
use LWP::Simple; |
|
1
|
|
|
|
|
50340
|
|
|
1
|
|
|
|
|
8
|
|
8
|
1
|
|
|
1
|
|
1429
|
use HTTP::Cookies; |
|
1
|
|
|
|
|
9604
|
|
|
1
|
|
|
|
|
43
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
WWW::OpenSVN - An automated interface for OpenSVN.csie.org. |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
1
|
|
|
1
|
|
8
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
167
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
$VERSION = '0.1.4'; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
my $opensvn = |
23
|
|
|
|
|
|
|
WWW::OpenSVN->new( |
24
|
|
|
|
|
|
|
'project' => "myproject", |
25
|
|
|
|
|
|
|
'password' => "MySecretPassphrase", |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
$opensvn->fetch_dump('filename' => "/backup-dir/myproject-dump.gz"); |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=head1 FUNCTIONS |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=cut |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
package WWW::OpenSVN::Base; |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=head2 WWW::OpenSVN->new() |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
A constructor. Accepts these mandatory named arguments: |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
'project' - The OpenSVN Project ID. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
'password' - The OpenSVN Project Management Password. |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=cut |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub new |
47
|
|
|
|
|
|
|
{ |
48
|
0
|
|
|
0
|
|
|
my $class = shift; |
49
|
0
|
|
|
|
|
|
my $self = {}; |
50
|
0
|
|
|
|
|
|
bless $self, $class; |
51
|
0
|
|
|
|
|
|
$self->_init(@_); |
52
|
0
|
|
|
|
|
|
return $self; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub project |
56
|
|
|
|
|
|
|
{ |
57
|
0
|
|
|
0
|
|
|
my $self = shift; |
58
|
0
|
|
|
|
|
|
return $self->{'project'}; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
package WWW::OpenSVN::Error; |
62
|
|
|
|
|
|
|
|
63
|
1
|
|
|
1
|
|
7
|
use vars qw(@ISA); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
141
|
|
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
@ISA=(qw(WWW::OpenSVN::Base)); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _init |
68
|
|
|
|
|
|
|
{ |
69
|
0
|
|
|
0
|
|
|
my $self = shift; |
70
|
0
|
|
|
|
|
|
my (%args) = (@_); |
71
|
0
|
|
|
|
|
|
$self->{'project'} = $args{'project'}; |
72
|
0
|
|
|
|
|
|
$self->{'phase'} = $args{'phase'}; |
73
|
|
|
|
|
|
|
|
74
|
0
|
|
|
|
|
|
return 0; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
sub phase |
78
|
|
|
|
|
|
|
{ |
79
|
0
|
|
|
0
|
|
|
my $self = shift; |
80
|
0
|
|
|
|
|
|
return $self->{'phase'}; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
package WWW::OpenSVN; |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
1
|
|
7
|
use vars qw(@ISA); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
751
|
|
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
@ISA=(qw(WWW::OpenSVN::Base)); |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub _init |
90
|
|
|
|
|
|
|
{ |
91
|
0
|
|
|
0
|
|
|
my $self = shift; |
92
|
0
|
|
|
|
|
|
my (%args) = (@_); |
93
|
0
|
0
|
|
|
|
|
$self->{'project'} = $args{'project'} |
94
|
|
|
|
|
|
|
or die "Project ID not specified!"; |
95
|
0
|
0
|
|
|
|
|
$self->{'_password'} = $args{'password'} |
96
|
|
|
|
|
|
|
or die "Project Password not speicified!"; |
97
|
0
|
|
|
|
|
|
return 0; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _password |
102
|
|
|
|
|
|
|
{ |
103
|
0
|
|
|
0
|
|
|
my $self = shift; |
104
|
0
|
|
|
|
|
|
return $self->{'_password'}; |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub _gen_error |
108
|
|
|
|
|
|
|
{ |
109
|
0
|
|
|
0
|
|
|
my $self = shift; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my (%args) = (@_); |
112
|
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
die |
114
|
|
|
|
|
|
|
WWW::OpenSVN::Error->new( |
115
|
|
|
|
|
|
|
'project' => $self->project(), |
116
|
|
|
|
|
|
|
'phase' => $args{'phase'} |
117
|
|
|
|
|
|
|
); |
118
|
|
|
|
|
|
|
} |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
sub _get_repos_revision |
121
|
|
|
|
|
|
|
{ |
122
|
0
|
|
|
0
|
|
|
my $self = shift; |
123
|
0
|
0
|
|
|
|
|
if (exists($self->{'repos_revision'})) |
124
|
|
|
|
|
|
|
{ |
125
|
0
|
|
|
|
|
|
return $self->{'repos_revision'}; |
126
|
|
|
|
|
|
|
} |
127
|
0
|
|
|
|
|
|
my $project = $self->project(); |
128
|
0
|
|
|
|
|
|
my $url = "http://opensvn.csie.org/$project/"; |
129
|
0
|
|
|
|
|
|
my $page = get($url); |
130
|
0
|
0
|
|
|
|
|
if ($page =~ /Revision (\d+): \/<\/title>/) |
131
|
|
|
|
|
|
|
{ |
132
|
0
|
|
|
|
|
|
return ($self->{'repos_revision'} = $1); |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
else |
135
|
|
|
|
|
|
|
{ |
136
|
0
|
|
|
|
|
|
$self->_gen_error( |
137
|
|
|
|
|
|
|
'phase' => 'get_repos_rev', |
138
|
|
|
|
|
|
|
); |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head2 $opensvn->fetch_dump('filename' => "myfile.dump.gz") |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
Fetches a subversion repository dump and stores it in a file. Accepts an |
145
|
|
|
|
|
|
|
optional argument - 'filename' that is used to specify the filename to store |
146
|
|
|
|
|
|
|
the dump into. If not specified, it defaults to "$project.dump.gz" |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=cut |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
sub fetch_dump |
151
|
|
|
|
|
|
|
{ |
152
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
153
|
0
|
|
|
|
|
|
my (%args) = (@_); |
154
|
|
|
|
|
|
|
|
155
|
0
|
|
|
|
|
|
my $url = "https://opensvn.csie.org/"; |
156
|
|
|
|
|
|
|
|
157
|
0
|
|
|
|
|
|
my $repos_top_version = $self->_get_repos_revision(); |
158
|
0
|
|
|
|
|
|
my %login_params = |
159
|
|
|
|
|
|
|
( |
160
|
|
|
|
|
|
|
'project' => $self->project(), |
161
|
|
|
|
|
|
|
'password' => $self->_password(), |
162
|
|
|
|
|
|
|
'action' => "login", |
163
|
|
|
|
|
|
|
); |
164
|
|
|
|
|
|
|
|
165
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new(); |
166
|
0
|
|
|
|
|
|
$ua->cookie_jar({}); |
167
|
0
|
|
|
|
|
|
my $response = $ua->post($url, \%login_params); |
168
|
|
|
|
|
|
|
|
169
|
0
|
0
|
|
|
|
|
if (!$response->is_success()) |
170
|
|
|
|
|
|
|
{ |
171
|
0
|
|
|
|
|
|
$self->_gen_error( |
172
|
|
|
|
|
|
|
'phase' => "login", |
173
|
|
|
|
|
|
|
); |
174
|
|
|
|
|
|
|
} |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
# We only need the previous response for the cookie. |
177
|
|
|
|
|
|
|
|
178
|
0
|
|
|
|
|
|
my %backup_params = |
179
|
|
|
|
|
|
|
( |
180
|
|
|
|
|
|
|
'action' => "backup1", |
181
|
|
|
|
|
|
|
'r1' => 0, |
182
|
|
|
|
|
|
|
'r2' => $repos_top_version, |
183
|
|
|
|
|
|
|
'i' => 1, |
184
|
|
|
|
|
|
|
'd' => 1, |
185
|
|
|
|
|
|
|
); |
186
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
$response = $ua->post($url, \%backup_params); |
188
|
|
|
|
|
|
|
|
189
|
0
|
0
|
|
|
|
|
if (! $response->is_success()) |
190
|
|
|
|
|
|
|
{ |
191
|
0
|
|
|
|
|
|
$self->_gen_error( |
192
|
|
|
|
|
|
|
'phase' => "dump_request", |
193
|
|
|
|
|
|
|
); |
194
|
|
|
|
|
|
|
} |
195
|
|
|
|
|
|
|
|
196
|
0
|
|
|
|
|
|
my $server_return = $response->content(); |
197
|
|
|
|
|
|
|
|
198
|
0
|
|
|
|
|
|
my $fetch_file_path; |
199
|
0
|
0
|
|
|
|
|
if ($server_return =~ m{
|
200
|
|
|
|
|
|
|
{ |
201
|
0
|
|
|
|
|
|
$fetch_file_path = $1; |
202
|
|
|
|
|
|
|
} |
203
|
|
|
|
|
|
|
else |
204
|
|
|
|
|
|
|
{ |
205
|
0
|
|
|
|
|
|
$self->_gen_error( |
206
|
|
|
|
|
|
|
'phase' => "dump_wrong_redirect", |
207
|
|
|
|
|
|
|
); |
208
|
|
|
|
|
|
|
} |
209
|
|
|
|
|
|
|
|
210
|
0
|
|
0
|
|
|
|
$response = |
211
|
|
|
|
|
|
|
$ua->get( |
212
|
|
|
|
|
|
|
"$url$fetch_file_path", |
213
|
|
|
|
|
|
|
":content_file" => |
214
|
|
|
|
|
|
|
($args{'filename'} || ($self->project() . ".dump.gz")), |
215
|
|
|
|
|
|
|
); |
216
|
|
|
|
|
|
|
|
217
|
0
|
0
|
|
|
|
|
if (! $response->is_success()) |
218
|
|
|
|
|
|
|
{ |
219
|
0
|
|
|
|
|
|
$self->_gen_error( |
220
|
|
|
|
|
|
|
'phase' => "dump_fetch" |
221
|
|
|
|
|
|
|
); |
222
|
|
|
|
|
|
|
} |
223
|
|
|
|
|
|
|
|
224
|
0
|
|
|
|
|
|
return 0; |
225
|
|
|
|
|
|
|
} |
226
|
|
|
|
|
|
|
|
227
|
|
|
|
|
|
|
1; |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
__END__ |