Gentoo Logo
Gentoo Spaceship




Note: Due to technical difficulties, the Archives are currently not up to date. GMANE provides an alternative service for most mailing lists.
c.f. bug 424647
List Archive: gentoo-portage-dev
Navigation:
Lists: gentoo-portage-dev: < Prev By Thread Next > < Prev By Date Next >
Headers:
To: gentoo-portage-dev@g.o
From: Mike Frysinger <vapier@g.o>
Subject: [RFC/PATCH] repoman: unroll escaped lines so we can check the entirety of it
Date: Thu, 24 May 2012 00:06:39 -0400
Sometimes people wrap long lines in their ebuilds to make it easier to
read, but this causes us issues when doing line-by-line checking.  So
automatically unroll those lines before passing the full content down
to our checkers.

This seems to work, but maybe someone can suggest something simpler.

Signed-off-by: Mike Frysinger <vapier@g.o>
---
 pym/repoman/checks.py |   35 +++++++++++++++++++++++++++++++++++
 1 files changed, 35 insertions(+), 0 deletions(-)

diff --git a/pym/repoman/checks.py b/pym/repoman/checks.py
index 65e7136..67f2b0a 100644
--- a/pym/repoman/checks.py
+++ b/pym/repoman/checks.py
@@ -750,11 +750,46 @@ _ignore_comment_re = re.compile(r'^\s*#')
 def run_checks(contents, pkg):
 	checks = _constant_checks
 	here_doc_delim = None
+	multiline = None
 
 	for lc in checks:
 		lc.new(pkg)
 	for num, line in enumerate(contents):
 
+		# Unroll multiline escaped strings so that we can check things:
+		#		inherit foo bar \
+		#			moo \
+		#			cow
+		# This will merge these lines like so:
+		#		inherit foo bar 	moo 	cow
+		try:
+			# A normal line will end in the two bytes: <\> <\n>.  So decoding
+			# that will result in python thinking the <\n> is being escaped
+			# and eat the single <\> which makes it hard for us to detect.
+			# Instead, strip the newline (which we know all lines have), and
+			# append a <0>.  Then when python escapes it, if the line ended
+			# in a <\>, we'll end up with a <\0> marker to key off of.  This
+			# shouldn't be a problem with any valid ebuild ...
+			line_escaped = (line.rstrip('\n') + '0').decode('string_escape')
+		except:
+			# Who knows what kind of crazy crap an ebuild will have
+			# in it -- don't allow it to kill us.
+			line_escaped = line
+		if multiline:
+			# Chop off the \ and \n bytes from the previous line.
+			multiline = multiline[:-2] + line
+			if not line_escaped.endswith('\0'):
+				line = multiline
+				num = multinum
+				multiline = None
+			else:
+				continue
+		else:
+			if line_escaped.endswith('\0'):
+				multinum = num
+				multiline = line
+				continue
+
 		# Check if we're inside a here-document.
 		if here_doc_delim is not None:
 			if here_doc_delim.match(line):
-- 
1.7.8.6



Replies:
[PATCH v3] repoman: unroll escaped lines so we can check the entirety of it
-- Mike Frysinger
[PATCH v2] repoman: unroll escaped lines so we can check the entirety of it
-- Mike Frysinger
Re: [RFC/PATCH] repoman: unroll escaped lines so we can check the entirety of it
-- Kent Fredric
Re: [RFC/PATCH] repoman: unroll escaped lines so we can check the entirety of it
-- Zac Medico
Navigation:
Lists: gentoo-portage-dev: < Prev By Thread Next > < Prev By Date Next >
Previous by thread:
[PATCH] repoman: add a mini framework for checking eclasses, and fill it out
Next by thread:
Re: [RFC/PATCH] repoman: unroll escaped lines so we can check the entirety of it
Previous by date:
Re: [PATCH] repoman: add a mini framework for checking eclasses, and fill it out
Next by date:
Re: [RFC/PATCH] repoman: unroll escaped lines so we can check the entirety of it


Updated Jun 13, 2012

Summary: Archive of the gentoo-portage-dev mailing list.

Donate to support our development efforts.

Copyright 2001-2013 Gentoo Foundation, Inc. Questions, Comments? Contact us.