Fixed pep8 failures in all tools/ scripts

Change-Id: Ie6e77a4d45210122746b544a1aa8da563833e395
Partially-Implements: blueprint enable-flake8
This commit is contained in:
Borne Mace 2015-07-07 08:22:25 -07:00
parent 75e01a2fb2
commit 42c2419353
3 changed files with 35 additions and 27 deletions

View File

@ -3,7 +3,8 @@
# TODO(SamYaple): Allow image pushing # TODO(SamYaple): Allow image pushing
# TODO(SamYaple): Single image building w/ optional parent building # TODO(SamYaple): Single image building w/ optional parent building
# TODO(SamYaple): Build only missing images # TODO(SamYaple): Build only missing images
#TODO(SamYaple): Execute the source install script that will pull down and create tarball # TODO(SamYaple): Execute the source install script that will pull
# down and create tarball
# TODO(SamYaple): Improve logging instead of printing to stdout # TODO(SamYaple): Improve logging instead of printing to stdout
from __future__ import print_function from __future__ import print_function
@ -21,7 +22,9 @@ import traceback
import docker import docker
class WorkerThread(Thread): class WorkerThread(Thread):
def __init__(self, queue, cache, rm): def __init__(self, queue, cache, rm):
self.queue = queue self.queue = queue
self.nocache = not cache self.nocache = not cache
@ -51,7 +54,7 @@ class WorkerThread(Thread):
return return
# Pull the latest image for the base distro only # Pull the latest image for the base distro only
pull = True if image['parent'] == None else False pull = True if image['parent'] is None else False
image['logs'] = str() image['logs'] = str()
for response in self.dc.build(path=image['path'], for response in self.dc.build(path=image['path'],
@ -71,6 +74,7 @@ class WorkerThread(Thread):
image['status'] = "built" image['status'] = "built"
print(image['logs'], '\nProcessed:', image['name']) print(image['logs'], '\nProcessed:', image['name'])
def argParser(): def argParser():
parser = argparse.ArgumentParser(description='Kolla build script') parser = argparse.ArgumentParser(description='Kolla build script')
parser.add_argument('-n', '--namespace', parser.add_argument('-n', '--namespace',
@ -103,7 +107,9 @@ def argParser():
default=8) default=8)
return vars(parser.parse_args()) return vars(parser.parse_args())
class KollaWorker(): class KollaWorker():
def __init__(self, args): def __init__(self, args):
self.kolla_dir = os.path.join(sys.path[0], '..') self.kolla_dir = os.path.join(sys.path[0], '..')
self.images_dir = os.path.join(self.kolla_dir, 'docker') self.images_dir = os.path.join(self.kolla_dir, 'docker')
@ -145,7 +151,7 @@ class KollaWorker():
processed_images = list() processed_images = list()
for image in images_to_process: for image in images_to_process:
if image['parent'] == None: if image['parent'] is None:
self.tiers[-1].append(image) self.tiers[-1].append(image)
processed_images.append(image) processed_images.append(image)
if len(self.tiers) > 1: if len(self.tiers) > 1:
@ -157,7 +163,8 @@ class KollaWorker():
# TODO(SamYaple): Improve error handling in this section # TODO(SamYaple): Improve error handling in this section
if not processed_images: if not processed_images:
print('Could not find parent image from some images. Aborting', file=sys.stderr) print('Could not find parent image from some images. Aborting',
file=sys.stderr)
for image in images_to_process: for image in images_to_process:
print(image['name'], image['parent'], file=sys.stderr) print(image['name'], image['parent'], file=sys.stderr)
sys.exit() sys.exit()
@ -180,7 +187,8 @@ class KollaWorker():
print("===========================") print("===========================")
for image in self.images: for image in self.images:
if image['status'] != "built": if image['status'] != "built":
print(image['name'], "\r\t\t\t Failed with status:", image['status']) print(image['name'], "\r\t\t\t Failed with status:",
image['status'])
def buildImageList(self): def buildImageList(self):
self.images = list() self.images = list()
@ -188,7 +196,8 @@ class KollaWorker():
# Walk all of the Dockerfiles and replace the %%KOLLA%% variables # Walk all of the Dockerfiles and replace the %%KOLLA%% variables
for path in self.docker_build_paths: for path in self.docker_build_paths:
with open(os.path.join(path, 'Dockerfile')) as f: with open(os.path.join(path, 'Dockerfile')) as f:
content = f.read().replace('%%KOLLA_NAMESPACE%%', self.namespace) content = f.read().replace('%%KOLLA_NAMESPACE%%',
self.namespace)
content = content.replace('%%KOLLA_PREFIX%%', self.prefix) content = content.replace('%%KOLLA_PREFIX%%', self.prefix)
content = content.replace('%%KOLLA_TAG%%', self.tag) content = content.replace('%%KOLLA_TAG%%', self.tag)
with open(os.path.join(path, 'Dockerfile'), 'w') as f: with open(os.path.join(path, 'Dockerfile'), 'w') as f:
@ -201,7 +210,7 @@ class KollaWorker():
image['name'] + ':' + self.tag image['name'] + ':' + self.tag
image['path'] = path image['path'] = path
image['parent'] = content.split(' ')[1].split('\n')[0] image['parent'] = content.split(' ')[1].split('\n')[0]
if not self.namespace in image['parent']: if self.namespace not in image['parent']:
image['parent'] = None image['parent'] = None
self.images.append(image) self.images.append(image)
@ -224,6 +233,7 @@ class KollaWorker():
return pools return pools
def main(): def main():
args = argParser() args = argParser()

View File

@ -1,16 +1,17 @@
#!/usr/bin/python #!/usr/bin/python
import os
import sys import sys
import argparse import argparse
import json import json
import logging import logging
def parse_args(): def parse_args():
p = argparse.ArgumentParser() p = argparse.ArgumentParser()
p.add_argument('input', nargs='*') p.add_argument('input', nargs='*')
return p.parse_args() return p.parse_args()
def main(): def main():
args = parse_args() args = parse_args()
logging.basicConfig() logging.basicConfig()
@ -19,7 +20,7 @@ def main():
for filename in args.input: for filename in args.input:
with open(filename) as fd: with open(filename) as fd:
try: try:
data = json.load(fd) json.load(fd)
except ValueError as error: except ValueError as error:
res = 1 res = 1
logging.error('%s failed validation: %s', logging.error('%s failed validation: %s',
@ -29,5 +30,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()

View File

@ -1,16 +1,17 @@
#!/usr/bin/python #!/usr/bin/python
import os
import sys import sys
import argparse import argparse
import yaml import yaml
import logging import logging
def parse_args(): def parse_args():
p = argparse.ArgumentParser() p = argparse.ArgumentParser()
p.add_argument('input', nargs='*') p.add_argument('input', nargs='*')
return p.parse_args() return p.parse_args()
def main(): def main():
args = parse_args() args = parse_args()
logging.basicConfig() logging.basicConfig()
@ -19,7 +20,7 @@ def main():
for filename in args.input: for filename in args.input:
with open(filename) as fd: with open(filename) as fd:
try: try:
data = yaml.load(fd) yaml.load(fd)
except yaml.error.YAMLError as error: except yaml.error.YAMLError as error:
res = 1 res = 1
logging.error('%s failed validation: %s', logging.error('%s failed validation: %s',
@ -29,5 +30,3 @@ def main():
if __name__ == '__main__': if __name__ == '__main__':
main() main()