forked from rpms/leapp-repository
117 lines
5.4 KiB
Diff
117 lines
5.4 KiB
Diff
From 44af150b6112cfd4a6d09757e0d7df64f31e8527 Mon Sep 17 00:00:00 2001
|
|
From: Inessa Vasilevskaya <ivasilev@redhat.com>
|
|
Date: Tue, 29 Mar 2022 15:09:20 +0200
|
|
Subject: [PATCH 02/39] Fix linting violations
|
|
|
|
used-before-assignment is a nice check worth keeping, so let's
|
|
fix occurencies in commands.upgrade.util code and vstpdconfigread.
|
|
As is the modified-iterating-list, so this patch fixes appropriately
|
|
cupsscanner actor's included_directive_check.
|
|
---
|
|
commands/upgrade/util.py | 2 +-
|
|
.../cupsscanner/libraries/cupsscanner.py | 18 +++++++++++++-----
|
|
.../libraries/config_parser.py | 10 +++++-----
|
|
.../test_config_parser_vsftpdconfigread.py | 8 ++++++--
|
|
4 files changed, 25 insertions(+), 13 deletions(-)
|
|
|
|
diff --git a/commands/upgrade/util.py b/commands/upgrade/util.py
|
|
index 75ffa6a6..22466ab7 100644
|
|
--- a/commands/upgrade/util.py
|
|
+++ b/commands/upgrade/util.py
|
|
@@ -20,8 +20,8 @@ def disable_database_sync():
|
|
def disable_db_sync_decorator(f):
|
|
@functools.wraps(f)
|
|
def wrapper(*args, **kwargs):
|
|
+ saved = os.environ.get('LEAPP_DEVEL_DATABASE_SYNC_OFF', None)
|
|
try:
|
|
- saved = os.environ.get('LEAPP_DEVEL_DATABASE_SYNC_OFF', None)
|
|
os.environ['LEAPP_DEVEL_DATABASE_SYNC_OFF'] = '1'
|
|
return f(*args, **kwargs)
|
|
finally:
|
|
diff --git a/repos/system_upgrade/el7toel8/actors/cupsscanner/libraries/cupsscanner.py b/repos/system_upgrade/el7toel8/actors/cupsscanner/libraries/cupsscanner.py
|
|
index 742d1e44..bc65c458 100644
|
|
--- a/repos/system_upgrade/el7toel8/actors/cupsscanner/libraries/cupsscanner.py
|
|
+++ b/repos/system_upgrade/el7toel8/actors/cupsscanner/libraries/cupsscanner.py
|
|
@@ -93,21 +93,29 @@ def include_directive_check(read_func=_read_file):
|
|
included_files = ['/etc/cups/cupsd.conf']
|
|
error_list = []
|
|
|
|
- for included_file in included_files:
|
|
+ vetted_included_files = []
|
|
+ while included_files:
|
|
+ # NOTE(ivasilev) Will be using stack to process last encountered include directives first
|
|
+ included_file = included_files.pop(-1)
|
|
try:
|
|
lines = read_func(included_file)
|
|
except IOError:
|
|
error_list.append('Error during reading file {}: file not'
|
|
' found'.format(included_file))
|
|
- included_files.remove(included_file)
|
|
continue
|
|
-
|
|
+ # Append to the resulting list of vetted files if exception wasn't raised
|
|
+ vetted_included_files.append(included_file)
|
|
+ # Mark any other included file you find as need-to-be-validated
|
|
+ includes_to_process = []
|
|
for line in lines:
|
|
value = get_directive_value('Include', line)
|
|
if value:
|
|
- included_files.append(value)
|
|
+ includes_to_process.append(value)
|
|
+ # NOTE(ivasilev) Add discovered Include directives to the stack in reversed order, so that they are processed
|
|
+ # in the same order they appeared in the file
|
|
+ included_files.extend(reversed(includes_to_process))
|
|
|
|
- return (included_files, error_list)
|
|
+ return (vetted_included_files, error_list)
|
|
|
|
|
|
def digest_directive_check(path, read_func=_read_file):
|
|
diff --git a/repos/system_upgrade/el7toel8/actors/vsftpdconfigread/libraries/config_parser.py b/repos/system_upgrade/el7toel8/actors/vsftpdconfigread/libraries/config_parser.py
|
|
index 395786f2..a7a6c179 100644
|
|
--- a/repos/system_upgrade/el7toel8/actors/vsftpdconfigread/libraries/config_parser.py
|
|
+++ b/repos/system_upgrade/el7toel8/actors/vsftpdconfigread/libraries/config_parser.py
|
|
@@ -94,9 +94,9 @@ class VsftpdConfigParser(object):
|
|
|
|
def _parse_config(self, contents):
|
|
res = {}
|
|
- try:
|
|
- for (ix, line) in enumerate(contents.split('\n')):
|
|
+ for (ix, line) in enumerate(contents.split('\n')):
|
|
+ try:
|
|
self._parse_config_line(line, res)
|
|
- return res
|
|
- except ParsingError as e:
|
|
- raise ParsingError("Syntax error on line %d: %s" % (ix + 1, e))
|
|
+ except ParsingError as e:
|
|
+ raise ParsingError("Syntax error on line %d: %s" % (ix + 1, e))
|
|
+ return res
|
|
diff --git a/repos/system_upgrade/el7toel8/actors/vsftpdconfigread/tests/test_config_parser_vsftpdconfigread.py b/repos/system_upgrade/el7toel8/actors/vsftpdconfigread/tests/test_config_parser_vsftpdconfigread.py
|
|
index 52ee9043..b10ec4c9 100644
|
|
--- a/repos/system_upgrade/el7toel8/actors/vsftpdconfigread/tests/test_config_parser_vsftpdconfigread.py
|
|
+++ b/repos/system_upgrade/el7toel8/actors/vsftpdconfigread/tests/test_config_parser_vsftpdconfigread.py
|
|
@@ -1,7 +1,6 @@
|
|
import pytest
|
|
|
|
-from leapp.libraries.actor.config_parser import ParsingError, VsftpdConfigOptionParser, \
|
|
- VsftpdConfigParser
|
|
+from leapp.libraries.actor.config_parser import ParsingError, VsftpdConfigOptionParser, VsftpdConfigParser
|
|
|
|
|
|
def test_VsftpdConfigOptionParser_invalid_syntax():
|
|
@@ -66,6 +65,11 @@ def test_VsftpdConfigParser_invalid_syntax():
|
|
with pytest.raises(ParsingError):
|
|
VsftpdConfigParser('anonymous_enable')
|
|
|
|
+ # Make sure that line num is properly shown
|
|
+ with pytest.raises(ParsingError) as err:
|
|
+ VsftpdConfigParser('background=0\n#andthislineisalso=fine\nError on line 3')
|
|
+ assert "Syntax error on line 3" in str(err.value)
|
|
+
|
|
|
|
def test_VsftpdConfigParser_empty_config():
|
|
parser = VsftpdConfigParser('')
|
|
--
|
|
2.35.3
|
|
|