[libvirt] [PATCH sandbox-image 0/9] Tweaks

This patch series introduces a few small changes towards making the code of virt-sandbox-image compatible with PEP8. Radostin Stoyanov (9): pylint: Remove unused import statements pylint: Move standard library imports on top pylint: Use consistent indentation of 4 spaces py3: Use 'builtins' instead of '__builtin__' pylint: Fix white-space around keywords setup: Add shebang cli: Remove unused constants cli: Remove redundant global statements docker: Add missing import base64 libvirt_sandbox_image/cli.py | 38 +++++++++++----------------- libvirt_sandbox_image/sources/base.py | 4 +-- libvirt_sandbox_image/sources/docker.py | 10 ++++---- libvirt_sandbox_image/sources/virtbuilder.py | 4 +-- libvirt_sandbox_image/template.py | 4 +-- scripts/virt-sandbox-image | 5 ++-- setup.py | 17 ++++++------- 7 files changed, 37 insertions(+), 45 deletions(-) mode change 100644 => 100755 setup.py -- 2.14.3

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/cli.py | 3 --- libvirt_sandbox_image/sources/docker.py | 1 - setup.py | 3 --- 3 files changed, 7 deletions(-) diff --git a/libvirt_sandbox_image/cli.py b/libvirt_sandbox_image/cli.py index 4bbeb5c..585df96 100644 --- a/libvirt_sandbox_image/cli.py +++ b/libvirt_sandbox_image/cli.py @@ -23,12 +23,9 @@ import argparse import gettext -import hashlib -import json import os import os.path import re -import shutil import sys import subprocess import random diff --git a/libvirt_sandbox_image/sources/docker.py b/libvirt_sandbox_image/sources/docker.py index be67e29..cf90112 100755 --- a/libvirt_sandbox_image/sources/docker.py +++ b/libvirt_sandbox_image/sources/docker.py @@ -22,7 +22,6 @@ import sys import json -import traceback import os import subprocess import shutil diff --git a/setup.py b/setup.py index c23c84d..f29be2f 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,7 @@ from setuptools import setup -from setuptools import Command from distutils.command.build import build -from distutils.util import get_platform -import sys import os import re import time -- 2.14.3

On Wed, 2018-04-18 at 21:57 +0100, Radostin Stoyanov wrote:
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/cli.py | 3 --- libvirt_sandbox_image/sources/docker.py | 1 - setup.py | 3 --- 3 files changed, 7 deletions(-)
diff --git a/libvirt_sandbox_image/cli.py b/libvirt_sandbox_image/cli.py index 4bbeb5c..585df96 100644 --- a/libvirt_sandbox_image/cli.py +++ b/libvirt_sandbox_image/cli.py @@ -23,12 +23,9 @@
import argparse import gettext -import hashlib -import json import os import os.path import re -import shutil import sys import subprocess import random diff --git a/libvirt_sandbox_image/sources/docker.py b/libvirt_sandbox_image/sources/docker.py index be67e29..cf90112 100755 --- a/libvirt_sandbox_image/sources/docker.py +++ b/libvirt_sandbox_image/sources/docker.py @@ -22,7 +22,6 @@
import sys import json -import traceback import os import subprocess import shutil diff --git a/setup.py b/setup.py index c23c84d..f29be2f 100644 --- a/setup.py +++ b/setup.py @@ -1,10 +1,7 @@
from setuptools import setup -from setuptools import Command from distutils.command.build import build -from distutils.util import get_platform
-import sys import os import re import time
ACK -- Cedric

Following PEP8 [1], imports should be grouped in the following order: standard library imports related third party imports local application/library specific imports With a blank line between each group of imports. [1] https://www.python.org/dev/peps/pep-0008/#imports Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- scripts/virt-sandbox-image | 3 ++- setup.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/scripts/virt-sandbox-image b/scripts/virt-sandbox-image index 9be4f8c..9d0ff82 100755 --- a/scripts/virt-sandbox-image +++ b/scripts/virt-sandbox-image @@ -1,8 +1,9 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*- -from libvirt_sandbox_image import cli import sys +from libvirt_sandbox_image import cli + if __name__ == '__main__': sys.exit(cli.main()) diff --git a/setup.py b/setup.py index f29be2f..85f5d45 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,11 @@ -from setuptools import setup -from distutils.command.build import build - import os import re import time +from distutils.command.build import build +from setuptools import setup + class my_build(build): user_options = build.user_options -- 2.14.3

On Wed, 2018-04-18 at 21:57 +0100, Radostin Stoyanov wrote:
Following PEP8 [1], imports should be grouped in the following order:
standard library imports related third party imports local application/library specific imports
With a blank line between each group of imports.
[1] https://www.python.org/dev/peps/pep-0008/#imports
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- scripts/virt-sandbox-image | 3 ++- setup.py | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/scripts/virt-sandbox-image b/scripts/virt-sandbox-image index 9be4f8c..9d0ff82 100755 --- a/scripts/virt-sandbox-image +++ b/scripts/virt-sandbox-image @@ -1,8 +1,9 @@ #!/usr/bin/env python3 # -*- coding: utf-8 -*-
-from libvirt_sandbox_image import cli import sys
+from libvirt_sandbox_image import cli + if __name__ == '__main__': sys.exit(cli.main()) diff --git a/setup.py b/setup.py index f29be2f..85f5d45 100644 --- a/setup.py +++ b/setup.py @@ -1,11 +1,11 @@
-from setuptools import setup -from distutils.command.build import build - import os import re import time
+from distutils.command.build import build +from setuptools import setup + class my_build(build): user_options = build.user_options
ACK -- Cedric

Pylint warning W0311 - Bad indentation http://pylint-messages.wikidot.com/messages:w0311 Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/sources/docker.py | 4 ++-- scripts/virt-sandbox-image | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/libvirt_sandbox_image/sources/docker.py b/libvirt_sandbox_image/sources/docker.py index cf90112..94eb6d1 100755 --- a/libvirt_sandbox_image/sources/docker.py +++ b/libvirt_sandbox_image/sources/docker.py @@ -47,9 +47,9 @@ class DockerConfParser(): def getEnvs(self): lst = self.json_data['config']['Env'] if lst is not None and isinstance(lst,list): - return lst + return lst else: - return [] + return [] class DockerImage(): diff --git a/scripts/virt-sandbox-image b/scripts/virt-sandbox-image index 9d0ff82..c021850 100755 --- a/scripts/virt-sandbox-image +++ b/scripts/virt-sandbox-image @@ -6,4 +6,4 @@ import sys from libvirt_sandbox_image import cli if __name__ == '__main__': - sys.exit(cli.main()) + sys.exit(cli.main()) diff --git a/setup.py b/setup.py index 85f5d45..dd22fd5 100644 --- a/setup.py +++ b/setup.py @@ -97,7 +97,7 @@ setup( ], install_requires=[], cmdclass = { - 'build': my_build, + 'build': my_build, }, classifiers = [ "License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)", -- 2.14.3

On Wed, 2018-04-18 at 21:57 +0100, Radostin Stoyanov wrote:
Pylint warning W0311 - Bad indentation
http://pylint-messages.wikidot.com/messages:w0311
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/sources/docker.py | 4 ++-- scripts/virt-sandbox-image | 2 +- setup.py | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-)
diff --git a/libvirt_sandbox_image/sources/docker.py b/libvirt_sandbox_image/sources/docker.py index cf90112..94eb6d1 100755 --- a/libvirt_sandbox_image/sources/docker.py +++ b/libvirt_sandbox_image/sources/docker.py @@ -47,9 +47,9 @@ class DockerConfParser(): def getEnvs(self): lst = self.json_data['config']['Env'] if lst is not None and isinstance(lst,list): - return lst + return lst else: - return [] + return []
class DockerImage():
diff --git a/scripts/virt-sandbox-image b/scripts/virt-sandbox-image index 9d0ff82..c021850 100755 --- a/scripts/virt-sandbox-image +++ b/scripts/virt-sandbox-image @@ -6,4 +6,4 @@ import sys from libvirt_sandbox_image import cli
if __name__ == '__main__': - sys.exit(cli.main()) + sys.exit(cli.main()) diff --git a/setup.py b/setup.py index 85f5d45..dd22fd5 100644 --- a/setup.py +++ b/setup.py @@ -97,7 +97,7 @@ setup( ], install_requires=[], cmdclass = { - 'build': my_build, + 'build': my_build, }, classifiers = [ "License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)",
ACK -- Cedric

In Python3, the __builtin__ module is renamed to builtins. https://docs.python.org/3/library/builtins.html#module-builtins Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/libvirt_sandbox_image/cli.py b/libvirt_sandbox_image/cli.py index 585df96..ec5fd6d 100644 --- a/libvirt_sandbox_image/cli.py +++ b/libvirt_sandbox_image/cli.py @@ -50,8 +50,8 @@ try: localedir="/usr/share/locale", codeset = 'utf-8') except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + import builtins + builtins.__dict__['_'] = str def debug(msg): -- 2.14.3

On Wed, 2018-04-18 at 21:57 +0100, Radostin Stoyanov wrote:
In Python3, the __builtin__ module is renamed to builtins.
https://docs.python.org/3/library/builtins.html#module-builtins
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/cli.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/libvirt_sandbox_image/cli.py b/libvirt_sandbox_image/cli.py index 585df96..ec5fd6d 100644 --- a/libvirt_sandbox_image/cli.py +++ b/libvirt_sandbox_image/cli.py @@ -50,8 +50,8 @@ try: localedir="/usr/share/locale", codeset = 'utf-8') except IOError: - import __builtin__ - __builtin__.__dict__['_'] = unicode + import builtins + builtins.__dict__['_'] = str
def debug(msg):
ACK -- Cedric

