mirror of
https://github.com/pi-hole/docker-pi-hole.git
synced 2026-05-08 09:48:31 +01:00
Use print() function in both Python 2 and Python 3
Legacy __print__ statements are syntax errors in Python 3 but __print()__ function works as expected in both Python 2 and Python 3.
This commit is contained in:
+10
-9
@@ -15,6 +15,7 @@ Options:
|
|||||||
|
|
||||||
Examples:
|
Examples:
|
||||||
"""
|
"""
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
from docopt import docopt
|
from docopt import docopt
|
||||||
from jinja2 import Environment, FileSystemLoader
|
from jinja2 import Environment, FileSystemLoader
|
||||||
@@ -64,7 +65,7 @@ images = {
|
|||||||
|
|
||||||
def generate_dockerfiles(args):
|
def generate_dockerfiles(args):
|
||||||
if args['--no-generate']:
|
if args['--no-generate']:
|
||||||
print " ::: Skipping Dockerfile generation"
|
print(" ::: Skipping Dockerfile generation")
|
||||||
return
|
return
|
||||||
|
|
||||||
for version, archs in images.iteritems():
|
for version, archs in images.iteritems():
|
||||||
@@ -92,13 +93,13 @@ def generate_dockerfiles(args):
|
|||||||
|
|
||||||
def build_dockerfiles(args):
|
def build_dockerfiles(args):
|
||||||
if args['--no-build']:
|
if args['--no-build']:
|
||||||
print " ::: Skipping Dockerfile building"
|
print(" ::: Skipping Dockerfile building")
|
||||||
return
|
return
|
||||||
|
|
||||||
for arch in args['--arch']:
|
for arch in args['--arch']:
|
||||||
# TODO: include from external .py that can be shared with Dockerfile.py / Tests / deploy scripts '''
|
# TODO: include from external .py that can be shared with Dockerfile.py / Tests / deploy scripts '''
|
||||||
if arch == 'armel':
|
if arch == 'armel':
|
||||||
print "Skipping armel, incompatible upstream binaries/broken"
|
print("Skipping armel, incompatible upstream binaries/broken")
|
||||||
continue
|
continue
|
||||||
build('pihole', arch, args)
|
build('pihole', arch, args)
|
||||||
|
|
||||||
@@ -119,16 +120,16 @@ def build(docker_repo, arch, args):
|
|||||||
no_cache = '--no-cache'
|
no_cache = '--no-cache'
|
||||||
build_command = '{time}docker build {no_cache} --pull --cache-from="{cache},{create_tag}" -f {dockerfile} -t {create_tag} .'\
|
build_command = '{time}docker build {no_cache} --pull --cache-from="{cache},{create_tag}" -f {dockerfile} -t {create_tag} .'\
|
||||||
.format(time=time, no_cache=no_cache, cache=cached_image, dockerfile=dockerfile, create_tag=repo_tag)
|
.format(time=time, no_cache=no_cache, cache=cached_image, dockerfile=dockerfile, create_tag=repo_tag)
|
||||||
print " ::: Building {} into {}".format(dockerfile, repo_tag)
|
print(" ::: Building {} into {}".format(dockerfile, repo_tag))
|
||||||
if args['-v']:
|
if args['-v']:
|
||||||
print build_command, '\n'
|
print(build_command, '\n')
|
||||||
build_result = run_local(build_command)
|
build_result = run_local(build_command)
|
||||||
if args['-v']:
|
if args['-v']:
|
||||||
print build_result.stdout
|
print(build_result.stdout)
|
||||||
print build_result.stderr
|
print(build_result.stderr)
|
||||||
if build_result.rc != 0:
|
if build_result.rc != 0:
|
||||||
print " ::: Building {} encountered an error".format(dockerfile)
|
print(" ::: Building {} encountered an error".format(dockerfile))
|
||||||
print build_result.stderr
|
print(build_result.stderr)
|
||||||
assert build_result.rc == 0
|
assert build_result.rc == 0
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
+2
-1
@@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import print_function
|
||||||
import pytest
|
import pytest
|
||||||
import testinfra
|
import testinfra
|
||||||
import os
|
import os
|
||||||
@@ -41,7 +42,7 @@ def DockerGeneric(request, _test_args, _args, _image, _cmd, _entrypoint):
|
|||||||
docker_run = 'docker run -d -t {args} {test_args} {entry} {image} {cmd}'\
|
docker_run = 'docker run -d -t {args} {test_args} {entry} {image} {cmd}'\
|
||||||
.format(args=_args, test_args=_test_args, entry=_entrypoint, image=_image, cmd=_cmd)
|
.format(args=_args, test_args=_test_args, entry=_entrypoint, image=_image, cmd=_cmd)
|
||||||
# Print a human runable version of the container run command for faster debugging
|
# Print a human runable version of the container run command for faster debugging
|
||||||
print docker_run.replace('-d -t', '--rm -it').replace('tail -f /dev/null', 'bash')
|
print(docker_run.replace('-d -t', '--rm -it').replace('tail -f /dev/null', 'bash'))
|
||||||
docker_id = check_output(docker_run)
|
docker_id = check_output(docker_run)
|
||||||
|
|
||||||
def teardown():
|
def teardown():
|
||||||
|
|||||||
@@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import print_function
|
||||||
import os
|
import os
|
||||||
import pytest
|
import pytest
|
||||||
import re
|
import re
|
||||||
@@ -197,5 +198,5 @@ def test_webPassword_pre_existing_trumps_all_envs(Docker, args_env, test_args):
|
|||||||
def test_docker_checks_for_resolvconf_misconfiguration(Docker, args_dns, expected_stdout):
|
def test_docker_checks_for_resolvconf_misconfiguration(Docker, args_dns, expected_stdout):
|
||||||
''' The container checks for misconfigured resolv.conf '''
|
''' The container checks for misconfigured resolv.conf '''
|
||||||
function = Docker.run('. /bash_functions.sh ; eval `grep docker_checks /start.sh`')
|
function = Docker.run('. /bash_functions.sh ; eval `grep docker_checks /start.sh`')
|
||||||
print function.stdout
|
print(function.stdout)
|
||||||
assert expected_stdout in function.stdout
|
assert expected_stdout in function.stdout
|
||||||
|
|||||||
+5
-4
@@ -1,3 +1,4 @@
|
|||||||
|
from __future__ import print_function
|
||||||
import pytest
|
import pytest
|
||||||
import time
|
import time
|
||||||
''' conftest.py provides the defaults through fixtures '''
|
''' conftest.py provides the defaults through fixtures '''
|
||||||
@@ -44,10 +45,10 @@ def test_indecies_are_present(RunningPiHole):
|
|||||||
|
|
||||||
def validate_curl(http_rc, expected_http_code, page_contents):
|
def validate_curl(http_rc, expected_http_code, page_contents):
|
||||||
if int(http_rc.rc) != 0 or int(http_rc.stdout) != expected_http_code:
|
if int(http_rc.rc) != 0 or int(http_rc.stdout) != expected_http_code:
|
||||||
print 'CURL return code: {}'.format(http_rc.rc)
|
print('CURL return code: {}'.format(http_rc.rc))
|
||||||
print 'CURL stdout: {}'.format(http_rc.stdout)
|
print('CURL stdout: {}'.format(http_rc.stdout))
|
||||||
print 'CURL stderr:{}'.format(http_rc.stderr)
|
print('CURL stderr:{}'.format(http_rc.stderr))
|
||||||
print 'CURL file:\n{}\n'.format(page_contents.encode('utf-8'))
|
print('CURL file:\n{}\n'.format(page_contents.encode('utf-8')))
|
||||||
|
|
||||||
|
|
||||||
@pytest.mark.parametrize('addr', [ 'localhost' ] )
|
@pytest.mark.parametrize('addr', [ 'localhost' ] )
|
||||||
|
|||||||
Reference in New Issue
Block a user