Update patching code to work on Python 2.7
Signed-off-by: Roberto Rosario <roberto.rosario.gonzalez@gmail.com>
This commit is contained in:
@@ -415,10 +415,14 @@ class Dependency(object):
|
||||
for replace_entry in replace_list or []:
|
||||
for path_entry in path_object.glob('**/{}'.format(replace_entry['filename_pattern'])):
|
||||
if path_entry.is_file():
|
||||
with fileinput.FileInput(path_entry, inplace=True, backup='.bck') as fo:
|
||||
for line in fo:
|
||||
for pattern in replace_entry['content_patterns']:
|
||||
print(line.replace(pattern['search'], pattern['replace']), end='')
|
||||
# PY3
|
||||
# Don't use context processor to allow working on Python 2.7
|
||||
# Update on Mayan EDMS version >= 4.0
|
||||
file_object = fileinput.FileInput(force_text(path_entry), inplace=True)
|
||||
for line in file_object:
|
||||
for pattern in replace_entry['content_patterns']:
|
||||
print(line.replace(pattern['search'], pattern['replace']), end='')
|
||||
file_object.close()
|
||||
|
||||
def verify(self):
|
||||
"""
|
||||
|
||||
@@ -25,7 +25,7 @@ class DependencyClassTestCase(BaseTestCase):
|
||||
path_temporary_directory = Path(temporary_directory)
|
||||
path_test_file = path_temporary_directory / 'test_file.css'
|
||||
|
||||
with open(path_test_file, mode='w') as file_object:
|
||||
with path_test_file.open(mode='w') as file_object:
|
||||
file_object.write(
|
||||
'@import url("https://fonts.googleapis.com/css?family=Lato:400,700,400italic");'
|
||||
)
|
||||
@@ -45,7 +45,7 @@ class DependencyClassTestCase(BaseTestCase):
|
||||
|
||||
dependency.patch_files(path=temporary_directory, replace_list=replace_list)
|
||||
|
||||
with open(path_test_file, mode='r') as file_object:
|
||||
with path_test_file.open(mode='r') as file_object:
|
||||
final_text = file_object.read()
|
||||
|
||||
shutil.rmtree(temporary_directory, ignore_errors=True)
|
||||
|
||||
Reference in New Issue
Block a user