23 |
my ( $command, $database, $design ) = @ARGV; |
my ( $command, $database, $design ) = @ARGV; |
24 |
die "usage: $0 [push|pull] database design\n" unless $database && $design; |
die "usage: $0 [push|pull] database design\n" unless $database && $design; |
25 |
|
|
26 |
|
if ( ! -e $design && $command eq 'pull') { |
27 |
|
warn "# create new design $design\n"; |
28 |
|
mkdir $design; |
29 |
|
} |
30 |
|
|
31 |
chdir $design || die "can't find $design: $!"; |
chdir $design || die "can't find $design: $!"; |
32 |
|
|
33 |
my $ua = LWP::UserAgent->new; |
my $ua = LWP::UserAgent->new; |
43 |
#warn "# dir $dir"; |
#warn "# dir $dir"; |
44 |
} |
} |
45 |
} |
} |
46 |
|
|
47 |
|
sub svn { |
48 |
|
my $path = shift; |
49 |
|
return if $path =~ m{(_.*|.*\.(push|pull)\.js)$}; |
50 |
|
system "svn add --parents $path"; |
51 |
|
} |
52 |
|
|
53 |
sub write_file { |
sub write_file { |
54 |
my ( $path, $content ) = @_; |
my ( $path, $content ) = @_; |
55 |
$path =~ s{^/+}{}; |
$path =~ s{^/+}{}; |
56 |
create_path $path; |
create_path $path; |
57 |
File::Slurp::write_file $path, $content; |
File::Slurp::write_file $path, $content; |
58 |
print "$path ", -s $path, " bytes created\n"; |
print "$path ", -s $path, " bytes created\n"; |
59 |
|
svn $path; |
60 |
} |
} |
61 |
|
|
62 |
sub write_attachment { |
sub write_attachment { |
65 |
create_path $file; |
create_path $file; |
66 |
$ua->mirror( "$url/$path", $file ); |
$ua->mirror( "$url/$path", $file ); |
67 |
print "detached $file ", -s $file, " bytes\n"; |
print "detached $file ", -s $file, " bytes\n"; |
68 |
|
svn $file; |
69 |
} |
} |
70 |
|
|
71 |
|
|
112 |
|
|
113 |
} elsif ( $command eq 'push' ) { |
} elsif ( $command eq 'push' ) { |
114 |
|
|
115 |
|
$ua->request( HTTP::Request::Common::PUT( "http://localhost:5984/$database" ) ) && warn "# created database $database\n"; |
116 |
|
|
117 |
my $json; |
my $json; |
118 |
|
|
119 |
find({ no_chdir => 1, wanted => sub { |
find({ no_chdir => 1, wanted => sub { |
120 |
my $path = $File::Find::name; |
my $path = $File::Find::name; |
121 |
return unless -f $path; |
return unless -f $path; |
122 |
|
return if $path =~ m{/\.svn}; |
123 |
|
|
124 |
warn "## $path\n"; |
warn "## $path\n"; |
125 |
|
|