mirror of
https://codeberg.org/scip/note.git
synced 2025-12-17 12:41:10 +01:00
added JSON export format:
Starting with version 1.4 JSON export format will be supported but not be enabled by default. However a deprecation notice will appear if a user still uses YAML format. YAML support will be removed in version 1.5. Fixes https://github.com/TLINDEN/note/issues/10.
This commit is contained in:
9
README
9
README
@@ -1,4 +1,4 @@
|
|||||||
note 1.3.26 by T.v.Dein (09/02/2015)
|
note 1.4.0 by T.v.Dein (13/08/2023)
|
||||||
=======================================
|
=======================================
|
||||||
|
|
||||||
Introduction
|
Introduction
|
||||||
@@ -104,6 +104,11 @@ You need the following things:
|
|||||||
you want to use the auto-completion and history functionality.
|
you want to use the auto-completion and history functionality.
|
||||||
o Config::General if you want to use the NOTEDB::general
|
o Config::General if you want to use the NOTEDB::general
|
||||||
backend.
|
backend.
|
||||||
|
o YAML is needed to create backups using -D. Please note,
|
||||||
|
that this format is deprecated starting with 1.4.0. The
|
||||||
|
Support will be removed in 1.5.0. Please switch to JSON
|
||||||
|
format as soon as possible, either by using the -j
|
||||||
|
commandline option or the UseJSON configuration value.
|
||||||
|
|
||||||
|
|
||||||
Installation
|
Installation
|
||||||
@@ -207,4 +212,4 @@ and I'll add you.
|
|||||||
Last changed
|
Last changed
|
||||||
============
|
============
|
||||||
|
|
||||||
09/02/2015
|
13/08/2023
|
||||||
|
|||||||
41
bin/note
41
bin/note
@@ -1,7 +1,7 @@
|
|||||||
#!/usr/bin/perl
|
#!/usr/bin/perl
|
||||||
#
|
#
|
||||||
# note - console notes management with database and encryption support.
|
# note - console notes management with database and encryption support.
|
||||||
# Copyright (C) 1999-2017 T.v.Dein (see README for details!)
|
# Copyright (C) 1999-2023 T.v.Dein (see README for details!)
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or
|
# This program is free software; you can redistribute it and/or
|
||||||
# modify it under the terms of the GNU General Public License
|
# modify it under the terms of the GNU General Public License
|
||||||
@@ -38,6 +38,7 @@ use Getopt::Long;
|
|||||||
use FileHandle;
|
use FileHandle;
|
||||||
use File::Spec;
|
use File::Spec;
|
||||||
use YAML;
|
use YAML;
|
||||||
|
use JSON::PP;
|
||||||
|
|
||||||
|
|
||||||
#
|
#
|
||||||
@@ -71,6 +72,7 @@ my (
|
|||||||
$opt_, $opt_i, $opt_r, $opt_e, $opt_d, $opt_enc,
|
$opt_, $opt_i, $opt_r, $opt_e, $opt_d, $opt_enc,
|
||||||
$opt_s, $opt_t, $opt_T, $opt_l, $opt_L, $opt_c,
|
$opt_s, $opt_t, $opt_T, $opt_l, $opt_L, $opt_c,
|
||||||
$opt_D, $opt_I, $opt_o, $opt_h, $opt_n, $opt_v,
|
$opt_D, $opt_I, $opt_o, $opt_h, $opt_n, $opt_v,
|
||||||
|
$opt_j,
|
||||||
|
|
||||||
#
|
#
|
||||||
# set from commandline (or interactive)
|
# set from commandline (or interactive)
|
||||||
@@ -133,7 +135,8 @@ my (
|
|||||||
'printlines' => 0,
|
'printlines' => 0,
|
||||||
'cache' => 0,
|
'cache' => 0,
|
||||||
'preferrededitor' => '',
|
'preferrededitor' => '',
|
||||||
'motd' => ''
|
'motd' => '',
|
||||||
|
'usejson' => 0, # will be the default in the future
|
||||||
);
|
);
|
||||||
|
|
||||||
# these are not customizable at runtime!
|
# these are not customizable at runtime!
|
||||||
@@ -141,7 +144,7 @@ $hardparams = "(readonly|maxlen|dbdriver|useencryption|cryptmethod)";
|
|||||||
$CONF = File::Spec->catfile($ENV{HOME}, ".noterc");
|
$CONF = File::Spec->catfile($ENV{HOME}, ".noterc");
|
||||||
$USER = getlogin || getpwuid($<); chomp $USER;
|
$USER = getlogin || getpwuid($<); chomp $USER;
|
||||||
$TOPIC = 1;
|
$TOPIC = 1;
|
||||||
$VERSION = "1.3.26";
|
$VERSION = "1.4.0";
|
||||||
$CurDepth = 1; # the current depth inside the topic "directory" structure...
|
$CurDepth = 1; # the current depth inside the topic "directory" structure...
|
||||||
$maxlen = "auto";
|
$maxlen = "auto";
|
||||||
$timelen = 22;
|
$timelen = 22;
|
||||||
@@ -214,6 +217,7 @@ else {
|
|||||||
"list|l:s" => \$opt_l, # string, optional
|
"list|l:s" => \$opt_l, # string, optional
|
||||||
"longlist|L:s" => \$opt_L, # string, optional
|
"longlist|L:s" => \$opt_L, # string, optional
|
||||||
"dump|Dump|D:s" => \$opt_D, # string, optional
|
"dump|Dump|D:s" => \$opt_D, # string, optional
|
||||||
|
"json|j" => \$opt_j, # bool, optional
|
||||||
"import|Import|I:s" => \$opt_I, # string, optional
|
"import|Import|I:s" => \$opt_I, # string, optional
|
||||||
"overwrite|o!" => \$opt_o, # no arg
|
"overwrite|o!" => \$opt_o, # no arg
|
||||||
"help|h|?!" => \$opt_h, # no arg
|
"help|h|?!" => \$opt_h, # no arg
|
||||||
@@ -276,6 +280,10 @@ else {
|
|||||||
else {
|
else {
|
||||||
$dump_file = "-"; # use STDIN
|
$dump_file = "-"; # use STDIN
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (defined $opt_j) {
|
||||||
|
$conf{usejson} = 1; # force JSON
|
||||||
|
}
|
||||||
}
|
}
|
||||||
elsif (defined $opt_I) {
|
elsif (defined $opt_I) {
|
||||||
$mode = "import";
|
$mode = "import";
|
||||||
@@ -923,6 +931,7 @@ sub edit {
|
|||||||
|
|
||||||
sub dump {
|
sub dump {
|
||||||
my(%res, $num, $DUMP);
|
my(%res, $num, $DUMP);
|
||||||
|
|
||||||
# $dump_file
|
# $dump_file
|
||||||
if ($dump_file eq "-") {
|
if ($dump_file eq "-") {
|
||||||
$DUMP = *STDOUT;
|
$DUMP = *STDOUT;
|
||||||
@@ -931,8 +940,11 @@ sub dump {
|
|||||||
open (DUMPFILE, ">$dump_file") or die "could not open $dump_file\n";
|
open (DUMPFILE, ">$dump_file") or die "could not open $dump_file\n";
|
||||||
$DUMP = *DUMPFILE;
|
$DUMP = *DUMPFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
select $DUMP;
|
select $DUMP;
|
||||||
|
|
||||||
%res = $db->get_all();
|
%res = $db->get_all();
|
||||||
|
|
||||||
# FIXME: prepare hashing in NOTEDB class
|
# FIXME: prepare hashing in NOTEDB class
|
||||||
foreach $num (sort { $a <=> $b } keys %res) {
|
foreach $num (sort { $a <=> $b } keys %res) {
|
||||||
print STDOUT "dumping note number $num to $dump_file\n" if($dump_file ne "-");
|
print STDOUT "dumping note number $num to $dump_file\n" if($dump_file ne "-");
|
||||||
@@ -947,7 +959,17 @@ sub dump {
|
|||||||
my $date = $res{$num}->{date};
|
my $date = $res{$num}->{date};
|
||||||
$res{$num} = { body => $body, title => $title, path => $path, date => $date};
|
$res{$num} = { body => $body, title => $title, path => $path, date => $date};
|
||||||
}
|
}
|
||||||
print Dump(\%res);
|
|
||||||
|
if($conf{usejson}) {
|
||||||
|
my $json = JSON::PP->new->utf8->pretty;
|
||||||
|
print $json->encode(\%res);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
warn "Deprecation notice: YAML export format will not be supported in the future!
|
||||||
|
Enable JSON using the UseJSON config parameter or the -j commandline parameter!";
|
||||||
|
print Dump(\%res);
|
||||||
|
}
|
||||||
|
|
||||||
close(DUMPFILE);
|
close(DUMPFILE);
|
||||||
select STDOUT;
|
select STDOUT;
|
||||||
}
|
}
|
||||||
@@ -964,9 +986,16 @@ sub import {
|
|||||||
$DUMP = *DUMPFILE;
|
$DUMP = *DUMPFILE;
|
||||||
}
|
}
|
||||||
|
|
||||||
my $yaml = join '', <$DUMP>;
|
my $serialized = join '', <$DUMP>;
|
||||||
|
|
||||||
my $res = Load($yaml);
|
my $res;
|
||||||
|
|
||||||
|
if($serialized =~ /^\{/) {
|
||||||
|
$res = decode_json($serialized);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
$res = Load($serialized);
|
||||||
|
}
|
||||||
|
|
||||||
foreach my $number (keys %{$res}) {
|
foreach my $number (keys %{$res}) {
|
||||||
my $note;
|
my $note;
|
||||||
|
|||||||
@@ -283,6 +283,12 @@ AddTicket = NO
|
|||||||
motd =
|
motd =
|
||||||
|
|
||||||
|
|
||||||
|
#
|
||||||
|
# Enable JSON formatted backups. The option will be removed
|
||||||
|
# in version 1.5 and become the only available option.
|
||||||
|
# In earlier versions: if unset or set to NO, YAML will be used.
|
||||||
|
UseJSON = YES
|
||||||
|
|
||||||
#
|
#
|
||||||
#
|
#
|
||||||
# That's all about it for now.
|
# That's all about it for now.
|
||||||
|
|||||||
6
note.pod
6
note.pod
@@ -77,6 +77,10 @@ the specified ones.
|
|||||||
Dumps all notes to the textfile <file>. If <file> is a "-" it will
|
Dumps all notes to the textfile <file>. If <file> is a "-" it will
|
||||||
be printed out to standard output (STDOUT).
|
be printed out to standard output (STDOUT).
|
||||||
|
|
||||||
|
=item I<-j --json>
|
||||||
|
|
||||||
|
Use JSON format for exports created using -D. The importer determines
|
||||||
|
the format to be used automatically.
|
||||||
|
|
||||||
=item I<-I, --Import file | ->
|
=item I<-I, --Import file | ->
|
||||||
|
|
||||||
@@ -534,6 +538,6 @@ T.v.Dein <tlinden@cpan.org>
|
|||||||
|
|
||||||
=head1 VERSION
|
=head1 VERSION
|
||||||
|
|
||||||
1.3.26
|
1.4.0
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|||||||
Reference in New Issue
Block a user