This changes aim to resolve Pylint C0326. http://pylint-messages.wikidot.com/messages:c0326 Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/cli.py | 26 +++++++++++++------------- libvirt_sandbox_image/sources/base.py | 4 ++-- libvirt_sandbox_image/sources/docker.py | 4 ++-- libvirt_sandbox_image/sources/virtbuilder.py | 4 ++-- libvirt_sandbox_image/template.py | 4 ++-- setup.py | 4 ++-- 6 files changed, 23 insertions(+), 23 deletions(-) diff --git a/libvirt_sandbox_image/cli.py b/libvirt_sandbox_image/cli.py index ec5fd6d..08c88a4 100644 --- a/libvirt_sandbox_image/cli.py +++ b/libvirt_sandbox_image/cli.py @@ -48,7 +48,7 @@ gettext.textdomain("libvirt-sandbox") try: gettext.install("libvirt-sandbox", localedir="/usr/share/locale", - codeset = 'utf-8') + codeset='utf-8') except IOError: import builtins builtins.__dict__['_'] = str @@ -109,7 +109,7 @@ def run(args): if args.connect is not None: cmd.append("-c") cmd.append(args.connect) - params = ['-m','host-image:/=%s,format=qcow2' % diskfile] + params = ['-m', 'host-image:/=%s,format=qcow2' % diskfile] networkArgs = args.network if networkArgs is not None: @@ -144,40 +144,40 @@ def list_cached(args): tmpls.extend(template.Template.get_all(source, "%s/%s" % (args.template_dir, source))) for tmpl in tmpls: - print (tmpl) + print(tmpl) def requires_template(parser): parser.add_argument("template", help=_("URI of the template")) def requires_name(parser): - parser.add_argument("-n","--name", + parser.add_argument("-n", "--name", help=_("Name of the running sandbox")) def requires_debug(parser): - parser.add_argument("-d","--debug", + parser.add_argument("-d", "--debug", default=False, action="store_true", help=_("Run in debug mode")) def check_connect(connectstr): - supportedDrivers = ['lxc:///','qemu:///session','qemu:///system'] + supportedDrivers = ['lxc:///', 'qemu:///session', 'qemu:///system'] if not connectstr in supportedDrivers: raise ValueError("URI '%s' is not supported by virt-sandbox-image" % connectstr) return True def requires_connect(parser): - parser.add_argument("-c","--connect", + parser.add_argument("-c", "--connect", help=_("Connect string for libvirt")) def requires_template_dir(parser): global default_template_dir - parser.add_argument("-t","--template-dir", + parser.add_argument("-t", "--template-dir", default=default_template_dir, help=_("Template directory for saving templates")) def requires_image_dir(parser): global default_image_dir - parser.add_argument("-I","--image-dir", + parser.add_argument("-I", "--image-dir", default=default_image_dir, help=_("Image directory for saving images")) @@ -222,9 +222,9 @@ def gen_run_args(subparser): parser.add_argument("args", nargs=argparse.REMAINDER, help=_("command arguments to run")) - parser.add_argument("-N","--network", + parser.add_argument("-N", "--network", help=_("Network params for running template")) - parser.add_argument("-e","--env",action="append", + parser.add_argument("-e", "--env", action="append", help=_("Environment params for running template")) parser.set_defaults(func=run) @@ -234,7 +234,7 @@ def gen_list_args(subparser): _("List locally cached images")) requires_template_dir(parser) - parser.add_argument("-s","--source", + parser.add_argument("-s", "--source", help=_("Name of the template source")) parser.set_defaults(func=list_cached) @@ -275,5 +275,5 @@ def main(): sys.stderr.flush() sys.exit(1) except Exception as e: - print (e) + print(e) sys.exit(1) diff --git a/libvirt_sandbox_image/sources/base.py b/libvirt_sandbox_image/sources/base.py index 0fc9243..c132489 100644 --- a/libvirt_sandbox_image/sources/base.py +++ b/libvirt_sandbox_image/sources/base.py @@ -127,13 +127,13 @@ class Source(): # Utility functions to share between the sources. - def format_disk(self,disk,format,connect): + def format_disk(self, disk, format, connect): cmd = ['virt-sandbox'] if connect is not None: cmd.append("-c") cmd.append(connect) cmd.append("-p") - params = ['--disk=file:disk_image=%s,format=%s' %(disk,format), + params = ['--disk=file:disk_image=%s,format=%s' %(disk, format), '/sbin/mkfs.ext3', '/dev/disk/by-tag/disk_image'] cmd = cmd + params diff --git a/libvirt_sandbox_image/sources/docker.py b/libvirt_sandbox_image/sources/docker.py index 94eb6d1..3ca1b10 100755 --- a/libvirt_sandbox_image/sources/docker.py +++ b/libvirt_sandbox_image/sources/docker.py @@ -533,7 +533,7 @@ class DockerSource(base.Source): parentImage = None for imagetagid in imagelist: templateImage = templatedir + "/" + imagetagid + "/template.qcow2" - cmd = ["qemu-img","create","-f","qcow2"] + cmd = ["qemu-img", "create", "-f", "qcow2"] if parentImage is not None: cmd.append("-o") cmd.append("backing_fmt=qcow2,backing_file=%s" % parentImage) @@ -657,7 +657,7 @@ class DockerSource(base.Source): tempfile = imagedir + "/" + sandboxname.split('/')[-1] + ".qcow2" if not os.path.exists(imagedir): os.makedirs(imagedir) - cmd = ["qemu-img","create","-q","-f","qcow2"] + cmd = ["qemu-img", "create", "-q", "-f", "qcow2"] cmd.append("-o") cmd.append("backing_fmt=qcow2,backing_file=%s" % diskfile) cmd.append(tempfile) diff --git a/libvirt_sandbox_image/sources/virtbuilder.py b/libvirt_sandbox_image/sources/virtbuilder.py index ba554e8..5e723e6 100755 --- a/libvirt_sandbox_image/sources/virtbuilder.py +++ b/libvirt_sandbox_image/sources/virtbuilder.py @@ -93,7 +93,7 @@ class VirtBuilderSource(base.Source): def get_command(self, template, templatedir, userargs): return userargs - def get_disk(self,template, templatedir, imagedir, sandboxname): + def get_disk(self, template, templatedir, imagedir, sandboxname): diskfile = "%s/%s.qcow2" % (templatedir, self._get_template_name(template)) tempfile = imagedir + "/" + sandboxname + ".qcow2" if not os.path.exists(imagedir): @@ -105,5 +105,5 @@ class VirtBuilderSource(base.Source): subprocess.check_call(cmd) return tempfile - def get_env(self,template, templatedir): + def get_env(self, template, templatedir): return [] diff --git a/libvirt_sandbox_image/template.py b/libvirt_sandbox_image/template.py index 25c43e6..a69ef53 100644 --- a/libvirt_sandbox_image/template.py +++ b/libvirt_sandbox_image/template.py @@ -71,7 +71,7 @@ class Template(object): classimpl = getattr(mod, classname) return classimpl() except Exception as e: - print (e) + print(e) raise Exception("Invalid source: '%s'" % source) def get_source_impl(self): @@ -120,7 +120,7 @@ class Template(object): if o.query is not None and o.query != "": for param in o.query.split("&"): (key, val) = param.split("=") - query[key] = val + query[key] = val return klass(source, protocol, o.hostname, o.port, o.username, o.password, diff --git a/setup.py b/setup.py index dd22fd5..0b16ae7 100644 --- a/setup.py +++ b/setup.py @@ -96,10 +96,10 @@ setup( "libvirt_sandbox_image/sources" ], install_requires=[], - cmdclass = { + cmdclass={ 'build': my_build, }, - classifiers = [ + classifiers=[ "License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)", "Programming Language :: Python", "Programming Language :: Python :: 3", -- 2.14.3

