Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python cleanup #69

Open
wants to merge 8 commits into
base: master
Choose a base branch
from
Open
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
6 changes: 3 additions & 3 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@

sys.path.insert(0, os.path.abspath('..'))

import setup as lago_setup # flake8: noqa
import setup as lago_setup # noqa: E402
subprocess.call(
[
'sphinx-apidoc', '--module-first', '--no-toc', '-f', '-o',
Expand Down Expand Up @@ -183,8 +183,8 @@
# html_logo = None

# The name of an image file (relative to this directory) to use as a favicon of
# the docs. This file should be a Windows icon file (.ico) being 16x16 or 32x32
# pixels large.
# the docs. This file should be a Windows icon file (.ico) being 16x16 or
# 32x32 pixels large.
#
# html_favicon = None

Expand Down
4 changes: 2 additions & 2 deletions ovirtlago/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@
#
# Refer to the README and COPYING files for full details of the license
#
from __future__ import absolute_import

import logging
import os
import pkg_resources
Expand All @@ -38,8 +40,6 @@
prefix_class=OvirtPrefix,
workdir_class=OvirtWorkdir,
)
# TODO: Remove this, and properly complain on unset config values
DISTS = ['el6', 'el7', 'fc20']


@cli_plugin(
Expand Down
9 changes: 4 additions & 5 deletions ovirtlago/virt.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
from collections import OrderedDict
from lago.config import config as lago_config
from ovirtlago import utils
from utils import partial
from .utils import partial

import ovirtsdk.api
from ovirtsdk.infrastructure.errors import (RequestError, ConnectionError)
Expand Down Expand Up @@ -142,13 +142,12 @@ def get_ovirt_cpu_family(self, host=None):
raise RuntimeError(
('Unsupported CPU vendor: {0}. '
'Supported vendors: '
'{1}').format(host.cpu_vendor, ','.join(cpu_map.iterkeys()))
'{1}').format(host.cpu_vendor, ','.join(cpu_map))
)
if not cpu_map[host.cpu_vendor].get(host.cpu_model):
raise RuntimeError(
('Unsupported CPU model: {0}. Supported models: {1}').format(
host.cpu_model,
','.join(cpu_map[host.cpu_vendor].iterkeys())
host.cpu_model, ','.join(cpu_map[host.cpu_vendor])
)
)
return cpu_map[host.cpu_vendor][host.cpu_model]
Expand Down Expand Up @@ -532,7 +531,7 @@ def status(self):
]
)

for k, v in vars(sys_service.summary).viewitems():
for k, v in vars(sys_service.summary).items():
if isinstance(v, otypes.ApiSummaryItem):
info['items'][k.lstrip('_')] = OrderedDict(
[
Expand Down
58 changes: 31 additions & 27 deletions scripts/version_manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,15 +49,15 @@ def get_bzs_from_commit_msg(commit_msg):


def pretty_commit(commit, version=''):
subject = commit.message.split('\n', 1)[0] # noqa
subject = commit.message.decode('utf-8').split('\n', 1)[0] # noqa
short_hash = commit.sha().hexdigest()[:8] # noqa
author_date = datetime.datetime.fromtimestamp( # noqa
int(commit.commit_time)
).strftime('%a %b %d %Y')
author = commit.author # noqa
if version:
version = ' - ' + version
bugs = get_bzs_from_commit_msg(commit.message)
bugs = get_bzs_from_commit_msg(commit.message.decode('utf-8'))
changelog_message = fit_to_cols( # noqa
'{short_hash}: {subject}'.format(**vars()),
indent=' ',
Expand All @@ -70,18 +70,20 @@ def pretty_commit(commit, version=''):
else:
changelog_bugs = '' # noqa
return (
('* {author_date} {author}{version}\n' if version is not None else '')
+ '{changelog_message}\n' + '{changelog_bugs}'
('* {author_date} {author}{version}\n'
if version is not None else '') + '{changelog_message}\n' +
'{changelog_bugs}'
).format(**vars())


def get_tags(repo):
return {
commit: os.path.basename(tag_ref)
for tag_ref, commit in repo.get_refs().items()
if tag_ref.startswith('refs/tags/')
and VALID_TAG.match(tag_ref[len('refs/tags/'):])
}
tags = {}
for tag_ref, commit in repo.get_refs().items():
tag_ref = tag_ref.decode('utf-8')
if tag_ref.startswith('refs/tags/') \
and VALID_TAG.match(tag_ref[len('refs/tags/'):]):
tags[commit] = os.path.basename(tag_ref)
return tags


def get_refs(repo):
Expand Down Expand Up @@ -116,6 +118,16 @@ def get_children_per_parent(repo_path):
return children_per_parent


def append_parent(parents, commit, add_parent=True, add_digest=True):
if add_digest:
hexdigest = commit.sha().hexdigest().encode('utf-8')
if hexdigest not in parents:
parents.append(hexdigest)
if add_parent:
if commit.parents[0] not in parents:
parents.append(commit.parents[0])


def get_first_parents(repo_path):
repo = dulwich.repo.Repo(repo_path)
#: these are the commits that are parents of more than one other commit
Expand All @@ -125,22 +137,14 @@ def get_first_parents(repo_path):
for entry in repo.get_walker(order=dulwich.walk.ORDER_TOPO):
commit = entry.commit
if not commit.parents:
if commit.sha().hexdigest() not in first_parents:
first_parents.append(commit.sha().hexdigest())
append_parent(first_parents, commit, add_parent=False)
elif len(commit.parents) == 1 and not on_merge:
if commit.sha().hexdigest() not in first_parents:
first_parents.append(commit.sha().hexdigest())
if commit.parents[0] not in first_parents:
first_parents.append(commit.parents[0])
append_parent(first_parents, commit)
elif len(commit.parents) > 1 and not on_merge:
on_merge = True
if commit.sha().hexdigest() not in first_parents:
first_parents.append(commit.sha().hexdigest())
if commit.parents[0] not in first_parents:
first_parents.append(commit.parents[0])
append_parent(first_parents, commit)
elif commit.parents and commit.sha().hexdigest() in first_parents:
if commit.parents[0] not in first_parents:
first_parents.append(commit.parents[0])
append_parent(first_parents, commit, add_digest=False)

return first_parents

Expand All @@ -154,7 +158,7 @@ def has_firstparent_child(sha, first_parents, parents_per_child):
def get_merged_commits(repo, commit, first_parents, children_per_parent):
merge_children = set()

to_explore = set([commit.sha().hexdigest()])
to_explore = set([commit.sha().hexdigest().encode('utf-8')])

while to_explore:
next_sha = to_explore.pop()
Expand Down Expand Up @@ -200,18 +204,18 @@ def get_children_per_first_parent(repo_path):


def get_version(commit, tags, maj_version=0, feat_version=0, fix_version=0):
commit_sha = commit.sha().hexdigest()
commit_sha = commit.sha().hexdigest().encode('utf-8')

if commit_sha in tags:
maj_version, feat_version = tags[commit_sha].split('.')
maj_version = int(maj_version)
feat_version = int(feat_version)
fix_version = 0
elif MAJOR_HEADER.search(commit.message):
elif MAJOR_HEADER.search(commit.message.decode('utf-8')):
maj_version += 1
feat_version = 0
fix_version = 0
elif FEAT_HEADER.search(commit.message):
elif FEAT_HEADER.search(commit.message.decode('utf-8')):
feat_version += 1
fix_version = 0
else:
Expand Down Expand Up @@ -334,4 +338,4 @@ def main(args):

if __name__ == '__main__':

print main(sys.argv[1:])
print(main(sys.argv[1:]))