[FIX] Packaging: better filename handling

Allow to
1) avoid a special case for debian packages in _publish function
2) publish debian packages with correct filename (ie keeping _amd64, _all)
This commit is contained in:
Simon Lejeune 2014-11-25 12:25:01 +01:00
parent 1c41f36993
commit 50a4da99f0
1 changed files with 51 additions and 37 deletions

View File

@ -43,15 +43,19 @@ version = version.split('-')[0]
timestamp = time.strftime("%Y%m%d", time.gmtime())
PUBLISH_DIRS = {
'tar.gz': 'src',
'exe': 'exe',
'deb': 'deb',
'dsc': 'deb',
'changes': 'deb',
'deb.tar.gz': ['deb', 'tar.gz'],
'noarch.rpm': 'rpm',
'src.rpm': 'rpm',
'debian': 'deb',
'redhat': 'rpm',
'tarball': 'src',
'windows': 'exe',
}
EXTENSIONS = [
'.tar.gz',
'.deb',
'.dsc',
'.changes',
'.noarch.rpm',
'.exe',
]
def mkdir(d):
if not os.path.isdir(d):
@ -90,19 +94,26 @@ def _rpc_count_modules(addr='http://127.0.0.1', port=8069, dbname='mycompany'):
print("Package test: FAILED. Not able to install base.")
raise Exception("Installation of package failed")
def publish(o, releases):
def publish(o, type, releases):
def _publish(o, release):
extension = ''.join(release.split('.', 1)[1])
release_extension = PUBLISH_DIRS[extension][1] if isinstance(PUBLISH_DIRS[extension], list) else extension
release_dir = PUBLISH_DIRS[extension][0] if isinstance(PUBLISH_DIRS[extension], list) else PUBLISH_DIRS[extension]
arch = ''
filename = release.split(os.path.sep)[-1]
arch = ""
if release_extension == 'deb':
arch = "_all"
elif release_extension == "changes":
arch = "_amd64"
extension = None
for EXTENSION in EXTENSIONS:
if filename.endswith(EXTENSION):
extension = EXTENSION
filename = filename.replace(extension, '')
break
if extension is None:
raise Exception("Extension of %s is not handled" % filename)
release_filename = 'odoo_%s.%s%s.%s' % (version, timestamp, arch, release_extension)
# keep _all or _amd64
if filename.count('_') > 1:
arch = '_' + filename.split('_')[-1]
release_dir = PUBLISH_DIRS[type]
release_filename = 'odoo_%s.%s%s%s' % (version, timestamp, arch, extension)
release_path = join(o.pub, release_dir, release_filename)
system('mkdir -p %s' % join(o.pub, release_dir))
@ -261,10 +272,10 @@ def build_tgz(o):
def build_deb(o):
system(['dpkg-buildpackage', '-rfakeroot'], o.build_dir)
system(['cp', glob('%s/../odoo_*.deb' % o.build_dir)[0], '%s/odoo.deb' % o.build_dir])
system(['cp', glob('%s/../odoo_*.dsc' % o.build_dir)[0], '%s/odoo.dsc' % o.build_dir])
system(['cp', glob('%s/../odoo_*_amd64.changes' % o.build_dir)[0], '%s/odoo_amd64.changes' % o.build_dir])
system(['cp', glob('%s/../odoo_*.tar.gz' % o.build_dir)[0], '%s/odoo.deb.tar.gz' % o.build_dir])
system(['mv', glob('%s/../odoo_*.deb' % o.build_dir)[0], '%s' % o.build_dir])
system(['mv', glob('%s/../odoo_*.dsc' % o.build_dir)[0], '%s' % o.build_dir])
system(['mv', glob('%s/../odoo_*_amd64.changes' % o.build_dir)[0], '%s' % o.build_dir])
system(['mv', glob('%s/../odoo_*.tar.gz' % o.build_dir)[0], '%s' % o.build_dir])
def build_rpm(o):
system(['python2', 'setup.py', '--quiet', 'bdist_rpm'], o.build_dir)
@ -298,7 +309,7 @@ def test_tgz(o):
def test_deb(o):
with docker('debian:stable', o.build_dir, o.pub) as wheezy:
wheezy.release = 'odoo.deb'
wheezy.release = '*.deb'
wheezy.system('/usr/bin/apt-get update -qq && /usr/bin/apt-get upgrade -qq -y')
wheezy.system("apt-get install postgresql -y")
wheezy.system("service postgresql start")
@ -345,16 +356,17 @@ def gen_deb_package(o, published_files):
subprocess.call(command, stdout=out, cwd=path)
system(['cp', cur_tmp_file_path, os.path.join(o.pub, 'deb', file_name)])
# Copy files to a temp directory (required because the working directory must contain only the files of the last release)
# Copy files to a temp directory (required because the working directory must contain only the
# files of the last release)
temp_path = tempfile.mkdtemp(suffix='debPackages')
for pub_file_path in published_files:
system(['cp', pub_file_path, temp_path])
commands = [
(['dpkg-scanpackages', '.'], "Packages"), # Generate Packages file
(['dpkg-scansources', '.'], "Sources"), # Generate Sources file
(['apt-ftparchive', 'release', '.'], "Release") # Generate Release file
]
(['dpkg-scanpackages', '.'], "Packages"), # Generate Packages file
(['dpkg-scansources', '.'], "Sources"), # Generate Sources file
(['apt-ftparchive', 'release', '.'], "Release") # Generate Release file
]
# Generate files
for command in commands:
_gen_file(o, command, temp_path)
@ -363,8 +375,7 @@ def gen_deb_package(o, published_files):
# Generate Release.gpg (= signed Release)
# Options -abs: -a (Create ASCII armored output), -b (Make a detach signature), -s (Make a signature)
subprocess.call(['rm', 'Release.gpg'], cwd=os.path.join(o.pub, 'deb'))
subprocess.call(['gpg', '-abs', '-o', 'Release.gpg', 'Release'], cwd=os.path.join(o.pub, 'deb'))
subprocess.call(['gpg', '--yes', '-abs', '-o', 'Release.gpg', 'Release'], cwd=os.path.join(o.pub, 'deb'))
#----------------------------------------------------------
# Options and Main
@ -409,7 +420,7 @@ def main():
try:
if not o.no_testing:
test_tgz(o)
publish(o, 'odoo.tar.gz')
published_files = publish(o, 'tarball', ['odoo.tar.gz'])
except Exception, e:
print("Won't publish the tgz release.\n Exception: %s" % str(e))
if not o.no_debian:
@ -417,7 +428,13 @@ def main():
try:
if not o.no_testing:
test_deb(o)
published_files = publish(o, ['odoo.deb', 'odoo.dsc', 'odoo_amd64.changes', 'odoo.deb.tar.gz'])
to_publish = []
to_publish.append(glob("%s/odoo_*.deb" % o.build_dir)[0])
to_publish.append(glob("%s/odoo_*.dsc" % o.build_dir)[0])
to_publish.append(glob("%s/odoo_*.changes" % o.build_dir)[0])
to_publish.append(glob("%s/odoo_*.tar.gz" % o.build_dir)[0])
published_files = publish(o, 'debian', to_publish)
gen_deb_package(o, published_files)
except Exception, e:
print("Won't publish the deb release.\n Exception: %s" % str(e))
@ -426,7 +443,7 @@ def main():
try:
if not o.no_testing:
test_rpm(o)
publish(o, ['odoo.noarch.rpm', 'odoo.src.rpm'])
published_files = publish(o, 'redhat', ['odoo.noarch.rpm'])
except Exception, e:
print("Won't publish the rpm release.\n Exception: %s" % str(e))
if not o.no_windows:
@ -434,15 +451,12 @@ def main():
try:
if not o.no_testing:
test_exe(o)
publish(o, 'odoo.exe')
published_files = publish(o, 'windows', ['odoo.exe'])
except Exception, e:
print("Won't publish the exe release.\n Exception: %s" % str(e))
except:
pass
finally:
for leftover in glob('%s/../odoo_*' % o.build_dir):
os.remove(leftover)
shutil.rmtree(o.build_dir)
print('Build dir %s removed' % o.build_dir)