Dont error if file exists when building installer

This commit is contained in:
Kovid Goyal 2017-02-01 19:34:44 +05:30
parent 47ac17d962
commit e21f0a3acc
No known key found for this signature in database
GPG Key ID: 06BC317B515ACE7C

View File

@ -2,8 +2,7 @@
# vim:fileencoding=utf-8 # vim:fileencoding=utf-8
# License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net> # License: GPLv3 Copyright: 2016, Kovid Goyal <kovid at kovidgoyal.net>
from __future__ import (unicode_literals, division, absolute_import, from __future__ import (unicode_literals, division, absolute_import, print_function)
print_function)
import os, sys, subprocess import os, sys, subprocess
from setup import Command 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.path.join(d(base), 'build-calibre')
build_calibre = os.environ.get('BUILD_CALIBRE_LOCATION', build_calibre) build_calibre = os.environ.get('BUILD_CALIBRE_LOCATION', build_calibre)
if not os.path.isdir(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)] cmd = [sys.executable, os.path.join(build_calibre, which)]
if bitness: if bitness:
cmd.append(bitness) cmd.append(bitness)
@ -32,7 +33,12 @@ def build_single(which, bitness, shutdown=True):
dist = os.path.join(dist, 'dist') dist = os.path.join(dist, 'dist')
for x in os.listdir(dist): for x in os.listdir(dist):
print(x) 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': if shutdown and which != 'linux':
cmd = [sys.executable, os.path.join(build_calibre, which), 'shutdown'] cmd = [sys.executable, os.path.join(build_calibre, which), 'shutdown']
subprocess.Popen(cmd, env=env, cwd=build_calibre).wait() subprocess.Popen(cmd, env=env, cwd=build_calibre).wait()
@ -43,8 +49,12 @@ class BuildInstaller(Command):
OS = BITNESS = '' OS = BITNESS = ''
def add_options(self, parser): def add_options(self, parser):
parser.add_option('--dont-shutdown', default=False, action='store_true', parser.add_option(
help='Do not shutdown the VM after building') '--dont-shutdown',
default=False,
action='store_true',
help='Do not shutdown the VM after building'
)
def run(self, opts): def run(self, opts):
build_single(self.OS, self.BITNESS, not opts.dont_shutdown) 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 shutdown = bitness is bits[-1] and not opts.dont_shutdown
build_single(self.OS, bitness, shutdown) build_single(self.OS, bitness, shutdown)
class Linux32(BuildInstaller): class Linux32(BuildInstaller):
OS = 'linux' OS = 'linux'
BITNESS = '32' BITNESS = '32'
description = 'Build the 32-bit linux calibre installer' description = 'Build the 32-bit linux calibre installer'
class Linux64(BuildInstaller): class Linux64(BuildInstaller):
OS = 'linux' OS = 'linux'
BITNESS = '64' BITNESS = '64'
description = 'Build the 64-bit linux calibre installer' description = 'Build the 64-bit linux calibre installer'
class Win32(BuildInstaller): class Win32(BuildInstaller):
OS = 'win' OS = 'win'
BITNESS = '32' BITNESS = '32'
description = 'Build the 32-bit windows calibre installers' description = 'Build the 32-bit windows calibre installers'
class Win64(BuildInstaller): class Win64(BuildInstaller):
OS = 'win' OS = 'win'
BITNESS = '64' BITNESS = '64'
description = 'Build the 64-bit windows calibre installer' description = 'Build the 64-bit windows calibre installer'
class OSX(BuildInstaller): class OSX(BuildInstaller):
OS = 'osx' OS = 'osx'
class Linux(BuildInstallers): class Linux(BuildInstallers):
OS = 'linux' OS = 'linux'
class Win(BuildInstallers): class Win(BuildInstallers):
OS = 'win' OS = 'win'