Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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:
Expand All @@ -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/

Expand Down
2 changes: 1 addition & 1 deletion src/cmd-koji-upload
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

log.debug(" * calculating checksum")
self._found_files[lpath] = {
"local_path": lpath,
Expand Down
29 changes: 14 additions & 15 deletions src/cmdlib.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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))
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

raise SystemExit(1)


Expand All @@ -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):
Expand Down Expand Up @@ -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])
Expand All @@ -183,13 +178,17 @@ def get_basearch():
try:
return get_basearch.saved
except AttributeError:
import gi
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think we disable flake8 checking for imports within code so this should be fine. I am personally a fan of importing optional items when needed like this 👍

gi.require_version("RpmOstree", "1.0")
from gi.repository import RpmOstree
get_basearch.saved = RpmOstree.get_basearch()
return get_basearch.saved


# 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")):
Expand Down Expand Up @@ -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:
Expand Down