public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/quotes/
@ 2017-07-15  2:08 Brian Dolbec
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Dolbec @ 2017-07-15  2:08 UTC (permalink / raw
  To: gentoo-commits

commit:     8ce89cc3bd32e5f8b8b03464e109f2c484c73a10
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 01:04:31 2017 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Jul 15 02:08:28 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=8ce89cc3

repoman: New linechecks module, quotes

 .../repoman/modules/linechecks/quotes/__init__.py  | 27 +++++++
 .../repoman/modules/linechecks/quotes/quoteda.py   | 16 ++++
 .../repoman/modules/linechecks/quotes/quotes.py    | 86 ++++++++++++++++++++++
 3 files changed, 129 insertions(+)

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/__init__.py b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
new file mode 100644
index 000000000..6043ab20c
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Nested plug-in module for repoman LineChecks.
+Performs nested subshell checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+	'name': 'do',
+	'description': doc,
+	'provides':{
+		'quote-check': {
+			'name': "quote",
+			'sourcefile': "quotes",
+			'class': "EbuildQuote",
+			'description': doc,
+		},
+		'quoteda-check': {
+			'name': "quoteda",
+			'sourcefile': "quoteda",
+			'class': "EbuildQuotedA",
+			'description': doc,
+		},
+	}
+}
+

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
new file mode 100644
index 000000000..7fd9ba797
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
@@ -0,0 +1,16 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuotedA(LineCheck):
+	"""Ensure ebuilds have no quoting around ${A}"""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	a_quoted = re.compile(r'.*\"\$(\{A\}|A)\"')
+
+	def check(self, num, line):
+		match = self.a_quoted.match(line)
+		if match:
+			return "Quoted \"${A}\" on line: %d"

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quotes.py b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
new file mode 100644
index 000000000..68c594e23
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
@@ -0,0 +1,86 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuote(LineCheck):
+	"""Ensure ebuilds have valid quoting around things like D,FILESDIR, etc..."""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	_message_commands = [
+		"die", "echo", "eerror", "einfo", "elog", "eqawarn", "ewarn"]
+	_message_re = re.compile(
+		r'\s(' + "|".join(_message_commands) + r')\s+"[^"]*"\s*$')
+	_ignored_commands = ["local", "export"] + _message_commands
+	ignore_line = re.compile(
+		r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' +
+		r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
+	ignore_comment = False
+	var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
+
+	# EAPI=3/Prefix vars
+	var_names += ["ED", "EPREFIX", "EROOT"]
+
+	# variables for games.eclass
+	var_names += [
+		"Ddir", "GAMES_PREFIX_OPT", "GAMES_DATADIR",
+		"GAMES_DATADIR_BASE", "GAMES_SYSCONFDIR", "GAMES_STATEDIR",
+		"GAMES_LOGDIR", "GAMES_BINDIR"]
+
+	# variables for multibuild.eclass
+	var_names += ["BUILD_DIR"]
+
+	var_names = "(%s)" % "|".join(var_names)
+	var_reference = re.compile(
+		r'\$(\{%s\}|%s\W)' % (var_names, var_names))
+	missing_quotes = re.compile(
+		r'(\s|^)[^"\'\s]*\$\{?%s\}?[^"\'\s]*(\s|$)' % var_names)
+	cond_begin = re.compile(r'(^|\s+)\[\[($|\\$|\s+)')
+	cond_end = re.compile(r'(^|\s+)\]\]($|\\$|\s+)')
+
+	def check(self, num, line):
+		if self.var_reference.search(line) is None:
+			return
+		# There can be multiple matches / violations on a single line. We
+		# have to make sure none of the matches are violators. Once we've
+		# found one violator, any remaining matches on the same line can
+		# be ignored.
+		pos = 0
+		while pos <= len(line) - 1:
+			missing_quotes = self.missing_quotes.search(line, pos)
+			if not missing_quotes:
+				break
+			# If the last character of the previous match is a whitespace
+			# character, that character may be needed for the next
+			# missing_quotes match, so search overlaps by 1 character.
+			group = missing_quotes.group()
+			pos = missing_quotes.end() - 1
+
+			# Filter out some false positives that can
+			# get through the missing_quotes regex.
+			if self.var_reference.search(group) is None:
+				continue
+
+			# Filter matches that appear to be an
+			# argument to a message command.
+			# For example: false || ewarn "foo $WORKDIR/bar baz"
+			message_match = self._message_re.search(line)
+			if message_match is not None and \
+				message_match.start() < pos and \
+				message_match.end() > pos:
+				break
+
+			# This is an attempt to avoid false positives without getting
+			# too complex, while possibly allowing some (hopefully
+			# unlikely) violations to slip through. We just assume
+			# everything is correct if the there is a ' [[ ' or a ' ]] '
+			# anywhere in the whole line (possibly continued over one
+			# line).
+			if self.cond_begin.search(line) is not None:
+				continue
+			if self.cond_end.search(line) is not None:
+				continue
+
+			# Any remaining matches on the same line can be ignored.
+			return self.errors['MISSING_QUOTES_ERROR']


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/quotes/
@ 2017-07-15  2:29 Brian Dolbec
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Dolbec @ 2017-07-15  2:29 UTC (permalink / raw
  To: gentoo-commits

commit:     7802d8ede8fe099334e62ad5f1be776d184ae9e8
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 01:04:31 2017 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Jul 15 02:25:45 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=7802d8ed

repoman: New linechecks module, quotes

 .../repoman/modules/linechecks/quotes/__init__.py  | 27 +++++++
 .../repoman/modules/linechecks/quotes/quoteda.py   | 16 ++++
 .../repoman/modules/linechecks/quotes/quotes.py    | 86 ++++++++++++++++++++++
 3 files changed, 129 insertions(+)

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/__init__.py b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
new file mode 100644
index 000000000..6043ab20c
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Nested plug-in module for repoman LineChecks.
+Performs nested subshell checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+	'name': 'do',
+	'description': doc,
+	'provides':{
+		'quote-check': {
+			'name': "quote",
+			'sourcefile': "quotes",
+			'class': "EbuildQuote",
+			'description': doc,
+		},
+		'quoteda-check': {
+			'name': "quoteda",
+			'sourcefile': "quoteda",
+			'class': "EbuildQuotedA",
+			'description': doc,
+		},
+	}
+}
+

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
new file mode 100644
index 000000000..7fd9ba797
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
@@ -0,0 +1,16 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuotedA(LineCheck):
+	"""Ensure ebuilds have no quoting around ${A}"""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	a_quoted = re.compile(r'.*\"\$(\{A\}|A)\"')
+
+	def check(self, num, line):
+		match = self.a_quoted.match(line)
+		if match:
+			return "Quoted \"${A}\" on line: %d"

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quotes.py b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
new file mode 100644
index 000000000..68c594e23
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
@@ -0,0 +1,86 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuote(LineCheck):
+	"""Ensure ebuilds have valid quoting around things like D,FILESDIR, etc..."""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	_message_commands = [
+		"die", "echo", "eerror", "einfo", "elog", "eqawarn", "ewarn"]
+	_message_re = re.compile(
+		r'\s(' + "|".join(_message_commands) + r')\s+"[^"]*"\s*$')
+	_ignored_commands = ["local", "export"] + _message_commands
+	ignore_line = re.compile(
+		r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' +
+		r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
+	ignore_comment = False
+	var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
+
+	# EAPI=3/Prefix vars
+	var_names += ["ED", "EPREFIX", "EROOT"]
+
+	# variables for games.eclass
+	var_names += [
+		"Ddir", "GAMES_PREFIX_OPT", "GAMES_DATADIR",
+		"GAMES_DATADIR_BASE", "GAMES_SYSCONFDIR", "GAMES_STATEDIR",
+		"GAMES_LOGDIR", "GAMES_BINDIR"]
+
+	# variables for multibuild.eclass
+	var_names += ["BUILD_DIR"]
+
+	var_names = "(%s)" % "|".join(var_names)
+	var_reference = re.compile(
+		r'\$(\{%s\}|%s\W)' % (var_names, var_names))
+	missing_quotes = re.compile(
+		r'(\s|^)[^"\'\s]*\$\{?%s\}?[^"\'\s]*(\s|$)' % var_names)
+	cond_begin = re.compile(r'(^|\s+)\[\[($|\\$|\s+)')
+	cond_end = re.compile(r'(^|\s+)\]\]($|\\$|\s+)')
+
+	def check(self, num, line):
+		if self.var_reference.search(line) is None:
+			return
+		# There can be multiple matches / violations on a single line. We
+		# have to make sure none of the matches are violators. Once we've
+		# found one violator, any remaining matches on the same line can
+		# be ignored.
+		pos = 0
+		while pos <= len(line) - 1:
+			missing_quotes = self.missing_quotes.search(line, pos)
+			if not missing_quotes:
+				break
+			# If the last character of the previous match is a whitespace
+			# character, that character may be needed for the next
+			# missing_quotes match, so search overlaps by 1 character.
+			group = missing_quotes.group()
+			pos = missing_quotes.end() - 1
+
+			# Filter out some false positives that can
+			# get through the missing_quotes regex.
+			if self.var_reference.search(group) is None:
+				continue
+
+			# Filter matches that appear to be an
+			# argument to a message command.
+			# For example: false || ewarn "foo $WORKDIR/bar baz"
+			message_match = self._message_re.search(line)
+			if message_match is not None and \
+				message_match.start() < pos and \
+				message_match.end() > pos:
+				break
+
+			# This is an attempt to avoid false positives without getting
+			# too complex, while possibly allowing some (hopefully
+			# unlikely) violations to slip through. We just assume
+			# everything is correct if the there is a ' [[ ' or a ' ]] '
+			# anywhere in the whole line (possibly continued over one
+			# line).
+			if self.cond_begin.search(line) is not None:
+				continue
+			if self.cond_end.search(line) is not None:
+				continue
+
+			# Any remaining matches on the same line can be ignored.
+			return self.errors['MISSING_QUOTES_ERROR']


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/quotes/
@ 2017-09-11 21:43 Brian Dolbec
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Dolbec @ 2017-09-11 21:43 UTC (permalink / raw
  To: gentoo-commits

commit:     2f8ec909aac9fffc14c15499ed3394bd6445621c
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 01:04:31 2017 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Mon Sep 11 16:13:15 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=2f8ec909

repoman: New linechecks module, quotes

 .../repoman/modules/linechecks/quotes/__init__.py  | 27 +++++++
 .../repoman/modules/linechecks/quotes/quoteda.py   | 16 ++++
 .../repoman/modules/linechecks/quotes/quotes.py    | 86 ++++++++++++++++++++++
 3 files changed, 129 insertions(+)

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/__init__.py b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
new file mode 100644
index 000000000..6043ab20c
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Nested plug-in module for repoman LineChecks.
+Performs nested subshell checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+	'name': 'do',
+	'description': doc,
+	'provides':{
+		'quote-check': {
+			'name': "quote",
+			'sourcefile': "quotes",
+			'class': "EbuildQuote",
+			'description': doc,
+		},
+		'quoteda-check': {
+			'name': "quoteda",
+			'sourcefile': "quoteda",
+			'class': "EbuildQuotedA",
+			'description': doc,
+		},
+	}
+}
+

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
new file mode 100644
index 000000000..7fd9ba797
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
@@ -0,0 +1,16 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuotedA(LineCheck):
+	"""Ensure ebuilds have no quoting around ${A}"""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	a_quoted = re.compile(r'.*\"\$(\{A\}|A)\"')
+
+	def check(self, num, line):
+		match = self.a_quoted.match(line)
+		if match:
+			return "Quoted \"${A}\" on line: %d"

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quotes.py b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
new file mode 100644
index 000000000..68c594e23
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
@@ -0,0 +1,86 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuote(LineCheck):
+	"""Ensure ebuilds have valid quoting around things like D,FILESDIR, etc..."""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	_message_commands = [
+		"die", "echo", "eerror", "einfo", "elog", "eqawarn", "ewarn"]
+	_message_re = re.compile(
+		r'\s(' + "|".join(_message_commands) + r')\s+"[^"]*"\s*$')
+	_ignored_commands = ["local", "export"] + _message_commands
+	ignore_line = re.compile(
+		r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' +
+		r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
+	ignore_comment = False
+	var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
+
+	# EAPI=3/Prefix vars
+	var_names += ["ED", "EPREFIX", "EROOT"]
+
+	# variables for games.eclass
+	var_names += [
+		"Ddir", "GAMES_PREFIX_OPT", "GAMES_DATADIR",
+		"GAMES_DATADIR_BASE", "GAMES_SYSCONFDIR", "GAMES_STATEDIR",
+		"GAMES_LOGDIR", "GAMES_BINDIR"]
+
+	# variables for multibuild.eclass
+	var_names += ["BUILD_DIR"]
+
+	var_names = "(%s)" % "|".join(var_names)
+	var_reference = re.compile(
+		r'\$(\{%s\}|%s\W)' % (var_names, var_names))
+	missing_quotes = re.compile(
+		r'(\s|^)[^"\'\s]*\$\{?%s\}?[^"\'\s]*(\s|$)' % var_names)
+	cond_begin = re.compile(r'(^|\s+)\[\[($|\\$|\s+)')
+	cond_end = re.compile(r'(^|\s+)\]\]($|\\$|\s+)')
+
+	def check(self, num, line):
+		if self.var_reference.search(line) is None:
+			return
+		# There can be multiple matches / violations on a single line. We
+		# have to make sure none of the matches are violators. Once we've
+		# found one violator, any remaining matches on the same line can
+		# be ignored.
+		pos = 0
+		while pos <= len(line) - 1:
+			missing_quotes = self.missing_quotes.search(line, pos)
+			if not missing_quotes:
+				break
+			# If the last character of the previous match is a whitespace
+			# character, that character may be needed for the next
+			# missing_quotes match, so search overlaps by 1 character.
+			group = missing_quotes.group()
+			pos = missing_quotes.end() - 1
+
+			# Filter out some false positives that can
+			# get through the missing_quotes regex.
+			if self.var_reference.search(group) is None:
+				continue
+
+			# Filter matches that appear to be an
+			# argument to a message command.
+			# For example: false || ewarn "foo $WORKDIR/bar baz"
+			message_match = self._message_re.search(line)
+			if message_match is not None and \
+				message_match.start() < pos and \
+				message_match.end() > pos:
+				break
+
+			# This is an attempt to avoid false positives without getting
+			# too complex, while possibly allowing some (hopefully
+			# unlikely) violations to slip through. We just assume
+			# everything is correct if the there is a ' [[ ' or a ' ]] '
+			# anywhere in the whole line (possibly continued over one
+			# line).
+			if self.cond_begin.search(line) is not None:
+				continue
+			if self.cond_end.search(line) is not None:
+				continue
+
+			# Any remaining matches on the same line can be ignored.
+			return self.errors['MISSING_QUOTES_ERROR']


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/quotes/
@ 2017-11-26 17:46 Brian Dolbec
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Dolbec @ 2017-11-26 17:46 UTC (permalink / raw
  To: gentoo-commits

commit:     93847cf38f2e31d48809eaef7ad63fe6c565bec7
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 01:04:31 2017 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sun Nov 26 17:32:19 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=93847cf3

repoman: New linechecks module, quotes

 .../repoman/modules/linechecks/quotes/__init__.py  | 27 +++++++
 .../repoman/modules/linechecks/quotes/quoteda.py   | 16 ++++
 .../repoman/modules/linechecks/quotes/quotes.py    | 86 ++++++++++++++++++++++
 3 files changed, 129 insertions(+)

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/__init__.py b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
new file mode 100644
index 000000000..6043ab20c
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Nested plug-in module for repoman LineChecks.
+Performs nested subshell checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+	'name': 'do',
+	'description': doc,
+	'provides':{
+		'quote-check': {
+			'name': "quote",
+			'sourcefile': "quotes",
+			'class': "EbuildQuote",
+			'description': doc,
+		},
+		'quoteda-check': {
+			'name': "quoteda",
+			'sourcefile': "quoteda",
+			'class': "EbuildQuotedA",
+			'description': doc,
+		},
+	}
+}
+

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
new file mode 100644
index 000000000..7fd9ba797
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
@@ -0,0 +1,16 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuotedA(LineCheck):
+	"""Ensure ebuilds have no quoting around ${A}"""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	a_quoted = re.compile(r'.*\"\$(\{A\}|A)\"')
+
+	def check(self, num, line):
+		match = self.a_quoted.match(line)
+		if match:
+			return "Quoted \"${A}\" on line: %d"

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quotes.py b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
new file mode 100644
index 000000000..68c594e23
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
@@ -0,0 +1,86 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuote(LineCheck):
+	"""Ensure ebuilds have valid quoting around things like D,FILESDIR, etc..."""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	_message_commands = [
+		"die", "echo", "eerror", "einfo", "elog", "eqawarn", "ewarn"]
+	_message_re = re.compile(
+		r'\s(' + "|".join(_message_commands) + r')\s+"[^"]*"\s*$')
+	_ignored_commands = ["local", "export"] + _message_commands
+	ignore_line = re.compile(
+		r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' +
+		r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
+	ignore_comment = False
+	var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
+
+	# EAPI=3/Prefix vars
+	var_names += ["ED", "EPREFIX", "EROOT"]
+
+	# variables for games.eclass
+	var_names += [
+		"Ddir", "GAMES_PREFIX_OPT", "GAMES_DATADIR",
+		"GAMES_DATADIR_BASE", "GAMES_SYSCONFDIR", "GAMES_STATEDIR",
+		"GAMES_LOGDIR", "GAMES_BINDIR"]
+
+	# variables for multibuild.eclass
+	var_names += ["BUILD_DIR"]
+
+	var_names = "(%s)" % "|".join(var_names)
+	var_reference = re.compile(
+		r'\$(\{%s\}|%s\W)' % (var_names, var_names))
+	missing_quotes = re.compile(
+		r'(\s|^)[^"\'\s]*\$\{?%s\}?[^"\'\s]*(\s|$)' % var_names)
+	cond_begin = re.compile(r'(^|\s+)\[\[($|\\$|\s+)')
+	cond_end = re.compile(r'(^|\s+)\]\]($|\\$|\s+)')
+
+	def check(self, num, line):
+		if self.var_reference.search(line) is None:
+			return
+		# There can be multiple matches / violations on a single line. We
+		# have to make sure none of the matches are violators. Once we've
+		# found one violator, any remaining matches on the same line can
+		# be ignored.
+		pos = 0
+		while pos <= len(line) - 1:
+			missing_quotes = self.missing_quotes.search(line, pos)
+			if not missing_quotes:
+				break
+			# If the last character of the previous match is a whitespace
+			# character, that character may be needed for the next
+			# missing_quotes match, so search overlaps by 1 character.
+			group = missing_quotes.group()
+			pos = missing_quotes.end() - 1
+
+			# Filter out some false positives that can
+			# get through the missing_quotes regex.
+			if self.var_reference.search(group) is None:
+				continue
+
+			# Filter matches that appear to be an
+			# argument to a message command.
+			# For example: false || ewarn "foo $WORKDIR/bar baz"
+			message_match = self._message_re.search(line)
+			if message_match is not None and \
+				message_match.start() < pos and \
+				message_match.end() > pos:
+				break
+
+			# This is an attempt to avoid false positives without getting
+			# too complex, while possibly allowing some (hopefully
+			# unlikely) violations to slip through. We just assume
+			# everything is correct if the there is a ' [[ ' or a ' ]] '
+			# anywhere in the whole line (possibly continued over one
+			# line).
+			if self.cond_begin.search(line) is not None:
+				continue
+			if self.cond_end.search(line) is not None:
+				continue
+
+			# Any remaining matches on the same line can be ignored.
+			return self.errors['MISSING_QUOTES_ERROR']


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/quotes/
@ 2017-12-05 18:32 Brian Dolbec
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Dolbec @ 2017-12-05 18:32 UTC (permalink / raw
  To: gentoo-commits

commit:     3912a7c5b5852bb5011e677e536f9fe9e5440bd6
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 01:04:31 2017 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue Dec  5 18:24:49 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3912a7c5

repoman: New linechecks module, quotes

 .../repoman/modules/linechecks/quotes/__init__.py  | 27 +++++++
 .../repoman/modules/linechecks/quotes/quoteda.py   | 16 ++++
 .../repoman/modules/linechecks/quotes/quotes.py    | 86 ++++++++++++++++++++++
 3 files changed, 129 insertions(+)

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/__init__.py b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
new file mode 100644
index 000000000..6043ab20c
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Nested plug-in module for repoman LineChecks.
+Performs nested subshell checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+	'name': 'do',
+	'description': doc,
+	'provides':{
+		'quote-check': {
+			'name': "quote",
+			'sourcefile': "quotes",
+			'class': "EbuildQuote",
+			'description': doc,
+		},
+		'quoteda-check': {
+			'name': "quoteda",
+			'sourcefile': "quoteda",
+			'class': "EbuildQuotedA",
+			'description': doc,
+		},
+	}
+}
+

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
new file mode 100644
index 000000000..7fd9ba797
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
@@ -0,0 +1,16 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuotedA(LineCheck):
+	"""Ensure ebuilds have no quoting around ${A}"""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	a_quoted = re.compile(r'.*\"\$(\{A\}|A)\"')
+
+	def check(self, num, line):
+		match = self.a_quoted.match(line)
+		if match:
+			return "Quoted \"${A}\" on line: %d"

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quotes.py b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
new file mode 100644
index 000000000..68c594e23
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
@@ -0,0 +1,86 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuote(LineCheck):
+	"""Ensure ebuilds have valid quoting around things like D,FILESDIR, etc..."""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	_message_commands = [
+		"die", "echo", "eerror", "einfo", "elog", "eqawarn", "ewarn"]
+	_message_re = re.compile(
+		r'\s(' + "|".join(_message_commands) + r')\s+"[^"]*"\s*$')
+	_ignored_commands = ["local", "export"] + _message_commands
+	ignore_line = re.compile(
+		r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' +
+		r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
+	ignore_comment = False
+	var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
+
+	# EAPI=3/Prefix vars
+	var_names += ["ED", "EPREFIX", "EROOT"]
+
+	# variables for games.eclass
+	var_names += [
+		"Ddir", "GAMES_PREFIX_OPT", "GAMES_DATADIR",
+		"GAMES_DATADIR_BASE", "GAMES_SYSCONFDIR", "GAMES_STATEDIR",
+		"GAMES_LOGDIR", "GAMES_BINDIR"]
+
+	# variables for multibuild.eclass
+	var_names += ["BUILD_DIR"]
+
+	var_names = "(%s)" % "|".join(var_names)
+	var_reference = re.compile(
+		r'\$(\{%s\}|%s\W)' % (var_names, var_names))
+	missing_quotes = re.compile(
+		r'(\s|^)[^"\'\s]*\$\{?%s\}?[^"\'\s]*(\s|$)' % var_names)
+	cond_begin = re.compile(r'(^|\s+)\[\[($|\\$|\s+)')
+	cond_end = re.compile(r'(^|\s+)\]\]($|\\$|\s+)')
+
+	def check(self, num, line):
+		if self.var_reference.search(line) is None:
+			return
+		# There can be multiple matches / violations on a single line. We
+		# have to make sure none of the matches are violators. Once we've
+		# found one violator, any remaining matches on the same line can
+		# be ignored.
+		pos = 0
+		while pos <= len(line) - 1:
+			missing_quotes = self.missing_quotes.search(line, pos)
+			if not missing_quotes:
+				break
+			# If the last character of the previous match is a whitespace
+			# character, that character may be needed for the next
+			# missing_quotes match, so search overlaps by 1 character.
+			group = missing_quotes.group()
+			pos = missing_quotes.end() - 1
+
+			# Filter out some false positives that can
+			# get through the missing_quotes regex.
+			if self.var_reference.search(group) is None:
+				continue
+
+			# Filter matches that appear to be an
+			# argument to a message command.
+			# For example: false || ewarn "foo $WORKDIR/bar baz"
+			message_match = self._message_re.search(line)
+			if message_match is not None and \
+				message_match.start() < pos and \
+				message_match.end() > pos:
+				break
+
+			# This is an attempt to avoid false positives without getting
+			# too complex, while possibly allowing some (hopefully
+			# unlikely) violations to slip through. We just assume
+			# everything is correct if the there is a ' [[ ' or a ' ]] '
+			# anywhere in the whole line (possibly continued over one
+			# line).
+			if self.cond_begin.search(line) is not None:
+				continue
+			if self.cond_end.search(line) is not None:
+				continue
+
+			# Any remaining matches on the same line can be ignored.
+			return self.errors['MISSING_QUOTES_ERROR']


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/quotes/
@ 2017-12-06  0:16 Brian Dolbec
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Dolbec @ 2017-12-06  0:16 UTC (permalink / raw
  To: gentoo-commits

commit:     7eed84f7c4c01b85583681c6d2c895739f6f41af
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 01:04:31 2017 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Wed Dec  6 00:13:27 2017 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=7eed84f7

repoman: New linechecks module, quotes

 .../repoman/modules/linechecks/quotes/__init__.py  | 27 +++++++
 .../repoman/modules/linechecks/quotes/quoteda.py   | 16 ++++
 .../repoman/modules/linechecks/quotes/quotes.py    | 86 ++++++++++++++++++++++
 3 files changed, 129 insertions(+)

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/__init__.py b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
new file mode 100644
index 000000000..6043ab20c
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Nested plug-in module for repoman LineChecks.
+Performs nested subshell checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+	'name': 'do',
+	'description': doc,
+	'provides':{
+		'quote-check': {
+			'name': "quote",
+			'sourcefile': "quotes",
+			'class': "EbuildQuote",
+			'description': doc,
+		},
+		'quoteda-check': {
+			'name': "quoteda",
+			'sourcefile': "quoteda",
+			'class': "EbuildQuotedA",
+			'description': doc,
+		},
+	}
+}
+

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
new file mode 100644
index 000000000..7fd9ba797
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
@@ -0,0 +1,16 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuotedA(LineCheck):
+	"""Ensure ebuilds have no quoting around ${A}"""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	a_quoted = re.compile(r'.*\"\$(\{A\}|A)\"')
+
+	def check(self, num, line):
+		match = self.a_quoted.match(line)
+		if match:
+			return "Quoted \"${A}\" on line: %d"

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quotes.py b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
new file mode 100644
index 000000000..68c594e23
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
@@ -0,0 +1,86 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuote(LineCheck):
+	"""Ensure ebuilds have valid quoting around things like D,FILESDIR, etc..."""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	_message_commands = [
+		"die", "echo", "eerror", "einfo", "elog", "eqawarn", "ewarn"]
+	_message_re = re.compile(
+		r'\s(' + "|".join(_message_commands) + r')\s+"[^"]*"\s*$')
+	_ignored_commands = ["local", "export"] + _message_commands
+	ignore_line = re.compile(
+		r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' +
+		r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
+	ignore_comment = False
+	var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
+
+	# EAPI=3/Prefix vars
+	var_names += ["ED", "EPREFIX", "EROOT"]
+
+	# variables for games.eclass
+	var_names += [
+		"Ddir", "GAMES_PREFIX_OPT", "GAMES_DATADIR",
+		"GAMES_DATADIR_BASE", "GAMES_SYSCONFDIR", "GAMES_STATEDIR",
+		"GAMES_LOGDIR", "GAMES_BINDIR"]
+
+	# variables for multibuild.eclass
+	var_names += ["BUILD_DIR"]
+
+	var_names = "(%s)" % "|".join(var_names)
+	var_reference = re.compile(
+		r'\$(\{%s\}|%s\W)' % (var_names, var_names))
+	missing_quotes = re.compile(
+		r'(\s|^)[^"\'\s]*\$\{?%s\}?[^"\'\s]*(\s|$)' % var_names)
+	cond_begin = re.compile(r'(^|\s+)\[\[($|\\$|\s+)')
+	cond_end = re.compile(r'(^|\s+)\]\]($|\\$|\s+)')
+
+	def check(self, num, line):
+		if self.var_reference.search(line) is None:
+			return
+		# There can be multiple matches / violations on a single line. We
+		# have to make sure none of the matches are violators. Once we've
+		# found one violator, any remaining matches on the same line can
+		# be ignored.
+		pos = 0
+		while pos <= len(line) - 1:
+			missing_quotes = self.missing_quotes.search(line, pos)
+			if not missing_quotes:
+				break
+			# If the last character of the previous match is a whitespace
+			# character, that character may be needed for the next
+			# missing_quotes match, so search overlaps by 1 character.
+			group = missing_quotes.group()
+			pos = missing_quotes.end() - 1
+
+			# Filter out some false positives that can
+			# get through the missing_quotes regex.
+			if self.var_reference.search(group) is None:
+				continue
+
+			# Filter matches that appear to be an
+			# argument to a message command.
+			# For example: false || ewarn "foo $WORKDIR/bar baz"
+			message_match = self._message_re.search(line)
+			if message_match is not None and \
+				message_match.start() < pos and \
+				message_match.end() > pos:
+				break
+
+			# This is an attempt to avoid false positives without getting
+			# too complex, while possibly allowing some (hopefully
+			# unlikely) violations to slip through. We just assume
+			# everything is correct if the there is a ' [[ ' or a ' ]] '
+			# anywhere in the whole line (possibly continued over one
+			# line).
+			if self.cond_begin.search(line) is not None:
+				continue
+			if self.cond_end.search(line) is not None:
+				continue
+
+			# Any remaining matches on the same line can be ignored.
+			return self.errors['MISSING_QUOTES_ERROR']


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/quotes/
@ 2018-03-29 21:35 Brian Dolbec
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Dolbec @ 2018-03-29 21:35 UTC (permalink / raw
  To: gentoo-commits

commit:     0e5a3c428e629d9784ad147ecc0dddea1acad96d
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 01:04:31 2017 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Mar 29 20:43:39 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=0e5a3c42

repoman: New linechecks module, quotes

 .../repoman/modules/linechecks/quotes/__init__.py  | 27 +++++++
 .../repoman/modules/linechecks/quotes/quoteda.py   | 16 ++++
 .../repoman/modules/linechecks/quotes/quotes.py    | 86 ++++++++++++++++++++++
 3 files changed, 129 insertions(+)

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/__init__.py b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
new file mode 100644
index 000000000..6043ab20c
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Nested plug-in module for repoman LineChecks.
+Performs nested subshell checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+	'name': 'do',
+	'description': doc,
+	'provides':{
+		'quote-check': {
+			'name': "quote",
+			'sourcefile': "quotes",
+			'class': "EbuildQuote",
+			'description': doc,
+		},
+		'quoteda-check': {
+			'name': "quoteda",
+			'sourcefile': "quoteda",
+			'class': "EbuildQuotedA",
+			'description': doc,
+		},
+	}
+}
+

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
new file mode 100644
index 000000000..7fd9ba797
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
@@ -0,0 +1,16 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuotedA(LineCheck):
+	"""Ensure ebuilds have no quoting around ${A}"""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	a_quoted = re.compile(r'.*\"\$(\{A\}|A)\"')
+
+	def check(self, num, line):
+		match = self.a_quoted.match(line)
+		if match:
+			return "Quoted \"${A}\" on line: %d"

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quotes.py b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
new file mode 100644
index 000000000..68c594e23
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
@@ -0,0 +1,86 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuote(LineCheck):
+	"""Ensure ebuilds have valid quoting around things like D,FILESDIR, etc..."""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	_message_commands = [
+		"die", "echo", "eerror", "einfo", "elog", "eqawarn", "ewarn"]
+	_message_re = re.compile(
+		r'\s(' + "|".join(_message_commands) + r')\s+"[^"]*"\s*$')
+	_ignored_commands = ["local", "export"] + _message_commands
+	ignore_line = re.compile(
+		r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' +
+		r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
+	ignore_comment = False
+	var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
+
+	# EAPI=3/Prefix vars
+	var_names += ["ED", "EPREFIX", "EROOT"]
+
+	# variables for games.eclass
+	var_names += [
+		"Ddir", "GAMES_PREFIX_OPT", "GAMES_DATADIR",
+		"GAMES_DATADIR_BASE", "GAMES_SYSCONFDIR", "GAMES_STATEDIR",
+		"GAMES_LOGDIR", "GAMES_BINDIR"]
+
+	# variables for multibuild.eclass
+	var_names += ["BUILD_DIR"]
+
+	var_names = "(%s)" % "|".join(var_names)
+	var_reference = re.compile(
+		r'\$(\{%s\}|%s\W)' % (var_names, var_names))
+	missing_quotes = re.compile(
+		r'(\s|^)[^"\'\s]*\$\{?%s\}?[^"\'\s]*(\s|$)' % var_names)
+	cond_begin = re.compile(r'(^|\s+)\[\[($|\\$|\s+)')
+	cond_end = re.compile(r'(^|\s+)\]\]($|\\$|\s+)')
+
+	def check(self, num, line):
+		if self.var_reference.search(line) is None:
+			return
+		# There can be multiple matches / violations on a single line. We
+		# have to make sure none of the matches are violators. Once we've
+		# found one violator, any remaining matches on the same line can
+		# be ignored.
+		pos = 0
+		while pos <= len(line) - 1:
+			missing_quotes = self.missing_quotes.search(line, pos)
+			if not missing_quotes:
+				break
+			# If the last character of the previous match is a whitespace
+			# character, that character may be needed for the next
+			# missing_quotes match, so search overlaps by 1 character.
+			group = missing_quotes.group()
+			pos = missing_quotes.end() - 1
+
+			# Filter out some false positives that can
+			# get through the missing_quotes regex.
+			if self.var_reference.search(group) is None:
+				continue
+
+			# Filter matches that appear to be an
+			# argument to a message command.
+			# For example: false || ewarn "foo $WORKDIR/bar baz"
+			message_match = self._message_re.search(line)
+			if message_match is not None and \
+				message_match.start() < pos and \
+				message_match.end() > pos:
+				break
+
+			# This is an attempt to avoid false positives without getting
+			# too complex, while possibly allowing some (hopefully
+			# unlikely) violations to slip through. We just assume
+			# everything is correct if the there is a ' [[ ' or a ' ]] '
+			# anywhere in the whole line (possibly continued over one
+			# line).
+			if self.cond_begin.search(line) is not None:
+				continue
+			if self.cond_end.search(line) is not None:
+				continue
+
+			# Any remaining matches on the same line can be ignored.
+			return self.errors['MISSING_QUOTES_ERROR']


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/quotes/
@ 2018-03-30  0:48 Brian Dolbec
  0 siblings, 0 replies; 9+ messages in thread
From: Brian Dolbec @ 2018-03-30  0:48 UTC (permalink / raw
  To: gentoo-commits

commit:     4d375cd6318dd5cc16853c931acf33e3e92a794c
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 01:04:31 2017 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Fri Mar 30 00:43:45 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=4d375cd6

repoman: New linechecks module, quotes

 .../repoman/modules/linechecks/quotes/__init__.py  | 27 +++++++
 .../repoman/modules/linechecks/quotes/quoteda.py   | 16 ++++
 .../repoman/modules/linechecks/quotes/quotes.py    | 86 ++++++++++++++++++++++
 3 files changed, 129 insertions(+)

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/__init__.py b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
new file mode 100644
index 000000000..6043ab20c
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Nested plug-in module for repoman LineChecks.
+Performs nested subshell checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+	'name': 'do',
+	'description': doc,
+	'provides':{
+		'quote-check': {
+			'name': "quote",
+			'sourcefile': "quotes",
+			'class': "EbuildQuote",
+			'description': doc,
+		},
+		'quoteda-check': {
+			'name': "quoteda",
+			'sourcefile': "quoteda",
+			'class': "EbuildQuotedA",
+			'description': doc,
+		},
+	}
+}
+

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
new file mode 100644
index 000000000..7fd9ba797
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
@@ -0,0 +1,16 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuotedA(LineCheck):
+	"""Ensure ebuilds have no quoting around ${A}"""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	a_quoted = re.compile(r'.*\"\$(\{A\}|A)\"')
+
+	def check(self, num, line):
+		match = self.a_quoted.match(line)
+		if match:
+			return "Quoted \"${A}\" on line: %d"

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quotes.py b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
new file mode 100644
index 000000000..68c594e23
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
@@ -0,0 +1,86 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuote(LineCheck):
+	"""Ensure ebuilds have valid quoting around things like D,FILESDIR, etc..."""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	_message_commands = [
+		"die", "echo", "eerror", "einfo", "elog", "eqawarn", "ewarn"]
+	_message_re = re.compile(
+		r'\s(' + "|".join(_message_commands) + r')\s+"[^"]*"\s*$')
+	_ignored_commands = ["local", "export"] + _message_commands
+	ignore_line = re.compile(
+		r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' +
+		r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
+	ignore_comment = False
+	var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
+
+	# EAPI=3/Prefix vars
+	var_names += ["ED", "EPREFIX", "EROOT"]
+
+	# variables for games.eclass
+	var_names += [
+		"Ddir", "GAMES_PREFIX_OPT", "GAMES_DATADIR",
+		"GAMES_DATADIR_BASE", "GAMES_SYSCONFDIR", "GAMES_STATEDIR",
+		"GAMES_LOGDIR", "GAMES_BINDIR"]
+
+	# variables for multibuild.eclass
+	var_names += ["BUILD_DIR"]
+
+	var_names = "(%s)" % "|".join(var_names)
+	var_reference = re.compile(
+		r'\$(\{%s\}|%s\W)' % (var_names, var_names))
+	missing_quotes = re.compile(
+		r'(\s|^)[^"\'\s]*\$\{?%s\}?[^"\'\s]*(\s|$)' % var_names)
+	cond_begin = re.compile(r'(^|\s+)\[\[($|\\$|\s+)')
+	cond_end = re.compile(r'(^|\s+)\]\]($|\\$|\s+)')
+
+	def check(self, num, line):
+		if self.var_reference.search(line) is None:
+			return
+		# There can be multiple matches / violations on a single line. We
+		# have to make sure none of the matches are violators. Once we've
+		# found one violator, any remaining matches on the same line can
+		# be ignored.
+		pos = 0
+		while pos <= len(line) - 1:
+			missing_quotes = self.missing_quotes.search(line, pos)
+			if not missing_quotes:
+				break
+			# If the last character of the previous match is a whitespace
+			# character, that character may be needed for the next
+			# missing_quotes match, so search overlaps by 1 character.
+			group = missing_quotes.group()
+			pos = missing_quotes.end() - 1
+
+			# Filter out some false positives that can
+			# get through the missing_quotes regex.
+			if self.var_reference.search(group) is None:
+				continue
+
+			# Filter matches that appear to be an
+			# argument to a message command.
+			# For example: false || ewarn "foo $WORKDIR/bar baz"
+			message_match = self._message_re.search(line)
+			if message_match is not None and \
+				message_match.start() < pos and \
+				message_match.end() > pos:
+				break
+
+			# This is an attempt to avoid false positives without getting
+			# too complex, while possibly allowing some (hopefully
+			# unlikely) violations to slip through. We just assume
+			# everything is correct if the there is a ' [[ ' or a ' ]] '
+			# anywhere in the whole line (possibly continued over one
+			# line).
+			if self.cond_begin.search(line) is not None:
+				continue
+			if self.cond_end.search(line) is not None:
+				continue
+
+			# Any remaining matches on the same line can be ignored.
+			return self.errors['MISSING_QUOTES_ERROR']


^ permalink raw reply related	[flat|nested] 9+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/quotes/
  2018-03-30  4:23 [gentoo-commits] proj/portage:master " Zac Medico
@ 2018-03-30  5:20 ` Zac Medico
  0 siblings, 0 replies; 9+ messages in thread
From: Zac Medico @ 2018-03-30  5:20 UTC (permalink / raw
  To: gentoo-commits

commit:     3618bc93cf1cfcb9f7f2d5f11852a1b0edbed871
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Sat Jul 15 01:04:31 2017 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Fri Mar 30 03:51:18 2018 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=3618bc93

repoman: New linechecks module, quotes

 .../repoman/modules/linechecks/quotes/__init__.py  | 27 +++++++
 .../repoman/modules/linechecks/quotes/quoteda.py   | 16 ++++
 .../repoman/modules/linechecks/quotes/quotes.py    | 86 ++++++++++++++++++++++
 3 files changed, 129 insertions(+)

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/__init__.py b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
new file mode 100644
index 000000000..6043ab20c
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/__init__.py
@@ -0,0 +1,27 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Nested plug-in module for repoman LineChecks.
+Performs nested subshell checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+	'name': 'do',
+	'description': doc,
+	'provides':{
+		'quote-check': {
+			'name': "quote",
+			'sourcefile': "quotes",
+			'class': "EbuildQuote",
+			'description': doc,
+		},
+		'quoteda-check': {
+			'name': "quoteda",
+			'sourcefile': "quoteda",
+			'class': "EbuildQuotedA",
+			'description': doc,
+		},
+	}
+}
+

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
new file mode 100644
index 000000000..7fd9ba797
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quoteda.py
@@ -0,0 +1,16 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuotedA(LineCheck):
+	"""Ensure ebuilds have no quoting around ${A}"""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	a_quoted = re.compile(r'.*\"\$(\{A\}|A)\"')
+
+	def check(self, num, line):
+		match = self.a_quoted.match(line)
+		if match:
+			return "Quoted \"${A}\" on line: %d"

diff --git a/repoman/pym/repoman/modules/linechecks/quotes/quotes.py b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
new file mode 100644
index 000000000..68c594e23
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/quotes/quotes.py
@@ -0,0 +1,86 @@
+
+import re
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildQuote(LineCheck):
+	"""Ensure ebuilds have valid quoting around things like D,FILESDIR, etc..."""
+
+	repoman_check_name = 'ebuild.minorsyn'
+	_message_commands = [
+		"die", "echo", "eerror", "einfo", "elog", "eqawarn", "ewarn"]
+	_message_re = re.compile(
+		r'\s(' + "|".join(_message_commands) + r')\s+"[^"]*"\s*$')
+	_ignored_commands = ["local", "export"] + _message_commands
+	ignore_line = re.compile(
+		r'(^$)|(^\s*#.*)|(^\s*\w+=.*)' +
+		r'|(^\s*(' + "|".join(_ignored_commands) + r')\s+)')
+	ignore_comment = False
+	var_names = ["D", "DISTDIR", "FILESDIR", "S", "T", "ROOT", "WORKDIR"]
+
+	# EAPI=3/Prefix vars
+	var_names += ["ED", "EPREFIX", "EROOT"]
+
+	# variables for games.eclass
+	var_names += [
+		"Ddir", "GAMES_PREFIX_OPT", "GAMES_DATADIR",
+		"GAMES_DATADIR_BASE", "GAMES_SYSCONFDIR", "GAMES_STATEDIR",
+		"GAMES_LOGDIR", "GAMES_BINDIR"]
+
+	# variables for multibuild.eclass
+	var_names += ["BUILD_DIR"]
+
+	var_names = "(%s)" % "|".join(var_names)
+	var_reference = re.compile(
+		r'\$(\{%s\}|%s\W)' % (var_names, var_names))
+	missing_quotes = re.compile(
+		r'(\s|^)[^"\'\s]*\$\{?%s\}?[^"\'\s]*(\s|$)' % var_names)
+	cond_begin = re.compile(r'(^|\s+)\[\[($|\\$|\s+)')
+	cond_end = re.compile(r'(^|\s+)\]\]($|\\$|\s+)')
+
+	def check(self, num, line):
+		if self.var_reference.search(line) is None:
+			return
+		# There can be multiple matches / violations on a single line. We
+		# have to make sure none of the matches are violators. Once we've
+		# found one violator, any remaining matches on the same line can
+		# be ignored.
+		pos = 0
+		while pos <= len(line) - 1:
+			missing_quotes = self.missing_quotes.search(line, pos)
+			if not missing_quotes:
+				break
+			# If the last character of the previous match is a whitespace
+			# character, that character may be needed for the next
+			# missing_quotes match, so search overlaps by 1 character.
+			group = missing_quotes.group()
+			pos = missing_quotes.end() - 1
+
+			# Filter out some false positives that can
+			# get through the missing_quotes regex.
+			if self.var_reference.search(group) is None:
+				continue
+
+			# Filter matches that appear to be an
+			# argument to a message command.
+			# For example: false || ewarn "foo $WORKDIR/bar baz"
+			message_match = self._message_re.search(line)
+			if message_match is not None and \
+				message_match.start() < pos and \
+				message_match.end() > pos:
+				break
+
+			# This is an attempt to avoid false positives without getting
+			# too complex, while possibly allowing some (hopefully
+			# unlikely) violations to slip through. We just assume
+			# everything is correct if the there is a ' [[ ' or a ' ]] '
+			# anywhere in the whole line (possibly continued over one
+			# line).
+			if self.cond_begin.search(line) is not None:
+				continue
+			if self.cond_end.search(line) is not None:
+				continue
+
+			# Any remaining matches on the same line can be ignored.
+			return self.errors['MISSING_QUOTES_ERROR']


^ permalink raw reply related	[flat|nested] 9+ messages in thread

end of thread, other threads:[~2018-03-30  5:20 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2017-12-05 18:32 [gentoo-commits] proj/portage:repoman commit in: repoman/pym/repoman/modules/linechecks/quotes/ Brian Dolbec
  -- strict thread matches above, loose matches on Subject: below --
2018-03-30  4:23 [gentoo-commits] proj/portage:master " Zac Medico
2018-03-30  5:20 ` [gentoo-commits] proj/portage:repoman " Zac Medico
2018-03-30  0:48 Brian Dolbec
2018-03-29 21:35 Brian Dolbec
2017-12-06  0:16 Brian Dolbec
2017-11-26 17:46 Brian Dolbec
2017-09-11 21:43 Brian Dolbec
2017-07-15  2:29 Brian Dolbec
2017-07-15  2:08 Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox