Skip to content

Commit

Permalink
[FIX] Packaging: better filename handling
Browse files Browse the repository at this point in the history
Allow to
1) avoid a special case for debian packages in _publish function
2) publish debian packages with correct filename (ie keeping _amd64, _all)
  • Loading branch information
sle-odoo committed Nov 28, 2014
1 parent 1c41f36 commit 50a4da9
Showing 1 changed file with 53 additions and 39 deletions.
92 changes: 53 additions & 39 deletions setup/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,19 @@

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):
Expand Down Expand Up @@ -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 = ""
if release_extension == 'deb':
arch = "_all"
elif release_extension == "changes":
arch = "_amd64"

release_filename = 'odoo_%s.%s%s.%s' % (version, timestamp, arch, release_extension)
arch = ''
filename = release.split(os.path.sep)[-1]

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)

# 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))
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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")
Expand Down Expand Up @@ -345,16 +356,17 @@ def _gen_file(o, (command, file_name), path):
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)
Expand All @@ -363,8 +375,7 @@ def _gen_file(o, (command, file_name), path):

# 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
Expand Down Expand Up @@ -409,15 +420,21 @@ 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:
build_deb(o)
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))
Expand All @@ -426,23 +443,20 @@ 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:
build_exe(o)
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)

Expand Down

0 comments on commit 50a4da9

Please sign in to comment.