69 lines
2.5 KiB
Scheme
Executable File
69 lines
2.5 KiB
Scheme
Executable File
#!/usr/bin/guile \
|
||
-e (@\ (gnunet-search)\ main) -L . -s
|
||
!#
|
||
;;;; Copyright © 2015 Rémi Delrue <asgeir@free.fr>
|
||
;;;;
|
||
;;;; This program is free software: you can redistribute it and/or modify
|
||
;;;; it under the terms of the GNU General Public License as published by
|
||
;;;; the Free Software Foundation, either version 3 of the License, or
|
||
;;;; (at your option) any later version.
|
||
;;;;
|
||
;;;; This program is distributed in the hope that it will be useful,
|
||
;;;; but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||
;;;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||
;;;; GNU General Public License for more details.
|
||
;;;;
|
||
;;;; You should have received a copy of the GNU General Public License
|
||
;;;; along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||
|
||
(define-module (gnunet-search)
|
||
#:use-module (ice-9 match)
|
||
#:use-module (system foreign)
|
||
#:use-module (gnu gnunet common)
|
||
#:use-module (gnu gnunet container metadata)
|
||
#:use-module (gnu gnunet fs)
|
||
#:use-module (gnu gnunet fs uri)
|
||
#:use-module (gnu gnunet fs progress-info)
|
||
#:use-module (gnu gnunet configuration)
|
||
#:use-module (gnu gnunet scheduler)
|
||
#:export (main))
|
||
|
||
(define config-file "~/.gnunet/gnunet.conf")
|
||
|
||
|
||
(define (progress-cb %info)
|
||
(when (equal? '(#:search #:result) (progress-info-status %info))
|
||
(match (parse-c-progress-info %info)
|
||
(((context _ _ query duration anonymity
|
||
(%metadata %uri %result applicability-rank)) _ _)
|
||
(let* ((uri (uri->string (wrap-uri %uri)))
|
||
(meta (wrap-metadata %metadata))
|
||
(result-directory? (is-directory? meta))
|
||
(result-filename (metadata-ref meta #:original-filename)))
|
||
(cond ((and result-directory?
|
||
(string-null? result-filename))
|
||
(simple-format
|
||
#t "gnunet-download -o \"collection.gnd\" -R ~a\n" uri))
|
||
(result-directory?
|
||
(simple-format #t
|
||
"gnunet-download -o \"~a.gnd\" -R ~a\n"
|
||
result-filename uri))
|
||
((string-null? result-filename)
|
||
(simple-format #t "gnunet-download ~a\n"
|
||
uri))
|
||
(else
|
||
(simple-format #t "gnunet-download -o \"~a\" ~a\n"
|
||
result-filename uri))))))))
|
||
|
||
(define (main args)
|
||
(let ((config (load-configuration config-file)))
|
||
(define (first-task _)
|
||
(let* ((fs-service (open-filesharing-service config (car args)
|
||
progress-cb))
|
||
(uri (apply make-ksk-uri (cdr args)))
|
||
(search (start-search fs-service uri)))
|
||
;; adds a timeout in 5 seconds
|
||
(add-task! (lambda (_) (stop-search search))
|
||
#:delay (time-rel #:seconds 5))))
|
||
(call-with-scheduler config first-task)))
|