Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

python3 migration for build #451

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 8 additions & 8 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ full: provision build
all: build

build:
python2 ./bin/console docker:build --threads=auto
bin/console docker:build --threads=auto

bootstrap: webdevops/bootstrap webdevops/ansible
base: webdevops/base webdevops/base-app webdevops/storage
Expand All @@ -40,20 +40,20 @@ requirements:
cd tests/serverspec && bundle install --path=vendor

test:
python2 bin/console test:serverspec --threads=auto -v
bin/console test:serverspec --threads=auto -v

provision:
python2 bin/console generate:dockerfile
python2 bin/console generate:provision
bin/console generate:dockerfile
bin/console generate:provision

push:
python2 ./bin/console docker:push --threads=auto
bin/console docker:push --threads=auto

graph:
python2 ./bin/console generate:graph
bin/console generate:graph

graph-full:
python2 ./bin/console generate:graph --all\
bin/console generate:graph --all\
--filename docker-image-full-layout.gv

documentation:
Expand All @@ -65,4 +65,4 @@ documentation:
--poll -H 0.0.0.0 /opt/docs html

webdevops/%:
python2 ./bin/console docker:build --threads=auto --whitelist=$@
bin/console docker:build --threads=auto --whitelist=$@
2 changes: 1 addition & 1 deletion bin/command/docker_build_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand Down
24 changes: 12 additions & 12 deletions bin/command/docker_exec_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand Down Expand Up @@ -51,11 +51,11 @@ def run_task(self, configuration):
for dockerfile in dockerfile_list:
title = dockerfile['image']['fullname']

print title
print '~' * len(title)
print(title)
print('~' * len(title))

if configuration['dryRun']:
print ' exec: %s' % (docker_command)
print(' exec: %s' % (docker_command))
else:

cmd = [
Expand All @@ -71,19 +71,19 @@ def run_task(self, configuration):
status = Command.execute(cmd)

if status:
print colored(' -> successfull', 'green')
print(colored(' -> successfull', 'green'))
else:
print colored(' -> failed', 'red')
print(colored(' -> failed', 'red'))
image_fail_list.append(dockerfile['image']['fullname'])
print ''
print ''
print('')
print('')

if len(image_fail_list) >= 1:
print ''
print colored(' => failed images (%s):' % (str(len(image_fail_list))), 'red')
print('')
print(colored(' => failed images (%s):' % (str(len(image_fail_list))), 'red'))
for image in image_fail_list:
print ' - %s ' % image
print ''
print(' - %s ' % image)
print('')

return False
else:
Expand Down
2 changes: 1 addition & 1 deletion bin/command/docker_pull_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand Down
2 changes: 1 addition & 1 deletion bin/command/docker_push_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand Down
2 changes: 1 addition & 1 deletion bin/command/generate_dockerfile_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand Down
18 changes: 9 additions & 9 deletions bin/command/generate_graph_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand Down Expand Up @@ -43,7 +43,7 @@ class GenerateGraphCommand(BaseCommand):
'--format': Enum(['png', 'jpg', 'pdf', 'svg'])
}

from_regex = re.compile(ur'FROM\s+(?P<image>[^\s:]+)(:(?P<tag>.+))?', re.MULTILINE)
from_regex = re.compile(r'FROM\s+(?P<image>[^\s:]+)(:(?P<tag>.+))?', re.MULTILINE)

containers = {}

Expand Down Expand Up @@ -116,7 +116,7 @@ def __append_tag(self, docker_image, tag):

:return: self
"""
if not self.tags.has_key(docker_image):
if docker_image not in self.tags:
self.tags[docker_image] = {}
self.tags[docker_image][tag] = tag
return self
Expand All @@ -133,7 +133,7 @@ def __get_graph(self, default_graph, name):
:return: the selected diagram
:rtype: Digraph
"""
for group, group_attr in self.conf['diagram']['groups'].items():
for group, group_attr in list(self.conf['diagram']['groups'].items()):
for dockerRegex in group_attr['docker']:
if re.match(dockerRegex, name):
return group, self.subgraph[group]
Expand Down Expand Up @@ -190,15 +190,15 @@ def build_graph(self):
rank_group_list = {}

# Create subgraph
for group, group_attr in self.conf['diagram']['groups'].items():
for group, group_attr in list(self.conf['diagram']['groups'].items()):
self.subgraph[group] = Digraph('cluster_%s' % group)
self.subgraph[group].body.append(r'label = "%s"' % group_attr['name'])
self.subgraph[group] = self.__apply_styles(self.subgraph[group], group_attr['styles'])

