Merge pull request #111 from jumanjiman/python3_alpha

alpha support for python3
This commit is contained in:
Devan Goodwin 2014-03-11 11:50:24 -03:00
commit 78a0d98e70
7 changed files with 48 additions and 21 deletions

View file

@ -90,7 +90,7 @@ class ConfigLoader(object):
# Load the global config. Later, when we know what tag/package we're
# building, we may also load that and potentially override some global
# settings.
config = ConfigParser()
config = RawConfigParser()
config.read(filename)
self._check_legacy_globalconfig(config)
@ -492,7 +492,7 @@ class ReleaseModule(BaseCliModule):
"""
rel_eng_dir = os.path.join(find_git_root(), "rel-eng")
filename = os.path.join(rel_eng_dir, RELEASERS_CONF_FILENAME)
config = ConfigParser()
config = RawConfigParser()
config.read(filename)
return config

View file

@ -541,7 +541,7 @@ def create_tgz(git_root, prefix, commit, relative_dir,
'%s > /dev/null' % git_archive_cmd)
# If we're still alive, the previous command worked
archive_cmd = ('%s | %s %s %s | gzip -n -c - | tee %s' % (
archive_cmd = ('%s | %s %s %s | gzip -n -c - > %s' % (
git_archive_cmd, timestamp_script,
timestamp, commit, dest_tgz))
debug(archive_cmd)

View file

@ -13,18 +13,20 @@
"""
Compatibility library for Python 2.4 up through Python 3.
"""
import os
import sys
ENCODING = sys.getdefaultencoding()
PY2 = sys.version_info[0] == 2
if PY2:
import commands
from ConfigParser import ConfigParser
from ConfigParser import NoOptionError
from ConfigParser import RawConfigParser
from StringIO import StringIO
else:
import subprocess
from configparser import ConfigParser
from configparser import NoOptionError
from configparser import RawConfigParser
from io import StringIO
def getstatusoutput(cmd):
@ -44,3 +46,26 @@ def getoutput(cmd):
Supports Python 2.4 and 3.x.
"""
return getstatusoutput(cmd)[1]
def dictionary_override(d1, d2):
"""
Return a new dictionary object where
d2 elements override d1 elements.
"""
if PY2:
overrides = d1.items() + d2.items()
else:
overrides = d1.items() | d2.items()
return dict(overrides)
def write(fd, str):
"""
A version of os.write that
supports Python 2.4 and 3.x.
"""
if PY2:
os.write(fd, str)
else:
os.write(fd, bytes(str, ENCODING))

View file

@ -71,8 +71,11 @@ class Releaser(ConfigObject):
# Override with builder args from command line if any were given:
if 'builder_args' in kwargs:
self.builder_args = dict(config_builder_args.items() +
kwargs['builder_args'].items())
# (in case of dupes, last one wins)
self.builder_args = dictionary_override(
config_builder_args,
kwargs['builder_args']
)
else:
self.builder_args = config_builder_args
@ -487,11 +490,11 @@ class FedoraGitReleaser(Releaser):
fd, name = tempfile.mkstemp()
debug("Storing commit message in temp file: %s" % name)
os.write(fd, "Update %s to %s\n" % (self.project_name,
write(fd, "Update %s to %s\n" % (self.project_name,
self.builder.build_version))
# Write out Resolves line for all bugzillas we see in commit diff:
for line in extract_bzs(diff_output):
os.write(fd, line + "\n")
write(fd, line + "\n")
print("")
print("##### Commit message: #####")

View file

@ -70,11 +70,11 @@ class ObsReleaser(Releaser):
fd, name = tempfile.mkstemp()
debug("Storing commit message in temp file: %s" % name)
os.write(fd, "Update %s to %s\n" % (self.obs_package_name,
write(fd, "Update %s to %s\n" % (self.obs_package_name,
self.builder.build_version))
# Write out Resolves line for all bugzillas we see in commit diff:
for line in extract_bzs(diff_output):
os.write(fd, line + "\n")
write(fd, line + "\n")
print("")
print("##### Commit message: #####")

View file

@ -17,7 +17,6 @@ Code for tagging Spacewalk/Satellite packages.
import os
import re
import rpm
import StringIO
import shutil
import subprocess
import tempfile
@ -227,7 +226,7 @@ class VersionTagger(ConfigObject):
output = self._new_changelog_msg
fd, name = tempfile.mkstemp()
os.write(fd, "# Create your changelog entry below:\n")
write(fd, "# Create your changelog entry below:\n")
if self.git_email is None or (('HIDE_EMAIL' in self.user_config) and
(self.user_config['HIDE_EMAIL'] not in ['0', ''])):
header = "* %s %s\n" % (self.today, self.git_user)
@ -235,14 +234,14 @@ class VersionTagger(ConfigObject):
header = "* %s %s <%s>\n" % (self.today, self.git_user,
self.git_email)
os.write(fd, header)
write(fd, header)
for cmd_out in output.split("\n"):
os.write(fd, "- ")
os.write(fd, "\n ".join(textwrap.wrap(cmd_out, 77)))
os.write(fd, "\n")
write(fd, "- ")
write(fd, "\n ".join(textwrap.wrap(cmd_out, 77)))
write(fd, "\n")
os.write(fd, "\n")
write(fd, "\n")
if not self._accept_auto_changelog:
# Give the user a chance to edit the generated changelog:
@ -279,7 +278,7 @@ class VersionTagger(ConfigObject):
# check for the changelog entry before making any modifications, then
# bump the version, then update the changelog.
f = open(self.spec_file, 'r')
buf = StringIO.StringIO()
buf = StringIO()
found_match = False
for line in f.readlines():
match = self.changelog_regex.match(line)
@ -313,7 +312,7 @@ class VersionTagger(ConfigObject):
py_new_version = new_version.split('-')[0]
f = open(setup_file, 'r')
buf = StringIO.StringIO()
buf = StringIO()
for line in f.readlines():
buf.write(replace_version(line, py_new_version))
f.close()

View file

@ -12,7 +12,7 @@ class BuildTargetParserTests(unittest.TestCase):
self.valid_branches = ["branch1", "branch2"]
self.release_target = "project-x.y.z"
self.releasers_config = ConfigParser()
self.releasers_config = RawConfigParser()
self.releasers_config.add_section(self.release_target)
self.releasers_config.set(self.release_target, "build_targets",
"branch1:project-x.y.z-candidate")