1
0
mirror of https://github.com/GNS3/gns3-server synced 2024-12-25 00:08:11 +00:00

Fix RuntimeWarning: You have iterated over the result of

pkg_resources.parse_version. This is a legacy behavior

Fix #504
This commit is contained in:
Julien Duponchelle 2016-05-02 17:13:23 +02:00
parent 978ec1b5be
commit d952718f30
No known key found for this signature in database
GPG Key ID: CE8B29639E07F5E8
12 changed files with 56 additions and 11 deletions

View File

@ -24,7 +24,7 @@ import tempfile
import psutil
import platform
from pkg_resources import parse_version
from gns3server.utils import parse_version
from ..utils.asyncio import wait_run_in_executor
from ..ubridge.hypervisor import Hypervisor
from .vm_error import VMError

View File

@ -24,7 +24,7 @@ import logging
import aiohttp
import urllib
import json
from pkg_resources import parse_version
from gns3server.utils import parse_version
log = logging.getLogger(__name__)

View File

@ -34,7 +34,7 @@ log = logging.getLogger(__name__)
from gns3server.utils.interfaces import interfaces, is_interface_up
from gns3server.utils.asyncio import wait_run_in_executor
from pkg_resources import parse_version
from gns3server.utils import parse_version
from uuid import UUID, uuid4
from ..base_manager import BaseManager
from ..project_manager import ProjectManager

View File

@ -21,7 +21,7 @@ http://github.com/GNS3/dynamips/blob/master/README.hypervisor#L558
"""
import asyncio
from pkg_resources import parse_version
from gns3server.utils import parse_version
from .device import Device
from ..nios.nio_udp import NIOUDP

View File

@ -30,7 +30,7 @@ import asyncio
import socket
import gns3server
from pkg_resources import parse_version
from gns3server.utils import parse_version
from .qemu_error import QemuError
from ..adapters.ethernet_adapter import EthernetAdapter
from ..nios.nio_udp import NIOUDP

View File

@ -28,7 +28,7 @@ import json
import socket
import asyncio
from pkg_resources import parse_version
from gns3server.utils import parse_version
from gns3server.utils.telnet_server import TelnetServer
from gns3server.utils.asyncio import wait_for_file_creation, wait_for_named_pipe_creation
from .virtualbox_error import VirtualBoxError

View File

@ -31,7 +31,7 @@ import codecs
from collections import OrderedDict
from gns3server.utils.interfaces import interfaces
from gns3server.utils.asyncio import subprocess_check_output
from pkg_resources import parse_version
from gns3server.utils import parse_version
log = logging.getLogger(__name__)

View File

@ -31,7 +31,7 @@ import shutil
from ...utils.asyncio import wait_for_process_termination
from ...utils.asyncio import monitor_process
from ...utils.asyncio import subprocess_check_output
from pkg_resources import parse_version
from gns3server.utils import parse_version
from .vpcs_error import VPCSError
from ..adapters.ethernet_adapter import EthernetAdapter
from ..nios.nio_udp import NIOUDP

View File

@ -25,7 +25,7 @@ import asyncio
import socket
import re
from pkg_resources import parse_version
from gns3server.utils import parse_version
from gns3server.utils.asyncio import wait_for_process_termination
from gns3server.utils.asyncio import subprocess_check_output
from .ubridge_hypervisor import UBridgeHypervisor

View File

@ -16,6 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
import re
import textwrap
import posixpath
@ -44,3 +45,32 @@ def int_to_macaddress(integer):
Convert an integer to a macaddress
"""
return ":".join(textwrap.wrap("%012x" % (integer), width=2))
def parse_version(version):
"""
Return a comparable tuple from a version string.
Replace pkg_resources.parse_version which now display a warning when use for comparing version with tuple
:returns: Version string as comparable tuple
"""
release_type_found = False
version_infos = re.split('(\.|[a-z]+)', version)
version = []
for info in version_infos:
if info == '.' or len(info) == 0:
continue
try:
info = int(info)
version.append(info)
except ValueError:
# We want rc to be at lower level than dev version
if info == 'rc':
info = 'c'
version.append(info)
release_type_found = True
if release_type_found is False:
version.append("final")
return tuple(version)

View File

@ -22,7 +22,7 @@ import os
import sys
from tests.utils import asyncio_patch
from pkg_resources import parse_version
from gns3server.utils import parse_version
from unittest.mock import patch, MagicMock
from gns3server.modules.vpcs.vpcs_vm import VPCSVM

View File

@ -16,7 +16,7 @@
# along with this program. If not, see <http://www.gnu.org/licenses/>.
from gns3server.utils import force_unix_path, macaddress_to_int, int_to_macaddress
from gns3server.utils import *
def test_force_unix_path():
@ -31,3 +31,18 @@ def test_macaddress_to_int():
def test_int_to_macaddress():
assert int_to_macaddress(52228632586) == "00:0c:29:11:b0:0a"
def test_parse_version():
assert parse_version('1') == (1, 'final')
assert parse_version('1.3') == (1, 3, 'final')
assert parse_version('1.3.dev3') == (1, 3, 'dev', 3)
assert parse_version('1.3a1') == (1, 3, 'a', 1)
assert parse_version('1.3rc1') == (1, 3, 'c', 1)
assert parse_version('1.2.3') > parse_version('1.2.2')
assert parse_version('1.3') > parse_version('1.2.2')
assert parse_version('1.3') > parse_version('1.3alpha1')
assert parse_version('1.3') > parse_version('1.3rc1')
assert parse_version('1.3rc1') > parse_version('1.3alpha3')
assert parse_version('1.3dev1') > parse_version('1.3rc1')