line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::Cmd::export; |
2
|
|
|
|
|
|
|
|
3
|
14
|
|
|
14
|
|
166363
|
use Catmandu::Sane; |
|
14
|
|
|
|
|
40
|
|
|
14
|
|
|
|
|
86
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.2020'; |
6
|
|
|
|
|
|
|
|
7
|
14
|
|
|
14
|
|
109
|
use parent 'Catmandu::Cmd'; |
|
14
|
|
|
|
|
40
|
|
|
14
|
|
|
|
|
88
|
|
8
|
14
|
|
|
14
|
|
1027
|
use Catmandu; |
|
14
|
|
|
|
|
33
|
|
|
14
|
|
|
|
|
72
|
|
9
|
14
|
|
|
14
|
|
8814
|
use Catmandu::ArrayIterator; |
|
14
|
|
|
|
|
39
|
|
|
14
|
|
|
|
|
431
|
|
10
|
14
|
|
|
14
|
|
102
|
use namespace::clean; |
|
14
|
|
|
|
|
35
|
|
|
14
|
|
|
|
|
79
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub command_opt_spec { |
13
|
|
|
|
|
|
|
( |
14
|
2
|
|
|
2
|
1
|
46
|
["verbose|v", ""], |
15
|
|
|
|
|
|
|
["fix=s@", ""], |
16
|
|
|
|
|
|
|
["var=s%", ""], |
17
|
|
|
|
|
|
|
["preprocess|pp", ""], |
18
|
|
|
|
|
|
|
["start=i", ""], |
19
|
|
|
|
|
|
|
["limit=i", ""], |
20
|
|
|
|
|
|
|
["total=i", ""], |
21
|
|
|
|
|
|
|
["cql-query|q=s", ""], |
22
|
|
|
|
|
|
|
["query=s", ""], |
23
|
|
|
|
|
|
|
["sru-sortkeys=s", ""], |
24
|
|
|
|
|
|
|
["sort=s", ""], |
25
|
|
|
|
|
|
|
["id=s@", ""], |
26
|
|
|
|
|
|
|
["id-file=s", "A line-delimited file containing the id's to export."], |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub command { |
31
|
2
|
|
|
2
|
1
|
6
|
my ($self, $opts, $args) = @_; |
32
|
|
|
|
|
|
|
|
33
|
2
|
|
|
|
|
16
|
my ($from_args, $from_opts, $into_args, $into_opts) |
34
|
|
|
|
|
|
|
= $self->_parse_options($args); |
35
|
|
|
|
|
|
|
|
36
|
2
|
|
|
|
|
5
|
my $from_bag = delete $from_opts->{bag}; |
37
|
2
|
|
|
|
|
15
|
my $from = Catmandu->store($from_args->[0], $from_opts)->bag($from_bag); |
38
|
2
|
|
|
|
|
18
|
my $into = Catmandu->exporter($into_args->[0], $into_opts); |
39
|
|
|
|
|
|
|
|
40
|
2
|
100
|
33
|
|
|
12
|
if ($opts->id_file) { |
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
|
|
50
|
33
|
|
|
|
|
41
|
1
|
|
|
|
|
6
|
my $bag = $from; |
42
|
|
|
|
|
|
|
$from = Catmandu->importer('Text', file => $opts->id_file) |
43
|
1
|
|
|
3
|
|
4
|
->map(sub {$bag->get($_[0]->{text})}); |
|
3
|
|
|
|
|
67
|
|
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
elsif (my $ids = $opts->id) { |
46
|
0
|
|
|
|
|
0
|
my $bag = $from; |
47
|
0
|
|
|
|
|
0
|
$from = Catmandu::ArrayIterator->new([map {$bag->get($_)} @$ids]); |
|
0
|
|
|
|
|
0
|
|
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
elsif ($opts->query // $opts->cql_query // $opts->sort |
50
|
|
|
|
|
|
|
// $opts->sru_sortkeys) |
51
|
|
|
|
|
|
|
{ |
52
|
0
|
0
|
|
|
|
0
|
$self->usage_error("Bag isn't searchable") |
53
|
|
|
|
|
|
|
if !$from->does('Catmandu::Searchable'); |
54
|
0
|
0
|
0
|
|
|
0
|
$self->usage_error("Bag isn't CQL searchable") |
|
|
|
0
|
|
|
|
|
55
|
|
|
|
|
|
|
if ($opts->cql_query // $opts->sru_sortkeys) |
56
|
|
|
|
|
|
|
&& !$from->does('Catmandu::CQLSearchable'); |
57
|
0
|
|
|
|
|
0
|
$from = $from->searcher( |
58
|
|
|
|
|
|
|
cql_query => $opts->cql_query, |
59
|
|
|
|
|
|
|
query => $opts->query, |
60
|
|
|
|
|
|
|
sru_sortkeys => $opts->sru_sortkeys, |
61
|
|
|
|
|
|
|
sort => $opts->sort, |
62
|
|
|
|
|
|
|
start => $opts->start, |
63
|
|
|
|
|
|
|
total => $opts->total, |
64
|
|
|
|
|
|
|
limit => $opts->limit, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
elsif ($opts->start // $opts->total) { |
68
|
1
|
|
|
|
|
51
|
$from = $from->slice($opts->start, $opts->total); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
2
|
100
|
|
|
|
10
|
if ($opts->fix) { |
72
|
1
|
|
|
|
|
16
|
$from = $self->_build_fixer($opts)->fix($from); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
2
|
50
|
|
|
|
57
|
if ($opts->verbose) { |
76
|
2
|
|
|
|
|
19
|
$from = $from->benchmark; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
|
79
|
2
|
|
|
|
|
14
|
my $n = $into->add_many($from); |
80
|
2
|
|
|
|
|
50
|
$into->commit; |
81
|
2
|
50
|
|
|
|
12
|
if ($opts->verbose) { |
82
|
2
|
100
|
|
|
|
161
|
say STDERR $n == 1 ? "exported 1 item" : "exported $n items"; |
83
|
2
|
|
|
|
|
44
|
say STDERR "done"; |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
__END__ |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=pod |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head1 NAME |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Catmandu::Cmd::export - export items from a store |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=head1 EXAMPLES |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
catmandu export <STORE> <OPTIONS> to <EXPORTER> <OPTIONS> |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
catmandu export MongoDB --database-name items --bag book to YAML |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
catmandu export ElasticSearch --bag book --sru-sortkeys 'title,,1' --cql-query '(title = "test")' |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
catmandu help store MongoDB |
106
|
|
|
|
|
|
|
catmandu help exporter YAML |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=cut |