I have pushed the new gnunet-search with printf-like capabilities to the git repository. I have also updated the man page. Feel free to play with it and write your feedbacks :)
--madmurphy On Tue, Feb 8, 2022 at 1:39 PM madmurphy <madmurphy...@gmail.com> wrote: > Last proposal about gnunet-search, then I will stop because the program > is becoming hardcore: add a %[NUM]#[SPEC] syntax for the metadata > specifiers (now they are two, %a and %j) in order to extract only > specific metatypes. For example, -f '%f%49#j\n' -i ' (%p)' will print the > file's keywords in brackets, if found. Something like (emphasis mine) > > $ gnunet-search commons -f '%f%49#j\n' -i ' (%p)' > > 2019 Helfrich; Bollier_ Frei, fair und lebendig - Die Macht der Commons.pdf > Rose, Carol (1986)_ The Comedy of the Commons_ Commerce, Custom, and > inherently Public Property.pdf > De Angelis (2017)_ Omnia Sunt Communia. On the Commons and the Transformation > to Postcapitalism.pdf > Ostrom, Elinor (1990)_ Governing the Commons. The evolution of institutions > for collective action.pdf > Gemeingueter_Report_Commons.pdf*File with keywords.pdf (some keyword, some > other keyword, etc.)* > Rose, Carol (1986)_ The Comedy of the Commons_ Commerce, Custom, and > inherently Public Property.pdf > Klick, Jonna (2021)_ Massimo de Angelis - Omnia Sunt Communia - Eine > Grundlegung der Commons - Rezension.pdf > Helfrich, Silke_ Logik der Commons und des Marktes.png > Hardin, Garett (1968)_ Tragedy of the Commons.pdf*Another file with > keywords.pdf (some keyword, some other keyword, etc.)* > Liotard (2017)_ Fablab - a new space for commons based peer production.pdf > Neustart Schweiz (2016)_ Nach Hause kommen. Nachbarschaften als Commons.pdf > > The number 49 is the EXTRACTOR_METATYPE_KEYWORDS identifier from > extractor.h (not the search keywords). Once again, the new help page > should explain it: > > $ gnunet-search --help > > gnunet-search [OPTIONS] KEYWORD1 KEYWORD2 ... > Search for files that have been published on GNUnet > > Keywords should start with a plus sign to indicate that they are required - > e.g. `gnunet-search commons gpl` searches for files that match either > "commons" or "gpl", whereas `gnunet-search +commons +gpl` searches for files > that match both "commons" and "gpl". > > Arguments mandatory for long options are also mandatory for short options. > -a, --anonymity=LEVEL set the desired LEVEL of receiver-anonymity > -c, --config=FILENAME use configuration file FILENAME > -F, --dir-printf=FORMAT write search results for directories according to > FORMAT; the format specifiers supported here > are identical to the --printf argument (please > see there for more information); if missing, > --dir-printf defaults to --printf; if the > latter is missing too --dir-printf defaults to > `#%n:\ngnunet-download -o '%f' -R %u\n\n` > -f, --printf=FORMAT write search results according to FORMAT, where > %a is the complete list of all the printable > metadata available (each member will be > displayed according to the --prop-printf > argument) - use %j for printing one field only > - %f is the file's name, %l is the file name's > length, %m is the file's mime type, %n is the > search result number, %s is the file's size in > bytes and %u is the file's URI; the %a and %j > specifiers optionally support metatype > filtering via hash sign (e.g. `%5#j` prints a > book title, if present - see libextractor's > metatypes for the complete list of numerical > identifiers); if missing, --printf defaults to > `#%n:\ngnunet-download -o '%f' %u\n\n` > -h, --help print this help > -i, --prop-printf=FORMAT when the %a format specifier appears in --printf > or --dir-printf, list each metadata property > according to FORMAT, where %p is the property's > content, %l is the content's length in bytes, > %t is the property type, %i is the property > type's unique identifier, %n is the property > number and %w is the name of the plugin that > provided the information; if missing, > --prop-printf defaults to ` %t: %p\n` > -L, --log=LOGLEVEL configure logging to use LOGLEVEL > -l, --logfile=FILENAME configure logging to write logs to FILENAME > -N, --results=VALUE automatically terminate search after VALUE > results are found > -n, --no-network only search the local peer (no P2P network > search) > -o, --output=FILENAME create a GNUnet directory with search results at > FILENAME (e.g. `gnunet-search > --output=commons.gnd commons`) > -s, --silent silent mode (requires the --output argument) > -t, --timeout=DELAY automatically terminate search after DELAY (in > number of microseconds); if 0 or omitted it > means to wait for CTRL-C > -V, --verbose be verbose > -v, --version print the version number > Report bugs to gnunet-developers@gnu.org. > Home page: http://www.gnu.org/s/gnunet/ > General help using GNU software: http://www.gnu.org/gethelp/ > > What do you think? If it sounds already too hardcore I will go back to the > previous version. But then we will not have any means to print only > specific metatypes… > > Please find the new proposal attached. > > --madmurphy > > On Mon, Feb 7, 2022 at 12:47 PM madmurphy <madmurphy...@gmail.com> wrote: > >> Thank you a lot, Carlo. >> >> Yes, --format (--dir-format) was the original name. Then I saw that the >> tendency favoured --printf (--dir-printf) more and I changed it – but I >> have intentionally left -f (-F) for the short name(s). The new name is >> actually inspired to the -printf argument of find (%s and %f have even >> identical meaning in both find and gnunet-search), but if you guys think >> that --format (--dir-format) is better, then I will change it back. >> >> In the meanwhile, silly me, I had forgotten to actually implement the %s >> specifier for the file size. I did that now (patch attached). I also added >> a --silent argument for when people only want to create a GNUnet >> directory and don't care about the output printed on screen. And finally, I >> tried to expand the help page a bit. Here is the new text: >> >> $ gnunet-search --help >> >> gnunet-search [OPTIONS] KEYWORD >> Search for files that have been published on GNUnet >> Arguments mandatory for long options are also mandatory for short options. >> -a, --anonymity=LEVEL set the desired LEVEL of receiver-anonymity >> -c, --config=FILENAME use configuration file FILENAME >> -F, --dir-printf=FORMAT write search results for directories according >> to >> FORMAT, where %a is the complete list of all >> the printable metadata available (each member >> of which will be displayed according to the >> --prop-printf argument), %f is the directory's >> name, %l is the directory name's length, %m is >> the directory's mime type (always equal to >> `application/gnunet-directory`), %n is the >> search result number, %s is the directory's >> size in bytes and %u is the directory's URI; >> if >> missing, --dir-printf defaults to the --printf >> argument; if the latter is missing too >> --dir-printf defaults to >> `#%n:\ngnunet-download >> -o "%f" -R %u\n\n` >> -f, --printf=FORMAT write search results according to FORMAT, where >> %a is the complete list of all the printable >> metadata available (each member of which will >> be displayed according to the --prop-printf >> argument), %f is the file's name, %l is the >> file name's length, %m is the file's mime >> type, >> %n is the search result number, %s is the >> file's size in bytes and %u is the file's URI; >> if missing, --printf defaults to >> `#%n:\ngnunet-download -o "%f" %u\n\n` >> -h, --help print this help >> -i, --prop-printf=FORMAT when the %a format specifier appears in --printf >> or --dir-printf, list each metadata property >> according to FORMAT, where %p is the >> property's >> content, %l is the content's length in bytes, >> %t is the property type, %i is the property >> type's unique identifier, %n is the property >> number and %w is the name of the plugin that >> provided the information; if missing, >> --prop-printf defaults to `\t%t: %p\n` >> -L, --log=LOGLEVEL configure logging to use LOGLEVEL >> -l, --logfile=FILENAME configure logging to write logs to FILENAME >> -N, --results=VALUE automatically terminate search after VALUE >> results are found >> -n, --no-network only search the local peer (no P2P network >> search) >> -o, --output=FILENAME create a GNUnet directory with search results at >> FILENAME (e.g. `gnunet-search >> --output=commons.gnd commons`) >> -s, --silent silent mode (requires the --output argument) >> -t, --timeout=DELAY automatically terminate search after DELAY (in >> number of microseconds); if 0 or omitted il >> means to wait for CTRL-C >> -V, --verbose be verbose >> -v, --version print the version number >> Report bugs to gnunet-developers@gnu.org. >> Home page: http://www.gnu.org/s/gnunet/ >> General help using GNU software: http://www.gnu.org/gethelp/ >> >> Despite the multiple possibilities that the new features offer, I think >> the most needed one was the simplest one: that of simply launching >> >> gnunet-search -f '%f\n' commons >> >> and print a simple naked list of the files that can be retrieved with the >> commons keyword, without any URI or distractions (if later I want to >> actually download something I will omit the --printf argument, or use >> another format that contains the %u specifier). But the possibilities >> are really many. >> >> There is still room for additions, but there is also no hurry. >> >> --madmurphy >> >> On Mon, Feb 7, 2022 at 12:14 PM carlo von lynX < >> l...@time.to.get.psyced.org> wrote: >> >>> Thank you, madmurphy! I think several of the gnunet >>> CLI tools need improvements of this kind, actually. >>> I vaguely remember doing similar edits somewhere - >>> making outputs friendly to parse. >>> >>> On Sat, Feb 05, 2022 at 08:09:02AM +0000, madmurphy wrote: >>> > 1. What do you think about the fact that I have named the new >>> arguments >>> > --printf, --dir-printf and --prop-printf? Do you think that >>> alternative >>> > names would be better? >>> >>> Since %u %n etc now have a very different meaning from >>> what they mean in regular printf, I would rather just >>> call them --format, --dir-format and --prop-format. >>> >>> > 5. Do you like the idea? >>> >>> Yes. >>> >>> > > -F, --dir-format=DIRFORMAT write search results for directories >>> according to >>> > > -f, --format=FORMAT write search results according to >>> FORMAT, where >>> >>> Oh, you already had it that way. >>> >>> >>>