if 'rank' in group_attr:
rank_group_list[group] = group_attr['rank']

for image, base in self.containers.items():
for image, base in list(self.containers.items()):
group_image, graph_image = self.__get_graph(dia, image)
group_base, graph_base = self.__get_graph(dia, base)
if not "scratch" in base:
Expand All @@ -221,15 +221,15 @@ def build_graph(self):
rank_image_list[image_rank].append(image)

# add repositories (subgraph/cluster)
for name, subgraph in self.subgraph.items():
for name, subgraph in list(self.subgraph.items()):
dia.subgraph(subgraph)

# add images (node)
for image, base in self.edges.items():
for image, base in list(self.edges.items()):
dia.edge(base, image)

# add invisible constraints to add ranked groups
for rank, imagelist in rank_image_list.items():
for rank, imagelist in list(rank_image_list.items()):
rank_next = rank + 1

if rank_next in rank_image_list:
Expand Down
6 changes: 3 additions & 3 deletions bin/command/generate_provision_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand All @@ -22,7 +22,7 @@
import yaml
import yamlordereddictloader
import time
import Queue
import queue
import shutil
import grp
from cleo import Output
Expand All @@ -46,7 +46,7 @@ class GenerateProvisionCommand(BaseCommand):
__queue = ''

def run_task(self, configuration):
self.__queue = Queue.Queue()
self.__queue = queue.Queue()
if Output.VERBOSITY_VERBOSE <= self.output.get_verbosity():
self.line('<info>provision :</info> %s' % configuration.get('provisionPath'))
self.line('<info>dockerfile :</info> %s' % configuration.get('dockerPath'))
Expand Down
2 changes: 1 addition & 1 deletion bin/command/test_serverspec_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand Down
2 changes: 1 addition & 1 deletion bin/command/test_testinfra_command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand Down
18 changes: 9 additions & 9 deletions bin/console
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

import os, sys
Expand All @@ -7,8 +7,8 @@ import os, sys
sys.dont_write_bytecode = True

# unbuffered stdout / stderr
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w', 0)
sys.stderr = os.fdopen(sys.stderr.fileno(), 'w', 0)
sys.stdout = os.fdopen(sys.stdout.fileno(), 'w')
sys.stderr = os.fdopen(sys.stderr.fileno(), 'w')

import re, yaml
from cleo import Application
Expand Down Expand Up @@ -43,19 +43,19 @@ if __name__ == '__main__':
# Read console.yml for configuration
with open(os.path.join(conf_path, 'console.yml'), 'r') as stream:
try:
configuration = yaml.load(stream)
configuration = yaml.load(stream, Loader=yaml.FullLoader)
configuration['confPath'] = conf_path
except yaml.YAMLError as e:
configuration = None
print ' !!! Exception while loading configuration from %s:' % conf_path
print ''
print e
print ''
print(' !!! Exception while loading configuration from %s:' % conf_path)
print('')
print(e)
print('')
sys.exit(1)

# Check if configuration is valid
if configuration is None:
print ' !!! Configuration not found'
print(' !!! Configuration not found')
sys.exit(1)

# generate full paths
Expand Down
8 changes: 4 additions & 4 deletions bin/webdevops/Command.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand All @@ -25,7 +25,7 @@ def execute(cmd, cwd=False, env=None):
Execute cmd and output stdout/stderr
"""

print 'Execute: %s' % ' '.join(cmd)
print('Execute: %s' % ' '.join(cmd))

if env is not None:
env = copy.deepcopy(env)
Expand Down Expand Up @@ -67,13 +67,13 @@ def execute(cmd, cwd=False, env=None):
# output stdout
with open(file_stdout.name, 'r') as f:
for line in f:
print line.rstrip('\n')
print(line.rstrip('\n'))

# restore current work directory
os.chdir(path_current)

if proc.returncode == 0:
return True
else:
print '>> failed command with return code %s' % proc.returncode
print('>> failed command with return code %s' % proc.returncode)
return False
12 changes: 6 additions & 6 deletions bin/webdevops/Configuration.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand Down Expand Up @@ -44,7 +44,7 @@
'docker': {
'imagePrefix': '',
'autoLatestTag': False,
'fromRegExp': re.compile(ur'FROM\s+(?P<image>[^\s:]+)(:(?P<tag>.+))?', re.MULTILINE),
'fromRegExp': re.compile(r'FROM\s+(?P<image>[^\s:]+)(:(?P<tag>.+))?', re.MULTILINE),
'pathRegex': False,
'autoPull': False,
'autoPullWhitelist': False,
Expand Down Expand Up @@ -83,7 +83,7 @@ def dictmerge(original, update):
Recursively update a dict.
Subdict's won't be overwritten but also updated.
"""
for key, value in original.iteritems():
for key, value in original.items():
if key not in update:
update[key] = value
elif isinstance(value, dict):
Expand All @@ -101,7 +101,7 @@ def __init__(self, value=None):
for key in value:
self.__setitem_internal__(key, value[key])
else:
raise TypeError, 'expected dict'
raise TypeError('expected dict')

