diff --git a/Makefile b/Makefile index a80b23db37..7bcc005dbd 100644 --- a/Makefile +++ b/Makefile @@ -4,7 +4,8 @@ DESTDIR ?= # E722 do not use bare 'except' PYIGNORE ?= E402,E722 -pysources = src/cosalib src/oscontainer.py src/cmd-kola +pysources = src/cosalib src/oscontainer.py src/cmd-kola $(py2sources) +py2sources = src/cmdlib.py src/cmd-koji-upload .PHONY: all check flake8 unittest clean mantle install @@ -20,7 +21,7 @@ cwd_checked:=$(patsubst ./%,.%.shellchecked,${cwd}) .%.shellchecked: % ./tests/check_one.sh $< $@ -check: ${src_checked} ${tests_checked} ${cwd_checked} flake8 +check: ${src_checked} ${tests_checked} ${cwd_checked} flake8 py2syntax echo OK flake8: @@ -30,6 +31,9 @@ flake8: # grep -r "^\#\!/usr/bin/py" src/ | cut -d : -f 1 | xargs flake8 --ignore=$(PYIGNORE) # find src -maxdepth 1 -name "*.py" | xargs flake8 --ignore=$(PYIGNORE) +py2syntax: + python -m py_compile $(py2sources) + unittest: PYTHONPATH=`pwd`/src python3 -m pytest tests/ diff --git a/src/cmd-koji-upload b/src/cmd-koji-upload index 4944c5ce01..18fa908910 100755 --- a/src/cmd-koji-upload +++ b/src/cmd-koji-upload @@ -279,7 +279,7 @@ class Build(_Build): continue # os.path.getsize uses 1kB instead of 1KB. So we use stat instead. - fsize = subprocess.check_output(["stat", "--dereference", "--format", '%s', lpath]) + fsize = '{}'.format(os.stat(lpath).st_size) log.debug(" * calculating checksum") self._found_files[lpath] = { "local_path": lpath, diff --git a/src/cmdlib.py b/src/cmdlib.py index c3927997db..10bf8b920a 100755 --- a/src/cmdlib.py +++ b/src/cmdlib.py @@ -9,11 +9,6 @@ import subprocess import sys import tempfile -import gi -import semver - -gi.require_version("RpmOstree", "1.0") -from gi.repository import RpmOstree from datetime import datetime @@ -101,7 +96,7 @@ def fatal(msg): :type msg: str :raises: SystemExit """ - print('fatal: {}'.format(msg), file=sys.stderr) + sys.stderr.write('fatal: {}\n'.format(msg)) raise SystemExit(1) @@ -112,7 +107,7 @@ def info(msg): :param msg: The message to show to output :type msg: str """ - print('info: {}'.format(msg), file=sys.stderr) + print('info: {}'.format(msg)) def rfc3339_time(t=None): @@ -166,14 +161,14 @@ def import_ostree_commit(repo, commit, tarfile): # in the common case where we're operating on a recent build, the OSTree # commit should already be in the tmprepo - commitpartial = os.path.join(repo, f'state/{commit}.commitpartial') - if (subprocess.call(['ostree', 'show', '--repo', repo, commit], - stdout=subprocess.DEVNULL, - stderr=subprocess.DEVNULL) == 0 - and not os.path.isfile(commitpartial)): + commitpartial = os.path.join(repo, 'state/{}.commitpartial'.format(commit)) + have_commit = subprocess.call(['ostree', 'show', '--repo', repo, commit], + stdout=subprocess.DEVNULL, + stderr=subprocess.DEVNULL) == 0 + if have_commit and not os.path.isfile(commitpartial): return - with tempfile.TemporaryDirectory(dir=f'{repo}/tmp') as d: + with tempfile.TemporaryDirectory(dir='{}/tmp'.format(repo)) as d: subprocess.check_call(['tar', '-C', d, '-xf', tarfile]) subprocess.check_call(['ostree', 'pull-local', '--repo', repo, d, commit]) @@ -183,6 +178,9 @@ def get_basearch(): try: return get_basearch.saved except AttributeError: + import gi + gi.require_version("RpmOstree", "1.0") + from gi.repository import RpmOstree get_basearch.saved = RpmOstree.get_basearch() return get_basearch.saved @@ -190,6 +188,7 @@ def get_basearch(): # FIXME: Add tests class Builds: # pragma: nocover def __init__(self, workdir=None): + import semver self._workdir = workdir self._fn = self._path("builds/builds.json") if not os.path.isdir(self._path("builds")): @@ -242,11 +241,11 @@ def get_build_dir(self, build_id, basearch=None): if build_id == 'latest': build_id = self.get_latest() if self._legacy: - return self._path(f"builds/{build_id}") + return self._path("builds/" + build_id) if not basearch: # just assume caller wants build dir for current arch basearch = get_basearch() - return self._path(f"builds/{build_id}/{basearch}") + return self._path("builds/{}/{}".format(build_id, basearch)) def insert_build(self, build_id, basearch=None): if self._legacy: