From e21f0a3accb8a27582e59567cdd54123b45e4f41 Mon Sep 17 00:00:00 2001 From: Kovid Goyal Date: Wed, 1 Feb 2017 19:34:44 +0530 Subject: [PATCH] Dont error if file exists when building installer --- setup/installers.py | 29 +++++++++++++++++++++++------ 1 file changed, 23 insertions(+), 6 deletions(-) diff --git a/setup/installers.py b/setup/installers.py index e47184229a..e425a23c86 100644 --- a/setup/installers.py +++ b/setup/installers.py @@ -2,8 +2,7 @@ # vim:fileencoding=utf-8 # License: GPLv3 Copyright: 2016, Kovid Goyal -from __future__ import (unicode_literals, division, absolute_import, - print_function) +from __future__ import (unicode_literals, division, absolute_import, print_function) import os, sys, subprocess from setup import Command @@ -15,7 +14,9 @@ def build_single(which, bitness, shutdown=True): build_calibre = os.path.join(d(base), 'build-calibre') build_calibre = os.environ.get('BUILD_CALIBRE_LOCATION', build_calibre) if not os.path.isdir(build_calibre): - raise SystemExit('Cannot find the build-calibre code. Set the environment variable BUILD_CALIBRE_LOCATION to point to it') + raise SystemExit( + 'Cannot find the build-calibre code. Set the environment variable BUILD_CALIBRE_LOCATION to point to it' + ) cmd = [sys.executable, os.path.join(build_calibre, which)] if bitness: cmd.append(bitness) @@ -32,7 +33,12 @@ def build_single(which, bitness, shutdown=True): dist = os.path.join(dist, 'dist') for x in os.listdir(dist): print(x) - os.link(os.path.join(dist, x), os.path.join(base, 'dist', x)) + dest = os.path.join(base, 'dist', x) + try: + os.remove(dest) + except EnvironmentError: + pass + os.link(os.path.join(dist, x), dest) if shutdown and which != 'linux': cmd = [sys.executable, os.path.join(build_calibre, which), 'shutdown'] subprocess.Popen(cmd, env=env, cwd=build_calibre).wait() @@ -43,8 +49,12 @@ class BuildInstaller(Command): OS = BITNESS = '' def add_options(self, parser): - parser.add_option('--dont-shutdown', default=False, action='store_true', - help='Do not shutdown the VM after building') + parser.add_option( + '--dont-shutdown', + default=False, + action='store_true', + help='Do not shutdown the VM after building' + ) def run(self, opts): build_single(self.OS, self.BITNESS, not opts.dont_shutdown) @@ -60,31 +70,38 @@ class BuildInstallers(BuildInstaller): shutdown = bitness is bits[-1] and not opts.dont_shutdown build_single(self.OS, bitness, shutdown) + class Linux32(BuildInstaller): OS = 'linux' BITNESS = '32' description = 'Build the 32-bit linux calibre installer' + class Linux64(BuildInstaller): OS = 'linux' BITNESS = '64' description = 'Build the 64-bit linux calibre installer' + class Win32(BuildInstaller): OS = 'win' BITNESS = '32' description = 'Build the 32-bit windows calibre installers' + class Win64(BuildInstaller): OS = 'win' BITNESS = '64' description = 'Build the 64-bit windows calibre installer' + class OSX(BuildInstaller): OS = 'osx' + class Linux(BuildInstallers): OS = 'linux' + class Win(BuildInstallers): OS = 'win'