python: PEP8 compatibility

The new version of the pep8 command is detecting more indentation
mistakes than it used to, this fixes them.

Signed-off-by: Stéphane Graber <stgraber@ubuntu.com>
Acked-by: Serge E. Hallyn <serge.hallyn@ubuntu.com>
This commit is contained in:
Stéphane Graber 2012-11-22 15:25:45 -05:00
parent f79d43bbe7
commit bde1853954
4 changed files with 84 additions and 82 deletions

View File

@ -52,10 +52,11 @@ def randomMAC():
return ':'.join(map(lambda x: "%02x" % x, mac))
# Begin parsing the command line
parser = argparse.ArgumentParser(
description=_("LXC: Start an ephemeral container"),
formatter_class=argparse.RawTextHelpFormatter, epilog=_(
"""If a COMMAND is given, then the container will run only as long
parser = argparse.ArgumentParser(description=_(
"LXC: Start an ephemeral container"),
formatter_class=argparse.RawTextHelpFormatter,
epilog=_("If a COMMAND is given, then the "
"""container will run only as long
as the command runs.
If no COMMAND is given, this command will attach to tty1 and stop the
container when exiting (with ctrl-a-q).
@ -80,13 +81,15 @@ parser.add_argument("--daemon", "-d", action="store_true",
parser.add_argument("--union-type", "-U", type=str, default="overlayfs",
choices=("overlayfs", "aufs"),
help=_("type of union (overlayfs or aufs), defaults to overlayfs."))
help=_("type of union (overlayfs or aufs), "
"defaults to overlayfs."))
parser.add_argument("--keep-data", "-k", action="store_true",
help=_("Use a persistent backend instead of tmpfs."))
parser.add_argument("command", metavar='CMD', type=str, nargs="*",
help=_("Run specific command in container (command as argument)"))
help=_("Run specific command in container "
"(command as argument)"))
args = parser.parse_args()
@ -152,8 +155,8 @@ if orig.get_config_item("lxc.mount"):
continue
if "%s/rootfs/" % dest_path not in dest_mount:
print(_(
"Skipping mount entry '%s' as it's outside of the container rootfs.") % line)
print(_("Skipping mount entry '%s' as it's outside "
"of the container rootfs.") % line)
overlay_dirs += [(fields[0], dest_mount)]
@ -248,11 +251,9 @@ if args.daemon:
You can enter it from the command line with: lxc-console -n %s
The following IP addresses have be found in the container:
%s""") % (
dest.name,
%s""") % (dest.name,
"\n".join([" - %s" % entry for entry in ips]
or [" - %s" % _("No address could be found")])
))
or [" - %s" % _("No address could be found")])))
sys.exit(0)
# Now deal with the case where we want to run a command in the container

View File

@ -44,17 +44,17 @@ container = lxc.Container(CONTAINER_NAME)
# A few basic checks of the current state
assert(container.config_file_name == "%s/%s/config" %
(LXC_PATH_LIB, CONTAINER_NAME))
assert(container.defined == False)
assert(not container.defined)
assert(container.init_pid == -1)
assert(container.name == CONTAINER_NAME)
assert(container.running == False)
assert(not container.running)
assert(container.state == "STOPPED")
## Create a rootfs
print("Creating rootfs using '%s'" % LXC_TEMPLATE)
container.create(LXC_TEMPLATE)
assert(container.defined == True)
assert(container.defined)
assert(container.name == CONTAINER_NAME
== container.get_config_item("lxc.utsname"))
assert(container.name in lxc.list_containers())
@ -86,7 +86,7 @@ container.wait("RUNNING", 3)
# A few basic checks of the current state
assert(container.init_pid > 1)
assert(container.running == True)
assert(container.running)
assert(container.state == "RUNNING")
## Checking IP address
@ -104,7 +104,7 @@ container.wait("FROZEN", 3)
# A few basic checks of the current state
assert(container.init_pid > 1)
assert(container.running == True)
assert(container.running)
assert(container.state == "FROZEN")
## Unfreezing the container
@ -114,7 +114,7 @@ container.wait("RUNNING", 3)
# A few basic checks of the current state
assert(container.init_pid > 1)
assert(container.running == True)
assert(container.running)
assert(container.state == "RUNNING")
if len(sys.argv) > 1 and sys.argv[1] == "--with-console":
@ -133,7 +133,7 @@ if container.running:
# A few basic checks of the current state
assert(container.init_pid == -1)
assert(container.running == False)
assert(not container.running)
assert(container.state == "STOPPED")
## Cloning the container
@ -148,4 +148,4 @@ clone.destroy()
print("Destroying the container")
container.destroy()
assert(container.defined == False)
assert(not container.defined)

