Skip to content

Commit

Permalink
Switch to Python 3
Browse files Browse the repository at this point in the history
Signed-off-by: Aline Manera <aline.manera@gmail.com>
  • Loading branch information
alinefm committed May 15, 2019
1 parent c906860 commit 8334268
Show file tree
Hide file tree
Showing 100 changed files with 7,406 additions and 6,160 deletions.
71 changes: 48 additions & 23 deletions API.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"$schema": "http://json-schema.org/draft-03/schema#",
"$schema": "http://json-schema.org/draft-07/schema#",
"title": "Kimchi API",
"description": "Json schema for Kimchi API",
"type": "object",
Expand All @@ -9,15 +9,16 @@
"type": "object",
"properties": {
"type": {
"type": "string",
"enum": ["spice", "vnc"],
"error": "KCHVM0014E"
},
"listen": {
"error": "KCHVM0015E",
"type": [
"anyOf": [
{
"type": "string",
"format": "ip-address"
"format": "ipv4"
},
{
"type": "string",
Expand Down Expand Up @@ -93,18 +94,20 @@
"interface": {
"description": "Host network interface. This indicates how to configure the host network interface (Ethernet, Bond, VLAN) as direct macvtap or as OVS interface to a VM.",
"type": "object",
"required": [
"type",
"name"
],
"properties": {
"type": {
"description": "Host network interface type. Valid types are: 'macvtap' for host network interface (Ethernet, Bond, VLAN) to be connected as direct MacVTap or 'ovs' for openvswitch host network interface to be connected as virtual switch to a VM.",
"type": "string",
"pattern": "^(macvtap|ovs)$",
"required": "True",
"error": "KCHTMPL0034E"
},
"name": {
"description": "The host network interface name. It should be name of host network interface(Ethernet, Bond, VLAN) for type 'macvtap' and name of host openvswitch bridge interface for type ovs",
"type": "string",
"required": "True",
"error": "KCHTMPL0035E"
},
"mode": {
Expand All @@ -121,21 +124,23 @@
"properties": {
"storagepools_create": {
"type": "object",
"required": [
"name",
"type"
],
"error": "KCHPOOL0026E",
"properties": {
"name": {
"description": "The name of the Storage Pool",
"type": "string",
"minLength": 1,
"pattern": "^[^/]*$",
"required": true,
"error": "KCHPOOL0016E"
},
"type": {
"description": "The type of the defined Storage Pool",
"type": "string",
"pattern": "^dir|netfs|logical|kimchi-iso|iscsi|scsi$",
"required": true,
"error": "KCHPOOL0017E"
},
"path": {
Expand Down Expand Up @@ -270,23 +275,28 @@
},
"storagevolume_update": {
"type": "object",
"required": [
"chunk",
"chunk_size"
],
"properties": {
"chunk": {
"description": "Upload storage volume chunk",
"error": "KCHVOL0024E",
"required": true
"error": "KCHVOL0024E"
},
"chunk_size": {
"description": "Chunk size of uploaded storage volume",
"type": "string",
"error": "KCHVOL0024E",
"required": true
"error": "KCHVOL0024E"
}
},
"additionalProperties": false
},
"vms_create": {
"type": "object",
"required": [
"template"
],
"error": "KCHVM0016E",
"properties": {
"name": {
Expand All @@ -309,7 +319,6 @@
"description": "The URI of a template to use when building a VM",
"type": "string",
"pattern": "^/plugins/kimchi/templates/(.*?)/?$",
"required": true,
"error": "KCHVM0012E"
},
"storagepool": {
Expand Down Expand Up @@ -430,11 +439,13 @@
},
"vm_migrate": {
"type": "object",
"required": [
"remote_host"
],
"properties": {
"remote_host": {
"description": "IP address or hostname of the remote server",
"type": "string",
"required": true,
"minLength": 1,
"error": "KCHVM0060E"
},
Expand All @@ -459,21 +470,23 @@
},
"networks_create": {
"type": "object",
"required": [
"name",
"connection"
],
"error": "KCHNET0016E",
"properties": {
"name": {
"description": "The name of the new network",
"type": "string",
"minLength": 1,
"pattern": "^[^/\"]*$",
"required": true,
"error": "KCHNET0011E"
},
"connection": {
"description": "Specifies how this network should be connected to the other networks",
"type": "string",
"pattern": "^isolated|nat|bridge|macvtap|vepa|passthrough$",
"required": true,
"error": "KCHNET0012E"
},
"subnet": {
Expand Down Expand Up @@ -529,13 +542,15 @@
},
"vmifaces_create": {
"type": "object",
"required": [
"type"
],
"error": "KCHVMIF0007E",
"properties": {
"type": {
"description": "The type of VM network interface that libvirt supports. Type 'macvtap' for host network interface (Ethernet, Bond, VLAN) to be connected as direct MacVTap or 'ovs' for openvswitch host network interface to be connected as virtual switch to a VM or 'network' for libvirt virtual network to be connected to VM. ",
"type": "string",
"pattern": "^network|macvtap|ovs$",
"required": true,
"error": "KCHVMIF0004E"
},
"network": {
Expand Down Expand Up @@ -582,6 +597,9 @@
},
"templates_create": {
"type": "object",
"required": [
"source_media"
],
"error": "KCHTMPL0016E",
"properties": {
"name": {
Expand Down Expand Up @@ -612,21 +630,22 @@
"memory": { "$ref": "#/kimchitype/memory" },
"source_media": {
"type" : "object",
"required": [
"type"
],
"properties" : {
"type": {
"description": "Type of source media: disk or netboot",
"type": "string",
"pattern": "^disk|netboot$",
"required": true
"pattern": "^disk|netboot$"
},
"path": {
"description": "Path for installation media (ISO, disk, remote ISO)",
"type": "string",
"pattern" : "^((/)|(http)[s]?:|[t]?(ftp)[s]?:)+.*$"
}
},
"additionalProperties": false,
"required": true
"additionalProperties": false
},
"disks": {
"description": "List of disks",
Expand Down Expand Up @@ -728,13 +747,15 @@
},
"vmstorages_create": {
"type": "object",
"required": [
"type"
],
"error": "KCHVMSTOR0012E",
"properties": {
"type": {
"description": "The storage type",
"type": "string",
"pattern": "^cdrom|disk$",
"required": true,
"error": "KCHVMSTOR0002E"
},
"pool": {
Expand All @@ -759,13 +780,15 @@
},
"vmstorage_update": {
"type": "object",
"required": [
"path"
],
"error": "KCHVMSTOR0013E",
"properties": {
"path": {
"description": "Path of iso image file or disk mount point",
"type": "string",
"pattern": "^(|(/)|(http)[s]?:|[t]?(ftp)[s]?:)+.*$",
"required": true,
"error": "KCHVMSTOR0003E"
}
},
Expand Down Expand Up @@ -909,12 +932,14 @@
},
"vmhostdevs_create": {
"type": "object",
"required": [
"name"
],
"properties": {
"name": {
"description": "Then name of the device to assign to VM",
"type": "string",
"pattern": "^[_A-Za-z0-9-]+$",
"required": true,
"error": "KCHVMHDEV0004E"
}
},
Expand Down
1 change: 0 additions & 1 deletion __init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,5 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

from wok.plugins.kimchi.root import Kimchi
__all__ = [Kimchi]
6 changes: 3 additions & 3 deletions config.py.in
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ config = get_config()
def find_qemu_binary(find_emulator=False):
try:
connect = libvirt.open(None)
except Exception, e:
except Exception as e:
raise Exception("Unable to get qemu binary location: %s" % e)
try:
xml = connect.getCapabilities()
Expand All @@ -91,7 +91,7 @@ def find_qemu_binary(find_emulator=False):
/domain[@type='kvm']/emulator" % arch
res = xpath_get_text(xml, expr)
location = res[0]
except Exception, e:
except Exception as e:
raise Exception("Unable to get qemu binary location: %s" % e)
finally:
connect.close()
Expand Down Expand Up @@ -161,7 +161,7 @@ class KimchiConfig(PluginConfig):
'tools.staticdir.dir':
get_virtviewerfiles_path(),
'tools.staticdir.on': True}}
for uri, data in static_config.iteritems():
for uri, data in static_config.items():
custom_config[uri] = {'tools.nocache.on': True,
'tools.wokauth.on': True}
path = data['path']
Expand Down
2 changes: 1 addition & 1 deletion configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ AS_IF([test "x$PACKAGE_RELEASE" = x],

AC_CONFIG_AUX_DIR([build-aux])
AM_INIT_AUTOMAKE([-Wno-portability])
AM_PATH_PYTHON([2.6])
AM_PATH_PYTHON([3.6])
AC_PATH_PROG([PEP8], [pep8], [/usr/bin/pep8])
AC_PATH_PROG([GIT], [git], [/usr/bin/git])
AC_PATH_PROG([RPMLINT], [rpmlint], [/usr/bin/rpmlint])
Expand Down
42 changes: 23 additions & 19 deletions contrib/check_i18n.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/usr/bin/env python2
#!/usr/bin/env python3
#
# Project Kimchi
#
Expand All @@ -17,36 +17,37 @@
# You should have received a copy of the GNU Lesser General Public
# License along with this library; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA

import imp
import os
import re
import sys


# Match all conversion specifier with mapping key
PATTERN = re.compile(r'''%\([^)]+\) # Mapping key
PATTERN = re.compile(
r"""%\([^)]+\) # Mapping key
[#0\-+]? # Conversion flags (optional)
(\d+|\*)? # Minimum field width (optional)
(\.(\d+|\*))? # Precision (optional)
[lLh]? # Length modifier (optional)
[cdeEfFgGioursxX%] # Conversion type''',
re.VERBOSE)
BAD_PATTERN = re.compile(r"%\([^)]*?\)")
[cdeEfFgGioursxX%] # Conversion type""",
re.VERBOSE,
)
BAD_PATTERN = re.compile(r'%\([^)]*?\)')


def load_i18n_module(i18nfile):
path = os.path.dirname(i18nfile)
mname = i18nfile.replace("./", "_").replace("/", "_").rstrip(".py")
mobj = imp.find_module("i18n", [path])
mname = i18nfile.replace('./', '_').replace('/', '_').rstrip('.py')
mobj = imp.find_module('i18n', [path])
return imp.load_module(mname, *mobj)


def check_string_formatting(messages):
for k, v in messages.iteritems():
if BAD_PATTERN.findall(PATTERN.sub(" ", v)):
print "bad i18n string formatting:"
print " %s: %s" % (k, v)
for k, v in messages.items():
if BAD_PATTERN.findall(PATTERN.sub(' ', v)):
print('bad i18n string formatting:')
print(f' {k}: {v}')
exit(1)


Expand All @@ -55,27 +56,30 @@ def find_message_key(path, k):
for root, dirs, files in os.walk(path):
for f in files:
fname = os.path.join(root, f)
if (not fname.endswith("i18n.py") and fname.endswith(".py") or
fname.endswith(".json")):
if (
not fname.endswith('i18n.py')
and fname.endswith('.py')
or fname.endswith('.json')
):
with open(fname) as f:
string = "".join(f.readlines())
string = ''.join(f.readlines())
if k in string:
return True
return False

for k in messages.iterkeys():
for k in messages.keys():
if not find_message_key(path, k):
print " %s is obsolete, it is no longer in use" % k
print(f' {k} is obsolete, it is no longer in use')
exit(1)


def main():
print "Checking for invalid i18n string..."
print('Checking for invalid i18n string...')
for f in sys.argv[1:]:
messages = load_i18n_module(f).messages
check_string_formatting(messages)
check_obsolete_messages(os.path.dirname(f), messages)
print "Checking for invalid i18n string successfully"
print('Checking for invalid i18n string successfully')


if __name__ == '__main__':
Expand Down
Loading

0 comments on commit 8334268

Please sign in to comment.