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

@ -1,10 +1,11 @@
#!/usr/bin/env python #!/usr/bin/env python
#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
#TODO(SamYaple): Improve logging instead of printing to stdout # down and create tarball
# TODO(SamYaple): Improve logging instead of printing to stdout
from __future__ import print_function from __future__ import print_function
import argparse import argparse
@ -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,9 +74,10 @@ 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',
help='Set the Docker namespace name', help='Set the Docker namespace name',
type=str, type=str,
default='kollaglue') default='kollaglue')
@ -81,29 +85,31 @@ def argParser():
help='Set the Docker tag', help='Set the Docker tag',
type=str, type=str,
default='latest') default='latest')
parser.add_argument('-b','--base', parser.add_argument('-b', '--base',
help='The base distro to use when building', help='The base distro to use when building',
type=str, type=str,
default='centos') default='centos')
parser.add_argument('-t','--type', parser.add_argument('-t', '--type',
help='The method of the Openstack install', help='The method of the Openstack install',
type=str, type=str,
default='binary') default='binary')
parser.add_argument('-c','--cache', parser.add_argument('-c', '--cache',
help='Use Docker cache when building', help='Use Docker cache when building',
type=bool, type=bool,
default=True) default=True)
parser.add_argument('-r','--rm', parser.add_argument('-r', '--rm',
help='Remove intermediate containers while building', help='Remove intermediate containers while building',
type=bool, type=bool,
default=True) default=True)
parser.add_argument('-T','--threads', parser.add_argument('-T', '--threads',
help='The number of threads to use while building', help='The number of threads to use while building',
type=int, type=int,
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:
@ -155,9 +161,10 @@ class KollaWorker():
self.tiers[-1].append(image) self.tiers[-1].append(image)
processed_images.append(image) processed_images.append(image)
#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:
@ -198,10 +207,10 @@ class KollaWorker():
image['status'] = "unprocessed" image['status'] = "unprocessed"
image['name'] = os.path.basename(path) image['name'] = os.path.basename(path)
image['fullname'] = self.namespace + '/' + self.prefix + \ image['fullname'] = self.namespace + '/' + self.prefix + \
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()