From bd21325fcdd13c88b443233d1d55939d6868eadd Mon Sep 17 00:00:00 2001 From: Brad Warren Date: Mon, 18 Jul 2016 18:12:44 -0700 Subject: [PATCH] newline logic --- certbot-nginx/certbot_nginx/parser.py | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/certbot-nginx/certbot_nginx/parser.py b/certbot-nginx/certbot_nginx/parser.py index 5350e04d7..57ea2db56 100644 --- a/certbot-nginx/certbot_nginx/parser.py +++ b/certbot-nginx/certbot_nginx/parser.py @@ -517,10 +517,26 @@ def _add_directives(block, directives, replace): """ for directive in directives: _add_directive(block, directive, replace) - + last = block[-1] + if not (isinstance(last, str) and '\n' in last): + block.append('\n') + REPEATABLE_DIRECTIVES = set(['server_name', 'listen', 'include']) -COMMENT = [" ", "#", " managed by Certbot"] +COMMENT_STR = ' managed by Certbot' +COMMENT = [' ', '#', ' managed by Certbot'] + + +def _comment_directive(block, location): + """Add a comment to the end of the line at location.""" + block.insert(location + 1, COMMENT[:]) + + if len(block) > location + 2: # there is a block after us + next_entry = block[location + 2] + if isinstance(next_entry, list): + next_entry = next_entry.spaced[0] + if "\n" not in next_entry: + block.insert(location + 2, '\n') def _add_directive(block, directive, replace):