Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
docu-tools
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Package registry
Model registry
Operate
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Gerhard Gonter
docu-tools
Commits
d6496d0e
Commit
d6496d0e
authored
11 years ago
by
Gerhard Gonter
Browse files
Options
Downloads
Patches
Plain Diff
added "tom" script as a more general tool to work with Tomboy files
parent
a58367da
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
perl/Gnome-Tomboy/lib/Tomboy/TOC.pm
+106
-0
106 additions, 0 deletions
perl/Gnome-Tomboy/lib/Tomboy/TOC.pm
perl/Gnome-Tomboy/tom
+148
-0
148 additions, 0 deletions
perl/Gnome-Tomboy/tom
with
254 additions
and
0 deletions
perl/Gnome-Tomboy/lib/Tomboy/TOC.pm
0 → 100644
+
106
−
0
View file @
d6496d0e
#!/usr/bin/perl
package
Tomboy::
TOC
;
use
strict
;
use
Tomboy::
Directory
;
sub
new
{
my
$class
=
shift
;
my
$self
=
{};
bless
$self
,
$class
;
$self
->
set
(
@
_
);
$self
;
}
sub
set
{
my
$self
=
shift
;
my
%par
=
@_
;
foreach
my
$par
(
keys
%par
)
{
$self
->
{
$par
}
=
$par
{
$par
};
}
}
sub
find
{
my
$self
=
shift
;
my
$pattern
=
shift
;
print
"
find: pattern=[
$pattern
]
\n
";
my
(
$mode
,
$toc
,
$rows
)
=
$self
->
load_toc
();
my
@res
;
foreach
my
$row
(
@$rows
)
{
next
unless
(
$row
->
{'
title
'}
=~
m#$pattern#i
);
# print "row: ", main::Dumper ($row);
push
(
@res
,
$row
);
}
@res
;
}
sub
scan_dir
{
my
$self
=
shift
;
print
main::
Dumper
(
$self
);
my
(
$note_dir
,
$toc_file
)
=
map
{
$self
->
{
$_
}
}
qw(note_dir toc_file)
;
$note_dir
=~
s#/+$##
;
my
$tb_d
=
new
Tomboy::
Directory
();
# print "tb_d: ", Dumper ($tb_d);
print
"
scanning [
$note_dir
]
\n
";
my
(
$mode
,
$toc
,
$rows
)
=
$self
->
load_toc
();
my
$toc_data
=
$tb_d
->
scan_dir
(
$note_dir
,
$rows
,
$mode
);
# TODO: if verbose or so print "toc_data: ", Dumper ($toc_data);
$toc
->
{'
data
'}
=
$toc_data
;
# TODO: optionally sort the returned values
$toc
->
sort
('
uuid
');
# print "toc: ", Dumper ($toc);
$toc
->
save_csv_file
('
filename
'
=>
$toc_file
,
'
separator
'
=>
"
\t
",
'
UTF8
'
=>
1
);
}
sub
load_toc
{
my
$self
=
shift
;
my
$mode
=
0
;
my
$toc
;
print
"
load_toc
\n
";
return
(
1
,
$toc
,
$toc
->
{'
data
'})
if
(
defined
(
$toc
=
$self
->
{'
_toc
'}));
my
(
$toc_file
)
=
map
{
$self
->
{
$_
}
}
qw(toc_file)
;
print
"
load_toc: toc_file=[
$toc_file
]
\n
";
my
$toc
=
new
Util::
Simple_CSV
('
UTF8
'
=>
1
,
'
no_array
'
=>
1
,
'
separator
'
=>
"
\t
",
'
UTF8
'
=>
1
);
my
$rows
=
[]
;
if
(
-
f
$toc_file
)
{
print
"
loading
$toc_file
\n
";
$toc
->
load_csv_file
(
$toc_file
);
$mode
=
1
;
$rows
=
$toc
->
{'
data
'};
print
"
preparing quick scan, loaded [
$toc_file
]
\n
";
# print "toc: ", Dumper ($toc);
# print "rows: ", Dumper ($rows);
# exit;
}
else
{
$toc
->
define_columns
(
Tomboy::Directory::
TB_attrs
());
}
$self
->
{'
_toc
'}
=
$toc
;
(
$mode
,
$toc
,
$rows
);
}
1
;
This diff is collapsed.
Click to expand it.
perl/Gnome-Tomboy/tom
0 → 100755
+
148
−
0
View file @
d6496d0e
#!/usr/bin/perl
=head1 NAME
tom
=head1 DESCRIPTION
do stuff with Tomboy files
=head1 USAGE
tom <op-code> @options @parameters
=head1 OPTIONS
...
=head1 OP-CODES
=head2 show
=head2 diff
=cut
use
strict
;
use
Data::
Dumper
;
$
Data::Dumper::
Indent
=
1
;
use
Util::
Simple_CSV
;
use
Tomboy::Note::
Simple
;
use
Tomboy::
Directory
;
use
Tomboy::
TOC
;
my
$toc_file
;
my
$note_dir
=
$ENV
{'
HOME
'}
.
'
/.local/share/tomboy
';
my
$start_tb
=
0
;
my
$toc
;
my
$op_code
;
my
@PAR
;
while
(
my
$arg
=
shift
(
@ARGV
))
{
if
(
$arg
=~
/^-/
)
{
if
(
$arg
eq
'
-d
')
{
$note_dir
=
shift
(
@ARGV
);
}
elsif
(
$arg
eq
'
-t
')
{
$toc_file
=
shift
(
@ARGV
);
}
elsif
(
$arg
eq
'
-e
')
{
$start_tb
=
1
;
}
else
{
usage
();
}
}
else
{
push
(
@PAR
,
$arg
);
}
}
my
$op_code
=
shift
(
@PAR
)
unless
(
defined
(
$op_code
));
if
(
$op_code
eq
'
help
')
{
usage
();
}
elsif
(
$op_code
eq
'
dump
')
{
dump_note
(
$_
)
foreach
(
@PAR
);
}
elsif
(
$op_code
eq
'
toc
')
{
tom_toc
();
}
elsif
(
$op_code
eq
'
find
')
{
find_note
(
@PAR
);
}
elsif
(
$op_code
eq
'
diff
')
{
my
$f1
=
shift
(
@PAR
);
my
$n1
=
parse
Tomboy::Note::
Simple
(
$f1
);
foreach
my
$f2
(
@PAR
)
{
my
$n2
=
parse
Tomboy::Note::
Simple
(
$f2
);
diff_note
(
$n1
,
$n2
);
}
}
else
{
usage
();
}
exit
(
0
);
sub
usage
{
system
('
perldoc
',
$
0
);
exit
;
}
sub
setup_toc
{
$toc_file
=
join
('
/
',
$note_dir
,
'
Tomboy-TOC.csv
')
unless
(
defined
(
$toc_file
));
$toc
=
new
Tomboy::
TOC
('
note_dir
'
=>
$note_dir
,
'
toc_file
'
=>
$toc_file
);
# print "toc: ", Dumper ($toc);
}
sub
tom_toc
{
setup_toc
();
$toc
->
scan_dir
();
}
sub
find_note
{
setup_toc
();
my
%uuid
;
foreach
my
$pattern
(
@
_
)
{
my
@res
=
$toc
->
find
(
$pattern
);
foreach
my
$res
(
@res
)
{
$uuid
{
$res
->
{'
uuid
'}}
=
$res
;
}
# TODO: count hits
}
foreach
my
$uuid
(
keys
%uuid
)
{
if
(
$start_tb
)
{
Tomboy::
start_tb
('
uuid
',
$uuid
);
}
else
{
print
Dumper
(
$uuid
{
$uuid
});
}
}
}
sub
dump_note
{
my
$note_fnm
=
shift
;
my
$n1
=
parse
Tomboy::Note::
Simple
(
$note_fnm
);
$n1
->
update
();
print
"
n1:
",
Dumper
(
$n1
);
}
sub
diff_note
{
my
$n1
=
shift
;
my
$n2
=
shift
;
print
"
n1:
",
Dumper
(
$n1
);
print
"
n2:
",
Dumper
(
$n2
);
}
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment