general: update for python 3 (#41852)

This commit is contained in:
Frédéric Péters 2020-04-18 14:44:12 +02:00
parent d649f30ea8
commit db357708da
7 changed files with 68 additions and 61 deletions

View File

@ -77,15 +77,15 @@ if __name__ == '__main__':
if blacklisted:
continue
t0 = time.time()
print '='*60
print module
print '='*60
print('='*60)
print(module)
print('='*60)
sys.stdout.flush()
results[module] = build_module(config, module)
print '\n'
print '(%1.2f seconds)' % (time.time()-t0)
print '\n'
print('\n')
print('(%1.2f seconds)' % (time.time()-t0))
print('\n')
sys.stdout.flush()
for module in sorted(results.keys()):
print '%-40s %s' % (module, results[module])
print('%-40s %s' % (module, results[module]))

View File

@ -1,4 +1,4 @@
#!/usr/bin/env python
#!/usr/bin/env python3
import atexit
import re
@ -23,7 +23,7 @@ def smart_cleaning(files_path):
project_files = {}
for file_path in files_path:
project_name = os.path.basename(file_path).split('_')[0]
if not project_files.has_key(project_name):
if projet_name not in project_files:
project_files[project_name] = []
project_files[project_name].append(file_path)
@ -41,7 +41,7 @@ def smart_cleaning(files_path):
def clean(method):
print "+ Cleanning %s" % method
print("+ Cleanning %s" % method)
if method == "all":
shutil.rmtree(settings.ORIGIN_PATH)
shutil.rmtree(settings.PBUILDER_RESULT)
@ -157,14 +157,14 @@ def prepare_build(dist, project, cmd_options, new):
if debian_branch == "debian" and "debian-%s" % dist in branches:
debian_branch = "debian-" + dist
if not 'origin/%s' % debian_branch in output("git branch -r -l"):
print '!!! WARNING: cannot build for dist %s, no debian directory found' % dist
print('!!! WARNING: cannot build for dist %s, no debian directory found' % dist)
return
print "!!! WARNING obsolete: using a branch for debian/ packaging"
print "+ Updating Debian branch for %s" % dist
print("!!! WARNING obsolete: using a branch for debian/ packaging")
print("+ Updating Debian branch for %s" % dist)
call("git checkout --quiet %s" % debian_branch)
call("git pull")
else:
print "+ Building from %s debian folder" % debian_folder
print("+ Building from %s debian folder" % debian_folder)
for r in cmd_options.repositories:
repo = r.split(':')
if repo[0] == dist:
@ -183,7 +183,7 @@ def prepare_build(dist, project, cmd_options, new):
origin_archive = os.path.join(settings.ORIGIN_PATH,
"%s_%s.orig.tar.bz2" % (package['source_name'], project['version']))
if not os.path.exists(origin_archive):
print "+ Generating origin tarball ..."
print("+ Generating origin tarball ...")
os.chdir(project['git_path'])
call("git checkout --quiet %s" % build_branch)
if os.path.exists('setup.py'):
@ -251,7 +251,7 @@ def prepare_build(dist, project, cmd_options, new):
if os.path.exists(project['build_dir']):
shutil.rmtree(project['build_dir'])
os.makedirs(project['build_dir'], 0755)
os.makedirs(project['build_dir'], 0o755)
if package['version'].split('-')[0].split(':')[-1] == project['version']:
# the generated changelog has the right version number, use it.
@ -274,10 +274,10 @@ def prepare_build(dist, project, cmd_options, new):
build_branch.replace('/', '_'))
)
if os.path.exists(build_file):
print "+ Already built for %s !" % dist
print("+ Already built for %s !" % dist)
return package
print "+ Preparing Debian build (%s %s) ..." % (package['source_name'], package['version'])
print("+ Preparing Debian build (%s %s) ..." % (package['source_name'], package['version']))
if debian_branch:
call("git checkout --quiet %s" % debian_branch)
os.chdir(project['build_dir'])
@ -304,7 +304,7 @@ def build_project(dist, arch, project, package, new):
project_build_path = os.path.join(project['build_dir'],
"%s-%s" % (project['name'], project['version']))
if not os.path.exists(pbuilder_project_result):
os.makedirs(pbuilder_project_result, 0755)
os.makedirs(pbuilder_project_result, 0o755)
os.chdir(project['lock_path'])
source_build = os.path.join(project['lock_path'],
"%s_%s_%s_%s_source.build" % (project['name'],
@ -319,21 +319,21 @@ def build_project(dist, arch, project, package, new):
project['build_branch'].replace('/', '_'),
arch)
)
print 'SOURCE_BUILD:', source_build
print('SOURCE_BUILD:', source_build)
if os.path.exists(source_build):
source_opt = '-b'
else:
source_opt = '-sa'
if new == 0 and os.path.exists(bin_build):
print "+ Already build !"
print("+ Already build !")
return
os.chdir(project_build_path)
print "+ Building %s %s %s %s" % \
(project['name'], project['version'], dist, arch)
print("+ Building %s %s %s %s" % \
(project['name'], project['version'], dist, arch))
call('DIST=%s ARCH=%s pdebuild --use-pdebuild-internal --architecture %s --debbuildopts "%s"' % \
(dist, arch, arch, source_opt))
print "+ Lock build"
print("+ Lock build")
touch(bin_build)
if not os.path.exists(source_build):
touch(source_build)
@ -343,10 +343,10 @@ def send_packages(dist, arch, project, package, last_tag):
project['name'], package['version'],
package['repository'], arch, project['build_branch'].replace('/', '_')))
if os.path.exists(stamp_file):
print '+ Already uploaded'
print('+ Already uploaded')
return
print "+ Sending package..."
print("+ Sending package...")
pbuilder_project_result = os.path.join(settings.PBUILDER_RESULT,
'%s-%s' % (dist, arch))
os.chdir(pbuilder_project_result)
@ -357,23 +357,23 @@ def send_packages(dist, arch, project, package, last_tag):
arch)
)
print "+ Updating repository ..."
print("+ Updating repository ...")
call('ssh root@%s "/etc/cron.hourly/process-incoming"' % \
settings.REPOSITORY_URL)
old_version = tuple(int(d) for d in last_tag.split('.'))
new_version = tuple(int(d) for d in project['current_tag'].split('.'))
if new_version > old_version and \
project['current_tag'] == project['version']:
print "New tag detected : %s" % project['current_tag']
if settings.MANUAL_TESTING_REPOSITORIES.has_key(package['source_name']):
print("New tag detected : %s" % project['current_tag'])
if package['source_name'] in settings.MANUAL_TESTING_REPOSITORIES:
package_repos = settings.MANUAL_TESTING_REPOSITORIES[package['source_name']]
else:
package_repos = settings.DEFAULT_TESTING_REPOSITORIES
packages = package['names'] + [package['source_name']]
packages = " ".join(packages)
if package_repos.has_key(dist) and package['copy_in_testing']:
if dist in package_repos and package['copy_in_testing']:
for repo in package_repos[dist]:
print "+ Copy %s packages to %s repository (%s)" % (package['source_name'], repo, dist)
print("+ Copy %s packages to %s repository (%s)" % (package['source_name'], repo, dist))
call('ssh root@%s "/usr/bin/reprepro -b /var/vhosts/deb.entrouvert.org copy %s %s %s"'\
% (settings.REPOSITORY_URL, repo,
package['repository'], packages))
@ -406,7 +406,7 @@ def setup_git_tree(project_name, options):
subprocess.check_call(['git', 'checkout', '--quiet', options.branch])
subprocess.check_call(['git', 'reset', '--hard', 'origin/%s' % options.branch])
except subprocess.CalledProcessError as e:
print >> sys.stderr, e
print(e, file=sys.stderr)
shutil.rmtree(git_project_path)
return setup_git_tree(project_name, options)
else:
@ -426,7 +426,7 @@ def setup_git_tree(project_name, options):
subprocess.check_call(['git', 'submodule', 'update'])
except subprocess.CalledProcessError as e:
if existing_tree:
print >> sys.stderr, e
print(e, file=sys.stderr)
shutil.rmtree(git_project_path)
return setup_git_tree(project_name, options)
raise
@ -462,7 +462,7 @@ def main():
project = get_project_infos(git_project_path, options)
if not os.path.exists(project['lock_path']):
os.mkdir(project['lock_path'], 0755)
os.mkdir(project['lock_path'], 0o755)
# compare revision between last build and now to determine if something is really new
new = 1
@ -482,7 +482,7 @@ def main():
new = 0
if options.force and not new:
print "+ Warning force a new build"
print("+ Warning force a new build")
new = 1
for dist in options.distrib:
@ -493,7 +493,7 @@ def main():
for arch in options.architectures:
build_project(dist, arch, project, package, new)
send_packages(dist, arch, project, package, last_tag)
print "+ Add a build file to lock new build for %s" % dist
print("+ Add a build file to lock new build for %s" % dist)
touch(os.path.join(project['lock_path'],
"%s_%s_%s_%s.build" % (project['name'],
package['version'],

View File

@ -3,12 +3,12 @@ import os
VERSION = '7'
def init():
print "+ Init EO Builder"
print("+ Init EO Builder")
if not os.path.exists(settings.GIT_PATH):
os.makedirs(settings.GIT_PATH, 0755)
os.makedirs(settings.GIT_PATH, 0o755)
if not os.path.exists(settings.ORIGIN_PATH):
os.makedirs(settings.ORIGIN_PATH, 0755)
os.makedirs(settings.ORIGIN_PATH, 0o755)
if not os.path.exists(settings.PBUILDER_RESULT):
os.makedirs(settings.PBUILDER_RESULT, 0755)
os.makedirs(settings.PBUILDER_RESULT, 0o755)
if not os.path.exists(settings.LOCK_PATH):
os.makedirs(settings.LOCK_PATH, 0755)
os.makedirs(settings.LOCK_PATH, 0o755)

View File

@ -1,3 +1,4 @@
import codecs
import datetime
import textwrap
import os
@ -66,7 +67,9 @@ def changelog_from_git(project, version_suffix, path,
if i == n-1:
logs = [commit] + list(commit.iter_parents())
else:
reflog = '%s..%s' % (versions[i+1][1].binsha.encode('hex'), commit.binsha.encode('hex'))
def encode_hex(value):
return codecs.encode(value, 'hex').decode('ascii')
reflog = '%s..%s' % (encode_hex(versions[i+1][1].binsha), encode_hex(commit.binsha))
logs = list(Commit.iter_items(repo, reflog))
if not logs:
continue
@ -87,7 +90,7 @@ def changelog_from_git(project, version_suffix, path,
t = '(%s) %s' % (l.hexsha[:6], e)
lines = textwrap.wrap(t, 80)
for prefix, suffix in zip([' * '] + [' ']*(len(lines)-1), lines):
yield (prefix + suffix).encode('utf-8')
yield (prefix + suffix)
paris = pytz.timezone('Europe/Paris')
date = datetime.datetime.fromtimestamp(logs[0].committed_date + logs[0].committer_tz_offset).replace(
tzinfo=pytz.UTC).astimezone(paris).strftime('%a, %d %b %Y %H:%M:%S %z')
@ -102,4 +105,4 @@ if __name__ == '__main__':
path = sys.argv[3]
else:
path = os.getcwd()
print '\n'.join(changelog_from_git(project, version_suffix, path))
print('\n'.join(changelog_from_git(project, version_suffix, path)))

View File

@ -99,7 +99,7 @@ def cat(file_path):
return content
def touch(fname):
print 'TOUCH:', fname
print('TOUCH:', fname)
with open(fname, 'a'):
os.utime(fname, None)
@ -116,7 +116,7 @@ def call(cmd):
shebang = open('setup.py').readline()
if shebang.startswith('#!'):
cmd = shebang[2:].strip() + ' ' + cmd.split(' ', 1)[1]
print 'CALL:', cmd
print('CALL:', cmd)
rcode = subprocess.call(cmd, shell=True)
if rcode != 0:
error(cmd)
@ -135,11 +135,11 @@ def output(cmd, print_output=False, exit_on_error=True):
output = subprocess.check_output(cmd,
stderr=subprocess.STDOUT,
shell=True)
except subprocess.CalledProcessError, e:
except subprocess.CalledProcessError as e:
sys.stderr.write(e.output)
if exit_on_error:
error(cmd)
if print_output:
print output
return output
print(output)
return output.decode('utf-8')

View File

@ -56,4 +56,4 @@ MIN_AGE = 60
local_settings_file = os.environ.get('EOBUILDER_SETTINGS_FILE',
os.path.join(os.path.dirname(__file__), 'local_settings.py'))
if os.path.exists(local_settings_file):
execfile(local_settings_file)
exec(open(local_settings_file).read())

View File

@ -8,9 +8,7 @@ from setuptools.command.sdist import sdist
class eo_sdist(sdist):
def run(self):
print "creating VERSION file"
if os.path.exists('VERSION'):
os.remove('VERSION')
version = get_version()
@ -18,29 +16,35 @@ class eo_sdist(sdist):
version_file.write(version)
version_file.close()
sdist.run(self)
print "removing VERSION file"
if os.path.exists('VERSION'):
os.remove('VERSION')
def get_version():
'''Use the VERSION, if absent generates a version with git describe, if not
tag exists, take 0.0.0- and add the length of the commit log.
tag exists, take 0.0- and add the length of the commit log.
'''
if os.path.exists('VERSION'):
with open('VERSION', 'r') as v:
return v.read()
if os.path.exists('.git'):
p = subprocess.Popen(['git', 'describe', '--dirty', '--match=v*'], stdout=subprocess.PIPE,
stderr=subprocess.PIPE)
p = subprocess.Popen(
['git', 'describe', '--dirty=.dirty', '--match=v*'],
stdout=subprocess.PIPE,
stderr=subprocess.PIPE,
)
result = p.communicate()[0]
if p.returncode == 0:
result = result.split()[0][1:]
result = result.decode('ascii').strip()[1:] # strip spaces/newlines and initial v
if '-' in result: # not a tagged version
real_number, commit_count, commit_hash = result.split('-', 2)
version = '%s.post%s+%s' % (real_number, commit_count, commit_hash)
else:
version = result
return version
else:
result = '0.0.0-%s' % len(subprocess.check_output(
['git', 'rev-list', 'HEAD']).splitlines())
return result.replace('-', '.').replace('.g', '+g')
return '0.0.0'
return '0.0.post%s' % len(subprocess.check_output(['git', 'rev-list', 'HEAD']).splitlines())
return '0.0'
setup(name="eobuilder",