From b5c5acf5b13836d3f2ac8e6908f76031c040c5f5 Mon Sep 17 00:00:00 2001 From: Anders Ingemann Date: Sat, 17 Aug 2013 17:28:46 +0200 Subject: [PATCH] PEP8-ify things. --- CONTRIBUTING.md | 12 ++++++++++++ base/bootstrapinfo.py | 2 +- base/tasklist.py | 2 +- common/phases.py | 2 +- common/tasks/boot.py | 4 ++-- common/tasks/loopback.py | 6 +++--- common/tasks/parted.py | 2 +- common/tools.py | 2 +- plugins/prebootstrapped/tasks.py | 2 +- plugins/root_password/tasks.py | 2 +- providers/ec2/tasks/ebs.py | 2 +- providers/virtualbox/tasks/boot.py | 27 +++++++++++++-------------- 12 files changed, 38 insertions(+), 27 deletions(-) create mode 100644 CONTRIBUTING.md diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..fb4a18a --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,12 @@ +# Coding standards # +* Specify the full path when invoking a command. +* Use long options whenever possible, this makes the commands invoked a lot easier to understand. +* Use tabs for indentation and spaces for alignment. +* Max line length is 110 chars. +* Multiple assignments may be aligned. +* Follow PEP8 with the exception of the following rules + * E101: Indenting with tabs and aligning with spaces + * E221: Alignment of assignments + * E241: Alignment of assignments + * E501: The line length is 110 characters not 80 + * W191: We indent with tabs not spaces diff --git a/base/bootstrapinfo.py b/base/bootstrapinfo.py index 4d9d4df..d1c03ec 100644 --- a/base/bootstrapinfo.py +++ b/base/bootstrapinfo.py @@ -5,4 +5,4 @@ class BootstrapInformation(object): self.manifest = manifest self.debug = debug import random - self.run_id = random.randrange(16**8) + self.run_id = random.randrange(16 ** 8) diff --git a/base/tasklist.py b/base/tasklist.py index 758fe95..d786abd 100644 --- a/base/tasklist.py +++ b/base/tasklist.py @@ -44,7 +44,7 @@ class TaskList(object): successors = [] successors.extend([self.get(succ) for succ in task.before]) successors.extend(filter(lambda succ: type(task) in succ.after, tasks)) - succeeding_phases = order[order.index(task.phase)+1:] + succeeding_phases = order[order.index(task.phase) + 1:] successors.extend(filter(lambda succ: succ.phase in succeeding_phases, tasks)) graph[task] = filter(lambda succ: succ in self.tasks, successors) diff --git a/common/phases.py b/common/phases.py index 83743d8..ce50733 100644 --- a/common/phases.py +++ b/common/phases.py @@ -21,6 +21,6 @@ order = [preparation, system_cleaning, volume_unmounting, image_registration, - image_conversion, + image_conversion, cleaning, ] diff --git a/common/tasks/boot.py b/common/tasks/boot.py index 039a36e..de3c190 100644 --- a/common/tasks/boot.py +++ b/common/tasks/boot.py @@ -22,8 +22,8 @@ class DisableGetTTYs(Task): from common.tools import sed_i inittab_path = os.path.join(info.root, 'etc/inittab') tty1 = '1:2345:respawn:/sbin/getty 38400 tty1' - sed_i(inittab_path, '^'+tty1, '#'+tty1) + sed_i(inittab_path, '^' + tty1, '#' + tty1) ttyx = ':23:respawn:/sbin/getty 38400 tty' for i in range(2, 6): i = str(i) - sed_i(inittab_path, '^'+i+ttyx+i, '#'+i+ttyx+i) + sed_i(inittab_path, '^' + i + ttyx + i, '#' + i + ttyx + i) diff --git a/common/tasks/loopback.py b/common/tasks/loopback.py index 8ae20e1..b801fc1 100644 --- a/common/tasks/loopback.py +++ b/common/tasks/loopback.py @@ -13,8 +13,8 @@ class Create(Task): import os.path info.loopback_file = os.path.join(info.manifest.volume['loopback_dir'], loopback_filename) log_check_call(['/bin/dd', - 'if=/dev/zero', 'of='+info.loopback_file, - 'bs=1M', 'seek='+str(info.manifest.volume['size']), 'count=0']) + 'if=/dev/zero', 'of=' + info.loopback_file, + 'bs=1M', 'seek=' + str(info.manifest.volume['size']), 'count=0']) class CreateQemuImg(Task): @@ -26,7 +26,7 @@ class CreateQemuImg(Task): import os.path info.loopback_file = os.path.join(info.manifest.volume['loopback_dir'], loopback_filename) log_check_call(['/usr/bin/qemu-img', 'create', '-f', 'raw', - info.loopback_file, str(info.manifest.volume['size'])+'M']) + info.loopback_file, str(info.manifest.volume['size']) + 'M']) class Attach(Task): diff --git a/common/tasks/parted.py b/common/tasks/parted.py index b5d0925..e242765 100644 --- a/common/tasks/parted.py +++ b/common/tasks/parted.py @@ -25,7 +25,7 @@ class MapPartitions(Task): after = [PartitionVolume] def run(self, info): - root_partition_path = info.bootstrap_device['path'].replace('/dev', '/dev/mapper')+'p1' + root_partition_path = info.bootstrap_device['path'].replace('/dev', '/dev/mapper') + 'p1' log_check_call(['kpartx', '-a', '-v', info.bootstrap_device['path']]) info.bootstrap_device['partitions'] = {'root_path': root_partition_path} diff --git a/common/tools.py b/common/tools.py index ccb2000..3b42ffc 100644 --- a/common/tools.py +++ b/common/tools.py @@ -19,7 +19,7 @@ def log_call(command, stdin=None): if stdin is not None: process = subprocess.Popen(command, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) - process.stdin.write(stdin+"\n") + process.stdin.write(stdin + "\n") process.stdin.flush() process.stdin.close() else: diff --git a/plugins/prebootstrapped/tasks.py b/plugins/prebootstrapped/tasks.py index c3c4bc6..bcaebc8 100644 --- a/plugins/prebootstrapped/tasks.py +++ b/plugins/prebootstrapped/tasks.py @@ -25,7 +25,7 @@ class CreateFromSnapshot(Task): before = [ebs.Attach] def run(self, info): - volume_size = int(info.manifest.volume['size']/1024) + volume_size = int(info.manifest.volume['size'] / 1024) snapshot = info.manifest.plugins['prebootstrapped']['snapshot'] info.volume = info.connection.create_volume(volume_size, info.host['availabilityZone'], diff --git a/plugins/root_password/tasks.py b/plugins/root_password/tasks.py index 55c98d1..c6f89a0 100644 --- a/plugins/root_password/tasks.py +++ b/plugins/root_password/tasks.py @@ -9,4 +9,4 @@ class SetRootPassword(Task): def run(self, info): from common.tools import log_check_call log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/chpasswd'], - 'root:'+info.manifest.plugins['root_password']['password']) + 'root:' + info.manifest.plugins['root_password']['password']) diff --git a/providers/ec2/tasks/ebs.py b/providers/ec2/tasks/ebs.py index 71f23a7..85ad4b6 100644 --- a/providers/ec2/tasks/ebs.py +++ b/providers/ec2/tasks/ebs.py @@ -25,7 +25,7 @@ class Attach(Task): def run(self, info): def char_range(c1, c2): """Generates the characters from `c1` to `c2`, inclusive.""" - for c in xrange(ord(c1), ord(c2)+1): + for c in xrange(ord(c1), ord(c2) + 1): yield chr(c) import os.path diff --git a/providers/virtualbox/tasks/boot.py b/providers/virtualbox/tasks/boot.py index b55e4fe..428f70a 100644 --- a/providers/virtualbox/tasks/boot.py +++ b/providers/virtualbox/tasks/boot.py @@ -8,10 +8,9 @@ class ConfigureGrub(Task): def run(self, info): import stat - rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | - stat.S_IRGRP | stat.S_IXGRP | - stat.S_IROTH | stat.S_IXOTH) - x_all = stat.S_IXUSR | stat.S_IXGRP | stat.S_IXOTH + rwxr_xr_x = (stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR | + stat.S_IRGRP | stat.S_IXGRP | + stat.S_IROTH | stat.S_IXOTH) import os.path device_map_path = os.path.join(info.root, 'boot/grub/device.map') with open(device_map_path, 'w') as device_map: @@ -20,16 +19,16 @@ class ConfigureGrub(Task): from common.tools import log_check_call from shutil import copy - script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/grub.d/10_linux')) - script_dst = os.path.join(info.root, 'etc/grub.d/10_linux') - copy(script_src, script_dst) - os.chmod(script_dst, rwxr_xr_x) - script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/grub.d/00_header')) - script_dst = os.path.join(info.root, 'etc/grub.d/00_header') - copy(script_src, script_dst) - os.chmod(script_dst, rwxr_xr_x) + script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/grub.d/10_linux')) + script_dst = os.path.join(info.root, 'etc/grub.d/10_linux') + copy(script_src, script_dst) + os.chmod(script_dst, rwxr_xr_x) + script_src = os.path.normpath(os.path.join(os.path.dirname(__file__), '../assets/grub.d/00_header')) + script_dst = os.path.join(info.root, 'etc/grub.d/00_header') + copy(script_src, script_dst) + os.chmod(script_dst, rwxr_xr_x) log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-initramfs', '-u']) # Install grub in mbr - log_check_call(['/usr/sbin/grub-install', '--boot-directory='+info.root+"/boot/", info.bootstrap_device['path']]) - + log_check_call(['/usr/sbin/grub-install', '--boot-directory=' + info.root + "/boot/", + info.bootstrap_device['path']]) log_check_call(['/usr/sbin/chroot', info.root, '/usr/sbin/update-grub'])