View File

@ -272,8 +272,7 @@ class Container(_lxc.Container):
if not source.defined:
return False
if subprocess.call(
["lxc-clone", "-o", source.name, "-n", self.name],
if subprocess.call(["lxc-clone", "-o", source.name, "-n", self.name],
universal_newlines=True) != 0:
return False
@ -288,8 +287,7 @@ class Container(_lxc.Container):
if not self.running:
return False
if subprocess.call(
["lxc-console", "-n", self.name, "-t", "%s" % tty],
if subprocess.call(["lxc-console", "-n", self.name, "-t", "%s" % tty],
universal_newlines=True) != 0:
return False
return True
@ -339,7 +337,8 @@ class Container(_lxc.Container):
ip6_cmd = base_cmd + ["-6", "addr", "show", "scope", "global"]
if interface:
ip = subprocess.Popen(ip6_cmd + ["dev", interface],
stdout=subprocess.PIPE, universal_newlines=True)
stdout=subprocess.PIPE,
universal_newlines=True)
else:
ip = subprocess.Popen(ip6_cmd, stdout=subprocess.PIPE,
universal_newlines=True)
@ -355,7 +354,8 @@ class Container(_lxc.Container):
ip4_cmd = base_cmd + ["-4", "addr", "show", "scope", "global"]
if interface:
ip = subprocess.Popen(ip4_cmd + ["dev", interface],
stdout=subprocess.PIPE, universal_newlines=True)
stdout=subprocess.PIPE,
universal_newlines=True)
else:
ip = subprocess.Popen(ip4_cmd, stdout=subprocess.PIPE,
universal_newlines=True)
@ -407,14 +407,14 @@ class Container(_lxc.Container):
set_key(key, value)
new_value = self.get_config_item(key)
if isinstance(value, str) and isinstance(new_value, str) and \
value == new_value:
if (isinstance(value, str) and isinstance(new_value, str) and
value == new_value):
return True
elif isinstance(value, list) and isinstance(new_value, list) and \
set(value) == set(new_value):
elif (isinstance(value, list) and isinstance(new_value, list) and
set(value) == set(new_value)):
return True
elif isinstance(value, str) and isinstance(new_value, list) and \
set([value]) == set(new_value):
elif (isinstance(value, str) and isinstance(new_value, list) and
set([value]) == set(new_value)):
return True
elif old_value:
set_key(key, old_value)
@ -423,7 +423,7 @@ class Container(_lxc.Container):
self.clear_config_item(key)
return False
def wait(self, state, timeout = -1):
def wait(self, state, timeout=-1):
"""
Wait for the container to reach a given state or timeout.
"""
@ -433,6 +433,7 @@ class Container(_lxc.Container):
return _lxc.Container.wait(self, state, timeout)
def list_containers(as_object=False):
"""
List the containers on the system.

View File

@ -1,10 +1,10 @@
from distutils.core import setup, Extension
module = Extension('_lxc', sources = ['lxc.c'], libraries = ['lxc'])
module = Extension('_lxc', sources=['lxc.c'], libraries=['lxc'])
setup (name = '_lxc',
version = '0.1',
description = 'LXC',
packages = ['lxc'],
package_dir = {'lxc':'lxc'},
ext_modules = [module])
setup(name='_lxc',
version='0.1',
description='LXC',
packages=['lxc'],
package_dir={'lxc': 'lxc'},
ext_modules=[module])