def __setitem_internal__(self, key, value):
"""
Expand All @@ -116,7 +116,7 @@ def __setitem__(self, key, value):
myKey, restOfKey = key.split('.', 1)
target = self.setdefault(myKey, dotdictify())
if not isinstance(target, dotdictify):
raise KeyError, 'cannot set "%s" in "%s" (%s)' % (restOfKey, myKey, repr(target))
raise KeyError('cannot set "%s" in "%s" (%s)' % (restOfKey, myKey, repr(target)))
target[restOfKey] = value
else:
if isinstance(value, dict) and not isinstance(value, dotdictify):
Expand All @@ -129,7 +129,7 @@ def __getitem__(self, key, raw=False):
myKey, restOfKey = key.split('.', 1)
target = dict.get(self, myKey, None)
if not isinstance(target, dotdictify):
raise KeyError, 'cannot get "%s" in "%s" (%s)' % (restOfKey, myKey, repr(target))
raise KeyError('cannot get "%s" in "%s" (%s)' % (restOfKey, myKey, repr(target)))
return target[restOfKey]

def __contains__(self, key):
Expand Down
4 changes: 2 additions & 2 deletions bin/webdevops/Dockerfile.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand Down Expand Up @@ -40,7 +40,7 @@ def finder(dockerfile_path, filename="Dockerfile", filter=[]):
:rtype: list
"""
dockerfile_stack = []
filter_regex = re.compile(ur'.*(%s).*' % "|".join(filter), re.IGNORECASE)
filter_regex = re.compile(r'.*(%s).*' % "|".join(filter), re.IGNORECASE)
# pprint(filter_regex.pattern)
for root, dirs, files in os.walk(dockerfile_path):
for file in files:
Expand Down
10 changes: 5 additions & 5 deletions bin/webdevops/DockerfileUtility.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env/python
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
#
# (c) 2016 WebDevOps.io
Expand All @@ -21,8 +21,8 @@
import os
import re

DOCKERFILE_STATEMENT_FROM_RE = re.compile(ur'FROM\s+(?P<image>[^\s:]+)(:(?P<tag>[^\s:]+))?(?!.*\s+AS)', re.MULTILINE)
DOCKERFILE_STATEMENT_FROM_MULTISTAGE_RE = re.compile(ur'FROM\s+(?P<image>[^\s:]+)(:(?P<tag>[^\s:]+))?(\s+AS)', re.MULTILINE)
DOCKERFILE_STATEMENT_FROM_RE = re.compile(r'FROM\s+(?P<image>[^\s:]+)(:(?P<tag>[^\s:]+))?(?!.*\s+AS)', re.MULTILINE)
DOCKERFILE_STATEMENT_FROM_MULTISTAGE_RE = re.compile(r'FROM\s+(?P<image>[^\s:]+)(:(?P<tag>[^\s:]+))?(\s+AS)', re.MULTILINE)

def find_file_in_path(dockerfile_path, filename="Dockerfile", whitelist=False, blacklist=False):
"""
Expand Down Expand Up @@ -64,7 +64,7 @@ def find_file_in_path(dockerfile_path, filename="Dockerfile", whitelist=False, b

if blacklist:
for term in blacklist:
file_list = filter(lambda x: term not in x, file_list)
file_list = [x for x in file_list if term not in x]

return file_list

Expand Down Expand Up @@ -143,7 +143,7 @@ def filter_dockerfile(dockerfile_list, whitelist=False, blacklist=False):

if blacklist:
for term in blacklist:
dockerfile_list = filter(lambda x: term not in x['image']['fullname'], dockerfile_list)
dockerfile_list = [x for x in dockerfile_list if term not in x['image']['fullname']]

return dockerfile_list

Expand Down
Loading