From: Don Armstrong Date: Mon, 27 Jan 2014 19:29:43 +0000 (-0800) Subject: fix rebuild cache and pdf opening X-Git-Url: https://git.donarmstrong.com/?a=commitdiff_plain;h=0046ab21881959e4264ca31eaf4c0e7c94f8a48f;p=bin.git fix rebuild cache and pdf opening --- diff --git a/bibtex_to_paper b/bibtex_to_paper index 9d9cf7c..66fdf09 100755 --- a/bibtex_to_paper +++ b/bibtex_to_paper @@ -20,7 +20,6 @@ use User; use Data::Printer; use DBI; -use Tie::DBI; =head1 NAME @@ -87,7 +86,7 @@ my %options = (debug => 0, ); GetOptions(\%options, - 'build_cache|build-cache|B!', + 'build_cache|build-cache!', 'bibtex|b=s@', 'bibtex_cache|bibtex-cache|c=s', 'pdfviewer|p=s', @@ -131,6 +130,7 @@ sub main{ [@ARGV, @{ref $options{bibtex}?$options{bibtex}:[$options{bibtex}]}, ]; + @ARGV = (); } if (exists $options{bibtex}) { for my $bibtex_file (@{ref $options{bibtex}?$options{bibtex}:[$options{bibtex}]}) { @@ -150,6 +150,7 @@ sub main{ load_bibtex_entries_into_database($dbh,$sth,\%entries); } + p @ARGV if $DEBUG; for my $bibtex_key (@ARGV) { open_bibtex_key(\%options,$dbh,$sth,\%entries,$bibtex_key); } @@ -167,7 +168,7 @@ sub load_papers_into_database { if (-e "${_}.xoj") { $xoj = 1; } - insert_or_replace_papers($dbh,$sth,basename($File::Find::name),File::Spec->rel2abs($File::Find::name),$xoj); + insert_or_replace_papers($dbh,$sth,basename($File::Find::name),File::Spec->rel2abs($_),$xoj); }; my @pdfs; @@ -186,7 +187,7 @@ sub load_bibtex_entries_into_database { next unless defined $entries->{$entry}; $sth->{insert_bibtex}->execute($entry,@{$entries->{$entry}}{qw(file_name doi html)}); $sth->{insert_bibtex}->finish(); - print STDERR "inserted $entry $entries->{$entry}\n" if $DEBUG; + print STDERR "inserted $entry {".join(',',map {defined $_?"'$_'":"'undef'"} %{$entries->{$entry}})."}\n" if $DEBUG; } } @@ -239,7 +240,7 @@ sub open_entry{ p $paper if $DEBUG; print STDERR $entry->{file_name} if $DEBUG; if (defined $paper) { - open_pdf($paper->{file_name},$options,$paper->{xoj}); + open_pdf($paper->{path},$options,$paper->{has_xoj}); return; } } @@ -259,6 +260,10 @@ sub select_entry_from_bibtex_key{ my ($dbh,$sth,$bibtex_key) = @_; my $entry = select_one($dbh,$sth->{select_bibtex_by_key},$bibtex_key); + if (not defined $entry) { + $bibtex_key =~ s/:.*$//; + $entry = select_one($dbh,$sth->{select_bibtex_by_approximate_key},$bibtex_key.'%'); + } return $entry; } @@ -382,6 +387,9 @@ SELECT * FROM papers WHERE path = ?; EOF select_bibtex_by_key => <<'EOF', SELECT * FROM bibtex WHERE bibtex_key = ?; +EOF + select_bibtex_by_approximate_key => <<'EOF', +SELECT * FROM bibtex WHERE bibtex_key LIKE ?; EOF select_bibtex_by_file_name => <<'EOF', SELECT * FROM bibtex WHERE file_name = ?;