| 1 | #!perl | ||
| 2 | |||
| 3 | 1 | ▶ | use 5.10.1; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 4 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 5 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | |||
| 7 | $|++; | ||
| 8 | |||
| 9 | 0 | ▶ | use Bot::Cobalt::DB; |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 10 | use Bot::Cobalt::Serializer; | ||
| 11 | |||
| 12 | my($dbpath, $outpath); | ||
| 13 | |||
| 14 | my $format = 'YAMLXS'; | ||
| 15 | |||
| 16 | use Getopt::Long; | ||
| 17 | GetOptions( | ||
| 18 | help => sub { | ||
| 19 | say "Usage: $0 --database=PATH --output=PATH [ --format=TYPE ]"; | ||
| 20 | exit 0 | ||
| 21 | }, | ||
| 22 | |||
| 23 | 'database=s' => \$dbpath, | ||
| 24 | 'input=s' => \$dbpath, | ||
| 25 | |||
| 26 | 'output=s' => \$outpath, | ||
| 27 | |||
| 28 | 'format=s' => \$format, | ||
| 29 | ); | ||
| 30 | |||
| 31 | ## Format check | ||
| 32 | die "$format is not a valid export format; see perldoc Bot::Cobalt::Serializer" | ||
| 33 | unless Bot::Cobalt::Serializer->new->_check_if_avail($format); | ||
| 34 | |||
| 35 | unless ($dbpath) { | ||
| 36 | print "Path to database to be exported: \n > "; | ||
| 37 | $dbpath = <STDIN>; | ||
| 38 | chomp($dbpath); | ||
| 39 | } | ||
| 40 | |||
| 41 | die "could not locate dbpath: $dbpath" | ||
| 42 | unless -f $dbpath; | ||
| 43 | |||
| 44 | unless ($outpath) { | ||
| 45 | print "Output path: \n > "; | ||
| 46 | $outpath = <STDIN>; | ||
| 47 | chomp($outpath); | ||
| 48 | } | ||
| 49 | |||
| 50 | if (-f $outpath) { | ||
| 51 | print "Output path exists...\n"; | ||
| 52 | print "Press ENTER to continue, Ctrl+C to exit. "; | ||
| 53 | <STDIN>; | ||
| 54 | print "\n"; | ||
| 55 | } | ||
| 56 | |||
| 57 | my $db = Bot::Cobalt::DB->new( | ||
| 58 | file => $dbpath, | ||
| 59 | ); | ||
| 60 | |||
| 61 | $db->dbopen(ro => 1) or die "dbopen failure"; | ||
| 62 | my $yaml = $db->dbdump($format) or die "dbdump failure"; | ||
| 63 | $db->dbclose; | ||
| 64 | |||
| 65 | say "Writing $format to $outpath"; | ||
| 66 | |||
| 67 | open my $outfh, '>:encoding(UTF-8)', $outpath or die "open failed: $!"; | ||
| 68 | print $outfh $yaml; | ||
| 69 | close $outfh; | ||
| 70 | |||
| 71 | say "Done."; | ||
| 72 | |||
| 73 | __END__ | ||