Commit 866bb9c1 authored by Christos Stavrakakis's avatar Christos Stavrakakis
Browse files

Various fixes

parent 10a9cf64
......@@ -37,6 +37,9 @@ import sys
from sh import mktemp, cd, rm, git_dch, python
from optparse import OptionParser
from devflow.versioning import (get_python_version,
debian_version_from_python_version)
try:
from colors import red, green
except ImportError:
......@@ -55,9 +58,8 @@ PACKAGES = ("devflow", )
def main():
from devflow.version import __version__
parser = OptionParser(usage="usage: %prog [options] mode",
version="%prog - devflow %s" % __version__)
version="devflow %s" % __version__)
parser.add_option("-k", "--keep-repo",
action="store_true",
dest="keep_repo",
......@@ -79,7 +81,11 @@ def main():
(options, args) = parser.parse_args()
mode = args[0]
try:
mode = args[0]
except IndexError:
raise ValueError("Mode argument is mandatory. Usage: %s"
% parser.usage)
if mode not in AVAILABLE_MODES:
raise ValueError(red("Invalid argument! Mode must be one: %s"
% ", ".join(AVAILABLE_MODES)))
......@@ -118,11 +124,7 @@ def main():
repo.references[debian_branch]
except IndexError:
# Branch does not exist
# FIXME: remove hard-coded strings..
if branch == "debian":
repo.git.branch("--track", debian_branch, "origin/debian")
else:
repo.git.branch("--track", debian_branch, "origin/debian-develop")
repo.git.branch("--track", debian_branch, "origin/" + debian_branch)
repo.git.checkout(debian_branch)
print_green("Changed to branch '%s'" % debian_branch)
......@@ -131,32 +133,37 @@ def main():
print_green("Merged branch '%s' into '%s'" % (branch, debian_branch))
cd(repo_dir)
version = python(repo_dir + "/devflow/version.py", "debian").strip()
print_green("The new debian version will be: '%s'" % version)
python_version = get_python_version()
debian_version = debian_version_from_python_version(python_version)
print_green("The new debian version will be: '%s'" % debian_version)
dch = git_dch("--debian-branch=%s" % debian_branch,
"--git-author",
"--ignore-regex=\".*\"",
"--multimaint-merge",
"--since=HEAD",
"--new-version=%s" % version)
"--new-version=%s" % debian_version)
print_green("Successfully ran '%s'" % " ".join(dch.cmd))
os.system("vim debian/changelog")
repo.git.add("debian/changelog")
if mode == "release":
os.system("vim debian/changelog")
repo.git.add("debian/changelog")
repo.git.commit("-s", "-a", "-m", "Bump new upstream version")
if branch == "master":
repo.git.tag("debian/" + version)
python_tag = python_version
debian_tag = "debian/" + python_tag
repo.git.tag(debian_tag)
repo.git.tag(python_tag, branch)
for package in PACKAGES:
# python setup.py should run in its directory
cd(package)
package_dir = repo_dir + "/" + package
res = python(package_dir + "/setup.py", "sdist", _out=sys.stdout)
cd("../")
print res.stdout
if package != ".":
cd("../")
# Add version.py files to repo
os.system("grep \"__version_vcs\" -r . -l -I | xargs git add -f")
......@@ -167,6 +174,7 @@ def main():
print_green("Created directory '%s' to store the .deb files." %
build_dir)
cd(repo_dir)
os.system("git-buildpackage --git-export-dir=%s --git-upstream-branch=%s"
" --git-debian-branch=%s --git-export=INDEX --git-ignore-new -sa"
% (build_dir, branch, debian_branch))
......@@ -178,7 +186,23 @@ def main():
print_green("Repository dir '%s'" % repo_dir)
print_green("Completed. Version '%s', build area: '%s'"
% (version, build_dir))
% (debian_version, build_dir))
if mode == "release":
TAG_MSG = "Tagged branch %s with tag %s\n"
print_green(TAG_MSG % (branch, python_tag))
print_green(TAG_MSG % (debian_branch, debian_tag))
UPDATE_MSG = "To update repository %s, go to %s, and run the"\
" following commands:\n" + "git_push origin %s\n" * 3
origin_url = repo.remotes['origin'].url
remote_url = original_repo.remotes['origin'].url
print_green(UPDATE_MSG % (origin_url, repo_dir, debian_branch,
debian_tag, python_tag))
print_green(UPDATE_MSG % (remote_url, original_repo.working_dir,
debian_branch, debian_tag, python_tag))
if __name__ == "__main__":
......
......@@ -83,7 +83,7 @@ def get_commit_id(commit, current_branch):
elif len(parents) == 2:
if cur_br_name.startswith("debian-") or cur_br_name == "debian":
pr1, pr2 = parents
return short_id(pr1) + "~" + short_id(pr2)
return short_id(pr1) + "-" + short_id(pr2)
else:
return short_id(commit)
else:
......@@ -107,7 +107,6 @@ def vcs_info():
branch = repo.head.reference
revid = get_commit_id(branch.commit, branch)
revno = len(list(repo.iter_commits()))
desc = repo.git.describe("--tags")
toplevel = repo.working_dir
except git.InvalidGitRepositoryError:
log.error("Could not retrieve git information. " +
......@@ -115,9 +114,9 @@ def vcs_info():
return None
info = namedtuple("vcs_info", ["branch", "revid", "revno",
"desc", "toplevel"])
"toplevel"])
return info(branch=branch.name, revid=revid, revno=revno, desc=desc,
return info(branch=branch.name, revid=revid, revno=revno,
toplevel=toplevel)
......@@ -137,9 +136,12 @@ def build_mode():
try:
mode = os.environ["GITFLOW_BUILD_MODE"]
assert mode == "release" or mode == "snapshot"
except (KeyError, AssertionError):
raise ValueError("GITFLOW_BUILD_MODE environment variable must be "
"'release' or 'snapshot'")
except KeyError:
raise ValueError("GITFLOW_BUILD_MODE environment variable is not set."
" Set this variable to 'release' or 'snapshot'")
except AssertionError:
raise ValueError("GITFLOW_BUILD_MODE environment variable must be"
" 'release' or 'snapshot'")
return mode
......@@ -390,11 +392,25 @@ def debian_version_from_python_version(pyver):
return pyver.replace("_", "~").replace("rc", "~rc") + "-1"
def get_python_version():
v = vcs_info()
b = base_version(v)
mode = build_mode()
return python_version(b, v, mode)
def debian_version(base_version, vcs_info, mode):
p = python_version(base_version, vcs_info, mode)
return debian_version_from_python_version(p)
def get_debian_version():
v = vcs_info()
b = base_version(v)
mode = build_mode()
return debian_version(b, v, mode)
def user_info():
import getpass
import socket
......@@ -410,30 +426,34 @@ def update_version(module, name="version", root="."):
"""
paths = [root] + module.split(".") + ["%s.py" % name]
module_filename = os.path.join(*paths)
v = vcs_info()
if not v:
# Return early if not in development environment
log.error("Can not compute version outside of a git repository."
" Will not update %s version file" % module_filename)
return
b = base_version(v)
mode = build_mode()
paths = [root] + module.split(".") + ["%s.py" % name]
module_filename = os.path.join(*paths)
version = python_version(b, v, mode)
content = """
__version__ = "%(version)s"
__version_info__ = %(version_info)s
__version_vcs_info__ = %(vcs_info)s
__version_user_info__ = "%(user_info)s"
""" % dict(version=version, version_info=version.split("."),
""" % dict(version=version, version_info=version.split("."),
vcs_info=pprint.PrettyPrinter().pformat(dict(v._asdict())),
user_info=user_info())
module_file = file(module_filename, "w+")
module_file.write(content)
module_file.close()
return module_filename
if __name__ == "__main__":
def main():
v = vcs_info()
b = base_version(v)
mode = build_mode()
......@@ -448,3 +468,6 @@ if __name__ == "__main__":
print python_version(b, v, mode)
elif arg == "debian":
print debian_version(b, v, mode)
if __name__ == "__main__":
sys.exit(main())
# Copyright 2011 GRNET S.A. All rights reserved.
# Copyright 2012 GRNET S.A. All rights reserved.
#
# Redistribution and use in source and binary forms, with or
# without modification, are permitted provided that the following
......@@ -31,7 +31,6 @@
# interpreted as representing official policies, either expressed
# or implied, of GRNET S.A.
#
import distribute_setup
distribute_setup.use_setuptools()
......@@ -43,13 +42,15 @@ from fnmatch import fnmatchcase
from setuptools import setup, find_packages
HERE = os.path.abspath(os.path.normpath(os.path.dirname(__file__)))
try:
from devflow import versioning
# use devflow to update the version file
from devflow.versioning import update_version
update_version('devflow', 'version', HERE)
versioning.update_version('devflow', 'version', HERE)
except ImportError:
raise RuntimeError("devflow is a build dependency")
version_fpath = os.path.join(HERE, 'devflow', 'version.py')
sys.stdout.write("WARNING: Can not update version because `devflow` is"
" not installed. Please make sure to manually"
" update version file %s" % version_fpath)
from devflow.version import __version__
......@@ -67,7 +68,7 @@ CLASSIFIERS = []
# Package requirements
INSTALL_REQUIRES = [
'git'
'gitpython'
]
# Provided as an attribute, so you can append to these instead
......@@ -141,7 +142,8 @@ def find_package_data(
new_package = package + "." + name
stack.append((fn, "", new_package, False))
else:
stack.append((fn, prefix + name + "/", package, only_in_packages))
stack.append((fn, prefix + name + "/", package,
only_in_packages))
elif package or not only_in_packages:
# is a file
bad_name = False
......@@ -156,34 +158,35 @@ def find_package_data(
break
if bad_name:
continue
out.setdefault(package, []).append(prefix+name)
out.setdefault(package, []).append(prefix + name)
return out
setup(
name = 'devflow',
version = VERSION,
license = 'BSD',
url = 'http://www.synnefo.ogr/',
description = SHORT_DESCRIPTION,
long_description=README + '\n\n' + CHANGES,
classifiers = CLASSIFIERS,
author = 'GRNET dev team',
author_email = 'okeanos-dev@lists.grnet.gr',
maintainer = 'GRNET dev team',
maintainer_email = 'okeanos-dev@lists.grnet.gr',
packages = PACKAGES,
package_dir= {'': PACKAGES_ROOT},
include_package_data = True,
package_data = find_package_data('.'),
zip_safe = False,
install_requires = INSTALL_REQUIRES,
entry_points = {
name='devflow',
version=VERSION,
license='BSD',
url='http://www.synnefo.ogr/',
description=SHORT_DESCRIPTION,
long_description=README + '\n\n' + CHANGES,
classifiers=CLASSIFIERS,
author='GRNET dev team',
author_email='okeanos-dev@lists.grnet.gr',
maintainer='GRNET dev team',
maintainer_email='okeanos-dev@lists.grnet.gr',
packages=PACKAGES,
package_dir={'': PACKAGES_ROOT},
include_package_data=True,
package_data=find_package_data('.'),
zip_safe=False,
install_requires=INSTALL_REQUIRES,
entry_points={
'console_scripts': [
'devflow-version = devflow.versioning:main',
'devflow-version=devflow.versioning:main',
'devflow-autopkg=devflow.autopkg:main',
],
},
)
......@@ -45,7 +45,7 @@ for automatic generation of version strings.
import os
import unittest
from pkg_resources import parse_version
from versioning import debian_version_from_python_version
from devflow.versioning import debian_version_from_python_version
class DebianVersionObject(object):
......
0.1next
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment