Address deprecated warnings with Python 3.8
All these chances work fine with 3.5, our minimally required version. Signed-off-by: Jan Kiszka <jan.kiszka@siemens.com>
This commit is contained in:
parent
e383e16570
commit
6a67d69411
@ -26,7 +26,8 @@
|
|||||||
"""
|
"""
|
||||||
|
|
||||||
import os
|
import os
|
||||||
from collections import OrderedDict, Mapping
|
from collections import OrderedDict
|
||||||
|
from collections.abc import Mapping
|
||||||
import functools
|
import functools
|
||||||
import logging
|
import logging
|
||||||
|
|
||||||
|
@ -63,14 +63,13 @@ class LogOutput:
|
|||||||
self.stderr.append(line)
|
self.stderr.append(line)
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def _read_stream(stream, callback):
|
||||||
def _read_stream(stream, callback):
|
|
||||||
"""
|
"""
|
||||||
This asynchronous method reads from the output stream of the
|
This asynchronous method reads from the output stream of the
|
||||||
application and transfers each line to the callback function.
|
application and transfers each line to the callback function.
|
||||||
"""
|
"""
|
||||||
while True:
|
while True:
|
||||||
line = yield from stream.readline()
|
line = await stream.readline()
|
||||||
try:
|
try:
|
||||||
line = line.decode('utf-8')
|
line = line.decode('utf-8')
|
||||||
except UnicodeDecodeError as err:
|
except UnicodeDecodeError as err:
|
||||||
@ -82,8 +81,7 @@ def _read_stream(stream, callback):
|
|||||||
break
|
break
|
||||||
|
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def run_cmd_async(cmd, cwd, env=None, fail=True, liveupdate=True):
|
||||||
def run_cmd_async(cmd, cwd, env=None, fail=True, liveupdate=True):
|
|
||||||
"""
|
"""
|
||||||
Run a command asynchronously.
|
Run a command asynchronously.
|
||||||
"""
|
"""
|
||||||
@ -95,7 +93,7 @@ def run_cmd_async(cmd, cwd, env=None, fail=True, liveupdate=True):
|
|||||||
logo = LogOutput(liveupdate)
|
logo = LogOutput(liveupdate)
|
||||||
|
|
||||||
try:
|
try:
|
||||||
process = yield from asyncio.create_subprocess_exec(
|
process = await asyncio.create_subprocess_exec(
|
||||||
*cmd,
|
*cmd,
|
||||||
cwd=cwd,
|
cwd=cwd,
|
||||||
env=env,
|
env=env,
|
||||||
@ -110,11 +108,11 @@ def run_cmd_async(cmd, cwd, env=None, fail=True, liveupdate=True):
|
|||||||
raise ex
|
raise ex
|
||||||
return (errno.EPERM, str(ex))
|
return (errno.EPERM, str(ex))
|
||||||
|
|
||||||
yield from asyncio.wait([
|
await asyncio.wait([
|
||||||
_read_stream(process.stdout, logo.log_stdout),
|
_read_stream(process.stdout, logo.log_stdout),
|
||||||
_read_stream(process.stderr, logo.log_stderr)
|
_read_stream(process.stderr, logo.log_stderr)
|
||||||
])
|
])
|
||||||
ret = yield from process.wait()
|
ret = await process.wait()
|
||||||
|
|
||||||
if ret and fail:
|
if ret and fail:
|
||||||
msg = 'Command "{cwd}$ {cmd}" failed'.format(cwd=cwd, cmd=cmdstr)
|
msg = 'Command "{cwd}$ {cmd}" failed'.format(cwd=cwd, cmd=cmdstr)
|
||||||
|
35
kas/repos.py
35
kas/repos.py
@ -25,7 +25,6 @@
|
|||||||
|
|
||||||
import re
|
import re
|
||||||
import os
|
import os
|
||||||
import asyncio
|
|
||||||
import logging
|
import logging
|
||||||
from urllib.parse import urlparse
|
from urllib.parse import urlparse
|
||||||
from .context import get_context
|
from .context import get_context
|
||||||
@ -154,8 +153,7 @@ class RepoImpl(Repo):
|
|||||||
Provides a generic implementation for a Repo.
|
Provides a generic implementation for a Repo.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def fetch_async(self):
|
||||||
def fetch_async(self):
|
|
||||||
"""
|
"""
|
||||||
Starts asynchronous repository fetch.
|
Starts asynchronous repository fetch.
|
||||||
"""
|
"""
|
||||||
@ -168,7 +166,7 @@ class RepoImpl(Repo):
|
|||||||
self.qualified_name)
|
self.qualified_name)
|
||||||
logging.debug('Looking for repo ref dir in %s', sdir)
|
logging.debug('Looking for repo ref dir in %s', sdir)
|
||||||
|
|
||||||
(retc, _) = yield from run_cmd_async(
|
(retc, _) = await run_cmd_async(
|
||||||
self.clone_cmd(sdir),
|
self.clone_cmd(sdir),
|
||||||
cwd=get_context().kas_work_dir)
|
cwd=get_context().kas_work_dir)
|
||||||
if retc == 0:
|
if retc == 0:
|
||||||
@ -178,7 +176,7 @@ class RepoImpl(Repo):
|
|||||||
# Make sure the remote origin is set to the value
|
# Make sure the remote origin is set to the value
|
||||||
# in the kas file to avoid suprises
|
# in the kas file to avoid suprises
|
||||||
try:
|
try:
|
||||||
(retc, output) = yield from run_cmd_async(
|
(retc, output) = await run_cmd_async(
|
||||||
self.set_remote_url_cmd(),
|
self.set_remote_url_cmd(),
|
||||||
cwd=self.path,
|
cwd=self.path,
|
||||||
fail=False,
|
fail=False,
|
||||||
@ -196,19 +194,19 @@ class RepoImpl(Repo):
|
|||||||
return 0
|
return 0
|
||||||
|
|
||||||
# Does refspec exist in the current repository?
|
# Does refspec exist in the current repository?
|
||||||
(retc, output) = yield from run_cmd_async(self.contains_refspec_cmd(),
|
(retc, output) = await run_cmd_async(self.contains_refspec_cmd(),
|
||||||
cwd=self.path,
|
cwd=self.path,
|
||||||
fail=False,
|
fail=False,
|
||||||
liveupdate=False)
|
liveupdate=False)
|
||||||
if retc == 0:
|
if retc == 0:
|
||||||
logging.info('Repository %s already contains %s as %s',
|
logging.info('Repository %s already contains %s as %s',
|
||||||
self.name, self.refspec, output.strip())
|
self.name, self.refspec, output.strip())
|
||||||
return retc
|
return retc
|
||||||
|
|
||||||
# No it is missing, try to fetch
|
# No it is missing, try to fetch
|
||||||
(retc, output) = yield from run_cmd_async(self.fetch_cmd(),
|
(retc, output) = await run_cmd_async(self.fetch_cmd(),
|
||||||
cwd=self.path,
|
cwd=self.path,
|
||||||
fail=False)
|
fail=False)
|
||||||
if retc:
|
if retc:
|
||||||
logging.warning('Could not update repository %s: %s',
|
logging.warning('Could not update repository %s: %s',
|
||||||
self.name, output)
|
self.name, output)
|
||||||
@ -242,16 +240,15 @@ class RepoImpl(Repo):
|
|||||||
|
|
||||||
run_cmd(self.checkout_cmd(), cwd=self.path)
|
run_cmd(self.checkout_cmd(), cwd=self.path)
|
||||||
|
|
||||||
@asyncio.coroutine
|
async def apply_patches_async(self):
|
||||||
def apply_patches_async(self):
|
|
||||||
"""
|
"""
|
||||||
Applies patches to a repository asynchronously.
|
Applies patches to a repository asynchronously.
|
||||||
"""
|
"""
|
||||||
if self.operations_disabled or not self._patches:
|
if self.operations_disabled or not self._patches:
|
||||||
return 0
|
return 0
|
||||||
|
|
||||||
(retc, _) = yield from run_cmd_async(self.prepare_patches_cmd(),
|
(retc, _) = await run_cmd_async(self.prepare_patches_cmd(),
|
||||||
cwd=self.path)
|
cwd=self.path)
|
||||||
if retc:
|
if retc:
|
||||||
return retc
|
return retc
|
||||||
|
|
||||||
@ -296,7 +293,7 @@ class RepoImpl(Repo):
|
|||||||
|
|
||||||
for path in my_patches:
|
for path in my_patches:
|
||||||
cmd = self.apply_patches_file_cmd(path)
|
cmd = self.apply_patches_file_cmd(path)
|
||||||
(retc, output) = yield from run_cmd_async(cmd, cwd=self.path)
|
(retc, output) = await run_cmd_async(cmd, cwd=self.path)
|
||||||
if retc:
|
if retc:
|
||||||
logging.error('Could not apply patch. Please fix repos and '
|
logging.error('Could not apply patch. Please fix repos and '
|
||||||
'patches. (patch path: %s, repo: %s, patch '
|
'patches. (patch path: %s, repo: %s, patch '
|
||||||
@ -309,7 +306,7 @@ class RepoImpl(Repo):
|
|||||||
path, self.name, patch['id'])
|
path, self.name, patch['id'])
|
||||||
|
|
||||||
cmd = self.add_cmd()
|
cmd = self.add_cmd()
|
||||||
(retc, output) = yield from run_cmd_async(cmd, cwd=self.path)
|
(retc, output) = await run_cmd_async(cmd, cwd=self.path)
|
||||||
if retc:
|
if retc:
|
||||||
logging.error('Could not add patched files. '
|
logging.error('Could not add patched files. '
|
||||||
'repo: %s, vcs output: %s)',
|
'repo: %s, vcs output: %s)',
|
||||||
@ -317,7 +314,7 @@ class RepoImpl(Repo):
|
|||||||
return 1
|
return 1
|
||||||
|
|
||||||
cmd = self.commit_cmd()
|
cmd = self.commit_cmd()
|
||||||
(retc, output) = yield from run_cmd_async(cmd, cwd=self.path)
|
(retc, output) = await run_cmd_async(cmd, cwd=self.path)
|
||||||
if retc:
|
if retc:
|
||||||
logging.error('Could not commit patch changes. '
|
logging.error('Could not commit patch changes. '
|
||||||
'repo: %s, vcs output: %s)',
|
'repo: %s, vcs output: %s)',
|
||||||
|
Loading…
Reference in New Issue
Block a user