LibraryOfCongress / bagit-python

Work with BagIt packages from Python.
http://libraryofcongress.github.io/bagit-python
216 stars 85 forks source link

Add support for --wrap option #129

Open mhucka opened 5 years ago

mhucka commented 5 years ago

The previous behavior of bagit.py was asymmetrical with respect to how it treated long tag lines: it would handle folded lines when reading the bag-info.txt file, but it would not fold long lines when writing long tag values into bag-info.txt. This was hardwired into the function _make_tag_file(), which explicitly stripped line endings from tag values before writing them.

Section 2.2.2 of the BagIt spec (https://tools.ietf.org/html/rfc8493) states the following:

It is RECOMMENDED that lines not exceed 79 characters in length. Long values MAY be continued onto the next line by inserting a LF, CR, or CRLF, and then indenting the next line with one or more linear white space characters (spaces or tabs). Except for linebreaks, such padding does not form part of the value.

This PR adds a new command-line option, --wrap, and a new parameter named line_width to the functions make_bag() and save(), to make it possible to follow the recommendation. The default value is 0, which means don't wrap (which is the original behavior). An integer value greater than 0 causes line-wrapping to be performed on a best-effort basis to limit line lengths to the given value.

This addresses issue #126.

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.2%) to 83.303% when pulling 80686e852d11d199502066fb18f7482293fd54a7 on caltechlibrary:wrap-tag-lines into 8a8263e02d4b2bb95de4835e8d49fc70fd964f97 on LibraryOfCongress:master.

coveralls commented 5 years ago

Coverage Status

Coverage decreased (-0.2%) to 83.303% when pulling 80686e852d11d199502066fb18f7482293fd54a7 on caltechlibrary:wrap-tag-lines into 8a8263e02d4b2bb95de4835e8d49fc70fd964f97 on LibraryOfCongress:master.

coveralls commented 5 years ago

Coverage Status

Coverage increased (+0.3%) to 83.848% when pulling ad9a27d2cb9bf39013827d7b41ba4c2152028c9b on caltechlibrary:wrap-tag-lines into 8a8263e02d4b2bb95de4835e8d49fc70fd964f97 on LibraryOfCongress:master.