]> git.donarmstrong.com Git - bin.git/blobdiff - bibtex_to_paper
remove convert_to_xls and .sa_bin
[bin.git] / bibtex_to_paper
index c7165a3b2beab9b12bd6caf1ab83d4f73313a0af..d5c6bb1e37c7fb638adcbd0db64783ca43c97f90 100755 (executable)
@@ -91,6 +91,7 @@ my %options = (debug           => 0,
                man             => 0,
                only_print      => 0,
                search_by_pmid  => 0,
+               use_git         => 1,
                'bibtex_cache'  => File::Spec->catfile(User->Home,'.bibtex_to_paper_cache'),
               );
 
@@ -99,6 +100,7 @@ GetOptions(\%options,
            'bibtex|b=s@',
            'bibtex_cache|bibtex-cache|c=s',
            'pdfviewer|p=s',
+           'use_git|use-git!',
            'only_print|only-print!',
            'search_by_pmid|search-by-pmid!',
            'clear_cache|clear-cache!',
@@ -156,13 +158,17 @@ sub main{
     if (exists $options{papers_directory} and
         defined $dbh
        ) {
+        $dbh->begin_work;
         load_papers_into_database($dbh,$sth,$options{papers_directory});
+        $dbh->commit;
     }
 
     p %entries if $DEBUG;
     if (keys %entries and
         defined $dbh) {
+        $dbh->begin_work;
         load_bibtex_entries_into_database($dbh,$sth,\%entries);
+        $dbh->commit;
     }
 
     p @ARGV if $DEBUG;
@@ -183,21 +189,27 @@ sub load_papers_into_database {
 
     my @dirs = ref($dir)?@{$dir}:$dir;
 
-    my $actually_load_it = sub {
-        if (/\.git/) {
-            $File::Find::prune = 1;
-            return;
-        }
-        return unless /\.pdf$/;
-        my $xoj = 0;
-        if (-e "${_}.xoj") {
-            $xoj = 1;
+    if ($options{use_git}) {
+        my @files = grep /\.pdf\"?$/, split /\n/, qx(git ls-tree HEAD -r --full-name --name-only);
+        for my $file  (@files) {
+            $file =~ s/^\"(.+)\"$/"qq($1)"/gee;
+            insert_or_replace_papers($dbh,$sth,basename($file),File::Spec->rel2abs($file), -e "${file}.xoj");
         }
-        insert_or_replace_papers($dbh,$sth,basename($File::Find::name),File::Spec->rel2abs($_),$xoj);
-    };
-
-    my @pdfs;
-    find($actually_load_it,@dirs);
+    } else {
+        my $actually_load_it = sub {
+            if (/\.git/) {
+                $File::Find::prune = 1;
+                return;
+            }
+            return unless /\.pdf$/;
+            my $xoj = 0;
+            if (-e "${_}.xoj") {
+                $xoj = 1;
+            }
+            insert_or_replace_papers($dbh,$sth,basename($File::Find::name),File::Spec->rel2abs($_),$xoj);
+        };
+        find($actually_load_it,@dirs);
+    }
 }
 
 sub insert_or_replace_papers {
@@ -254,11 +266,11 @@ sub fork_exec {
 sub open_pdf {
     my ($file_name,$options,$has_xoj) = @_;
     print STDERR "opening $file_name\n" if $DEBUG;
-    if ($has_xoj) {
-        fork_exec('xournal',$file_name);
-    } else {
-        fork_exec('xournal',$file_name)
+    my $pdf_viewer = 'xournal';
+    if (exists $options->{pdfviewer} and defined $options->{pdfviewer}) {
+        $pdf_viewer = $options->{pdfviewer};
     }
+    fork_exec($pdf_viewer,$file_name);
 }
 
 sub open_browser{