On Wed, 2018-04-18 at 21:57 +0100, Radostin Stoyanov wrote:
This changes aim to resolve Pylint C0326.
http://pylint-messages.wikidot.com/messages:c0326
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/cli.py | 26 +++++++++++++------------- libvirt_sandbox_image/sources/base.py | 4 ++-- libvirt_sandbox_image/sources/docker.py | 4 ++-- libvirt_sandbox_image/sources/virtbuilder.py | 4 ++-- libvirt_sandbox_image/template.py | 4 ++-- setup.py | 4 ++-- 6 files changed, 23 insertions(+), 23 deletions(-)
diff --git a/libvirt_sandbox_image/cli.py b/libvirt_sandbox_image/cli.py index ec5fd6d..08c88a4 100644 --- a/libvirt_sandbox_image/cli.py +++ b/libvirt_sandbox_image/cli.py @@ -48,7 +48,7 @@ gettext.textdomain("libvirt-sandbox") try: gettext.install("libvirt-sandbox", localedir="/usr/share/locale", - codeset = 'utf-8') + codeset='utf-8') except IOError: import builtins builtins.__dict__['_'] = str @@ -109,7 +109,7 @@ def run(args): if args.connect is not None: cmd.append("-c") cmd.append(args.connect) - params = ['-m','host-image:/=%s,format=qcow2' % diskfile] + params = ['-m', 'host-image:/=%s,format=qcow2' % diskfile]
networkArgs = args.network if networkArgs is not None: @@ -144,40 +144,40 @@ def list_cached(args): tmpls.extend(template.Template.get_all(source, "%s/%s" % (args.template_dir, source))) for tmpl in tmpls: - print (tmpl) + print(tmpl)
def requires_template(parser): parser.add_argument("template", help=_("URI of the template"))
def requires_name(parser): - parser.add_argument("-n","--name", + parser.add_argument("-n", "--name", help=_("Name of the running sandbox"))
def requires_debug(parser): - parser.add_argument("-d","--debug", + parser.add_argument("-d", "--debug", default=False, action="store_true", help=_("Run in debug mode"))
def check_connect(connectstr): - supportedDrivers = ['lxc:///','qemu:///session','qemu:///system'] + supportedDrivers = ['lxc:///', 'qemu:///session', 'qemu:///system'] if not connectstr in supportedDrivers: raise ValueError("URI '%s' is not supported by virt-sandbox-image" % connectstr) return True
def requires_connect(parser): - parser.add_argument("-c","--connect", + parser.add_argument("-c", "--connect", help=_("Connect string for libvirt"))
def requires_template_dir(parser): global default_template_dir - parser.add_argument("-t","--template-dir", + parser.add_argument("-t", "--template-dir", default=default_template_dir, help=_("Template directory for saving templates"))
def requires_image_dir(parser): global default_image_dir - parser.add_argument("-I","--image-dir", + parser.add_argument("-I", "--image-dir", default=default_image_dir, help=_("Image directory for saving images"))
@@ -222,9 +222,9 @@ def gen_run_args(subparser): parser.add_argument("args", nargs=argparse.REMAINDER, help=_("command arguments to run")) - parser.add_argument("-N","--network", + parser.add_argument("-N", "--network", help=_("Network params for running template")) - parser.add_argument("-e","--env",action="append", + parser.add_argument("-e", "--env", action="append", help=_("Environment params for running template"))
parser.set_defaults(func=run) @@ -234,7 +234,7 @@ def gen_list_args(subparser): _("List locally cached images")) requires_template_dir(parser)
- parser.add_argument("-s","--source", + parser.add_argument("-s", "--source", help=_("Name of the template source"))
parser.set_defaults(func=list_cached) @@ -275,5 +275,5 @@ def main(): sys.stderr.flush() sys.exit(1) except Exception as e: - print (e) + print(e) sys.exit(1) diff --git a/libvirt_sandbox_image/sources/base.py b/libvirt_sandbox_image/sources/base.py index 0fc9243..c132489 100644 --- a/libvirt_sandbox_image/sources/base.py +++ b/libvirt_sandbox_image/sources/base.py @@ -127,13 +127,13 @@ class Source():
# Utility functions to share between the sources.
- def format_disk(self,disk,format,connect): + def format_disk(self, disk, format, connect): cmd = ['virt-sandbox'] if connect is not None: cmd.append("-c") cmd.append(connect) cmd.append("-p") - params = ['--disk=file:disk_image=%s,format=%s' %(disk,format), + params = ['--disk=file:disk_image=%s,format=%s' %(disk, format), '/sbin/mkfs.ext3', '/dev/disk/by-tag/disk_image'] cmd = cmd + params diff --git a/libvirt_sandbox_image/sources/docker.py b/libvirt_sandbox_image/sources/docker.py index 94eb6d1..3ca1b10 100755 --- a/libvirt_sandbox_image/sources/docker.py +++ b/libvirt_sandbox_image/sources/docker.py @@ -533,7 +533,7 @@ class DockerSource(base.Source): parentImage = None for imagetagid in imagelist: templateImage = templatedir + "/" + imagetagid + "/template.qcow2" - cmd = ["qemu-img","create","-f","qcow2"] + cmd = ["qemu-img", "create", "-f", "qcow2"] if parentImage is not None: cmd.append("-o") cmd.append("backing_fmt=qcow2,backing_file=%s" % parentImage) @@ -657,7 +657,7 @@ class DockerSource(base.Source): tempfile = imagedir + "/" + sandboxname.split('/')[-1] + ".qcow2" if not os.path.exists(imagedir): os.makedirs(imagedir) - cmd = ["qemu-img","create","-q","-f","qcow2"] + cmd = ["qemu-img", "create", "-q", "-f", "qcow2"] cmd.append("-o") cmd.append("backing_fmt=qcow2,backing_file=%s" % diskfile) cmd.append(tempfile) diff --git a/libvirt_sandbox_image/sources/virtbuilder.py b/libvirt_sandbox_image/sources/virtbuilder.py index ba554e8..5e723e6 100755 --- a/libvirt_sandbox_image/sources/virtbuilder.py +++ b/libvirt_sandbox_image/sources/virtbuilder.py @@ -93,7 +93,7 @@ class VirtBuilderSource(base.Source): def get_command(self, template, templatedir, userargs): return userargs
- def get_disk(self,template, templatedir, imagedir, sandboxname): + def get_disk(self, template, templatedir, imagedir, sandboxname): diskfile = "%s/%s.qcow2" % (templatedir, self._get_template_name(template)) tempfile = imagedir + "/" + sandboxname + ".qcow2" if not os.path.exists(imagedir): @@ -105,5 +105,5 @@ class VirtBuilderSource(base.Source): subprocess.check_call(cmd) return tempfile
- def get_env(self,template, templatedir): + def get_env(self, template, templatedir): return [] diff --git a/libvirt_sandbox_image/template.py b/libvirt_sandbox_image/template.py index 25c43e6..a69ef53 100644 --- a/libvirt_sandbox_image/template.py +++ b/libvirt_sandbox_image/template.py @@ -71,7 +71,7 @@ class Template(object): classimpl = getattr(mod, classname) return classimpl() except Exception as e: - print (e) + print(e) raise Exception("Invalid source: '%s'" % source)
def get_source_impl(self): @@ -120,7 +120,7 @@ class Template(object): if o.query is not None and o.query != "": for param in o.query.split("&"): (key, val) = param.split("=") - query[key] = val + query[key] = val return klass(source, protocol, o.hostname, o.port, o.username, o.password, diff --git a/setup.py b/setup.py index dd22fd5..0b16ae7 100644 --- a/setup.py +++ b/setup.py @@ -96,10 +96,10 @@ setup( "libvirt_sandbox_image/sources" ], install_requires=[], - cmdclass = { + cmdclass={ 'build': my_build, }, - classifiers = [ + classifiers=[ "License :: OSI Approved :: GNU Lesser General Public License v2 or later (LGPLv2+)", "Programming Language :: Python", "Programming Language :: Python :: 3",
ACK -- Cedric

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- setup.py | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 setup.py diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index 0b16ae7..aec7f03 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- import os import re -- 2.14.3

On Wed, 2018-04-18 at 21:57 +0100, Radostin Stoyanov wrote:
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- setup.py | 2 ++ 1 file changed, 2 insertions(+) mode change 100644 => 100755 setup.py
diff --git a/setup.py b/setup.py old mode 100644 new mode 100755 index 0b16ae7..aec7f03 --- a/setup.py +++ b/setup.py @@ -1,3 +1,5 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*-
import os import re
ACK -- Cedric

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/cli.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/libvirt_sandbox_image/cli.py b/libvirt_sandbox_image/cli.py index 08c88a4..e96d422 100644 --- a/libvirt_sandbox_image/cli.py +++ b/libvirt_sandbox_image/cli.py @@ -40,9 +40,6 @@ else: default_template_dir = os.environ['HOME'] + "/.local/share/libvirt/templates" default_image_dir = os.environ['HOME'] + "/.local/share/libvirt/images" -debug = False -verbose = False - gettext.bindtextdomain("libvirt-sandbox", "/usr/share/locale") gettext.textdomain("libvirt-sandbox") try: -- 2.14.3

On Wed, 2018-04-18 at 21:57 +0100, Radostin Stoyanov wrote:
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/cli.py | 3 --- 1 file changed, 3 deletions(-)
diff --git a/libvirt_sandbox_image/cli.py b/libvirt_sandbox_image/cli.py index 08c88a4..e96d422 100644 --- a/libvirt_sandbox_image/cli.py +++ b/libvirt_sandbox_image/cli.py @@ -40,9 +40,6 @@ else: default_template_dir = os.environ['HOME'] + "/.local/share/libvirt/templates" default_image_dir = os.environ['HOME'] + "/.local/share/libvirt/images"
-debug = False -verbose = False - gettext.bindtextdomain("libvirt-sandbox", "/usr/share/locale") gettext.textdomain("libvirt-sandbox") try:
ACK -- Cedric

The global statement is needed for assignment of variables in global scope [1]. In this case, we only read the value of those variables, therefore we do not need to explicitly use the global statement. [1] https://docs.python.org/3/reference/simple_stmts.html#the-global-statement Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/cli.py | 2 -- 1 file changed, 2 deletions(-) diff --git a/libvirt_sandbox_image/cli.py b/libvirt_sandbox_image/cli.py index e96d422..95c5147 100644 --- a/libvirt_sandbox_image/cli.py +++ b/libvirt_sandbox_image/cli.py @@ -167,13 +167,11 @@ def requires_connect(parser): help=_("Connect string for libvirt")) def requires_template_dir(parser): - global default_template_dir parser.add_argument("-t", "--template-dir", default=default_template_dir, help=_("Template directory for saving templates")) def requires_image_dir(parser): - global default_image_dir parser.add_argument("-I", "--image-dir", default=default_image_dir, help=_("Image directory for saving images")) -- 2.14.3

On Wed, 2018-04-18 at 21:57 +0100, Radostin Stoyanov wrote:
The global statement is needed for assignment of variables in global scope [1]. In this case, we only read the value of those variables, therefore we do not need to explicitly use the global statement.
[1] https://docs.python.org/3/reference/simple_stmts.html#the-global-statement
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/cli.py | 2 -- 1 file changed, 2 deletions(-)
diff --git a/libvirt_sandbox_image/cli.py b/libvirt_sandbox_image/cli.py index e96d422..95c5147 100644 --- a/libvirt_sandbox_image/cli.py +++ b/libvirt_sandbox_image/cli.py @@ -167,13 +167,11 @@ def requires_connect(parser): help=_("Connect string for libvirt"))
def requires_template_dir(parser): - global default_template_dir parser.add_argument("-t", "--template-dir", default=default_template_dir, help=_("Template directory for saving templates"))
def requires_image_dir(parser): - global default_image_dir parser.add_argument("-I", "--image-dir", default=default_image_dir, help=_("Image directory for saving images"))
ACK -- Cedric

Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/sources/docker.py | 1 + 1 file changed, 1 insertion(+) diff --git a/libvirt_sandbox_image/sources/docker.py b/libvirt_sandbox_image/sources/docker.py index 3ca1b10..8a231ee 100755 --- a/libvirt_sandbox_image/sources/docker.py +++ b/libvirt_sandbox_image/sources/docker.py @@ -20,6 +20,7 @@ # Author: Eren Yagdiran <erenyagdiran@gmail.com> # +import base64 import sys import json import os -- 2.14.3

On Wed, 2018-04-18 at 21:57 +0100, Radostin Stoyanov wrote:
Signed-off-by: Radostin Stoyanov <rstoyanov1@gmail.com> --- libvirt_sandbox_image/sources/docker.py | 1 + 1 file changed, 1 insertion(+)
diff --git a/libvirt_sandbox_image/sources/docker.py b/libvirt_sandbox_image/sources/docker.py index 3ca1b10..8a231ee 100755 --- a/libvirt_sandbox_image/sources/docker.py +++ b/libvirt_sandbox_image/sources/docker.py @@ -20,6 +20,7 @@ # Author: Eren Yagdiran <erenyagdiran@gmail.com> #
+import base64 import sys import json import os
ACK -- Cedric

On Wed, Apr 18, 2018 at 09:57:38PM +0100, Radostin Stoyanov wrote:
This patch series introduces a few small changes towards making the code of virt-sandbox-image compatible with PEP8.
Radostin Stoyanov (9): pylint: Remove unused import statements pylint: Move standard library imports on top pylint: Use consistent indentation of 4 spaces py3: Use 'builtins' instead of '__builtin__' pylint: Fix white-space around keywords setup: Add shebang cli: Remove unused constants cli: Remove redundant global statements docker: Add missing import base64
libvirt_sandbox_image/cli.py | 38 +++++++++++----------------- libvirt_sandbox_image/sources/base.py | 4 +-- libvirt_sandbox_image/sources/docker.py | 10 ++++---- libvirt_sandbox_image/sources/virtbuilder.py | 4 +-- libvirt_sandbox_image/template.py | 4 +-- scripts/virt-sandbox-image | 5 ++-- setup.py | 17 ++++++------- 7 files changed, 37 insertions(+), 45 deletions(-) mode change 100644 => 100755 setup.py
Thanks, I've pushed this series Regards, Daniel -- |: https://berrange.com -o- https://www.flickr.com/photos/dberrange :| |: https://libvirt.org -o- https://fstop138.berrange.com :| |: https://entangle-photo.org -o- https://www.instagram.com/dberrange :|
participants (3)
-
Cedric Bosdonnat
-
Daniel P. Berrangé
-
Radostin Stoyanov