mirror of
https://github.com/kovidgoyal/calibre.git
synced 2025-07-07 18:24:30 -04:00
pep8 and condition on PLATFORM
This commit is contained in:
parent
d5f2622b41
commit
933c7d221d
@ -2,25 +2,30 @@
|
|||||||
# 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 absolute_import, division, print_function, unicode_literals
|
||||||
print_function)
|
|
||||||
|
|
||||||
import os
|
|
||||||
import io
|
import io
|
||||||
import sys
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
import sys
|
||||||
import tarfile
|
import tarfile
|
||||||
|
|
||||||
def vcvars(is64bit=True): # {{{
|
try:
|
||||||
import _winreg as winreg
|
import _winreg as winreg
|
||||||
|
except ImportError:
|
||||||
|
import winreg
|
||||||
|
is64bit = os.environ.get('PLATFORM') != 'x86'
|
||||||
|
|
||||||
|
|
||||||
|
def vcvars(): # {{{
|
||||||
RegOpenKeyEx = winreg.OpenKeyEx
|
RegOpenKeyEx = winreg.OpenKeyEx
|
||||||
RegEnumValue = winreg.EnumValue
|
RegEnumValue = winreg.EnumValue
|
||||||
RegError = winreg.error
|
RegError = winreg.error
|
||||||
|
|
||||||
HKEYS = (winreg.HKEY_USERS,
|
HKEYS = (
|
||||||
winreg.HKEY_CURRENT_USER,
|
winreg.HKEY_USERS, winreg.HKEY_CURRENT_USER, winreg.HKEY_LOCAL_MACHINE,
|
||||||
winreg.HKEY_LOCAL_MACHINE,
|
winreg.HKEY_CLASSES_ROOT
|
||||||
winreg.HKEY_CLASSES_ROOT)
|
)
|
||||||
VS_BASE = r"Software\Wow6432Node\Microsoft\VisualStudio\%0.1f"
|
VS_BASE = r"Software\Wow6432Node\Microsoft\VisualStudio\%0.1f"
|
||||||
|
|
||||||
def get_reg_value(path, key):
|
def get_reg_value(path, key):
|
||||||
@ -65,7 +70,9 @@ def vcvars(is64bit=True): # {{{
|
|||||||
try:
|
try:
|
||||||
productdir = get_reg_value(r"%s\Setup\VC" % vsbase, "productdir")
|
productdir = get_reg_value(r"%s\Setup\VC" % vsbase, "productdir")
|
||||||
except KeyError:
|
except KeyError:
|
||||||
raise SystemExit("Unable to find Visual Studio product directory in the registry")
|
raise SystemExit(
|
||||||
|
"Unable to find Visual Studio product directory in the registry"
|
||||||
|
)
|
||||||
|
|
||||||
if not productdir:
|
if not productdir:
|
||||||
raise SystemExit("No productdir found")
|
raise SystemExit("No productdir found")
|
||||||
@ -86,8 +93,7 @@ def vcvars(is64bit=True): # {{{
|
|||||||
if is64bit and 'PROGRAMFILES(x86)' not in os.environ:
|
if is64bit and 'PROGRAMFILES(x86)' not in os.environ:
|
||||||
os.environ['PROGRAMFILES(x86)'] = os.environ['PROGRAMFILES'] + ' (x86)'
|
os.environ['PROGRAMFILES(x86)'] = os.environ['PROGRAMFILES'] + ' (x86)'
|
||||||
result = {}
|
result = {}
|
||||||
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE,
|
popen = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE)
|
||||||
stderr=subprocess.PIPE)
|
|
||||||
try:
|
try:
|
||||||
stdout, stderr = popen.communicate()
|
stdout, stderr = popen.communicate()
|
||||||
if popen.wait() != 0:
|
if popen.wait() != 0:
|
||||||
@ -128,13 +134,23 @@ def vcvars(is64bit=True): # {{{
|
|||||||
for i, p in enumerate(tuple(paths)):
|
for i, p in enumerate(tuple(paths)):
|
||||||
if os.path.exists(os.path.join(p, 'MSBuild.exe')):
|
if os.path.exists(os.path.join(p, 'MSBuild.exe')):
|
||||||
if '.net' in p.lower():
|
if '.net' in p.lower():
|
||||||
paths.insert(i, r'C:\Program Files (x86)\MSBuild\14.0\bin' + (r'\amd64' if is64bit else ''))
|
paths.insert(
|
||||||
|
i, r'C:\Program Files (x86)\MSBuild\14.0\bin' +
|
||||||
|
(r'\amd64' if is64bit else '')
|
||||||
|
)
|
||||||
env["PATH"] = os.pathsep.join(paths)
|
env["PATH"] = os.pathsep.join(paths)
|
||||||
break
|
break
|
||||||
|
|
||||||
return {k: g(k) for k in 'PATH LIB INCLUDE LIBPATH WINDOWSSDKDIR VS140COMNTOOLS UCRTVERSION UNIVERSALCRTSDKDIR'.split()}
|
return {
|
||||||
|
k: g(k)
|
||||||
|
for k in
|
||||||
|
'PATH LIB INCLUDE LIBPATH WINDOWSSDKDIR VS140COMNTOOLS UCRTVERSION UNIVERSALCRTSDKDIR'.
|
||||||
|
split()
|
||||||
|
}
|
||||||
|
|
||||||
return query_vcvarsall()
|
return query_vcvarsall()
|
||||||
|
|
||||||
|
|
||||||
# }}}
|
# }}}
|
||||||
|
|
||||||
|
|
||||||
@ -142,11 +158,12 @@ def printf(*args, **kw):
|
|||||||
print(*args, **kw)
|
print(*args, **kw)
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
|
||||||
def sw():
|
def sw():
|
||||||
sw=os.environ['SW']
|
sw = os.environ['SW']
|
||||||
os.makedirs(sw)
|
os.makedirs(sw)
|
||||||
os.chdir(sw)
|
os.chdir(sw)
|
||||||
url = 'https://download.calibre-ebook.com/travis/win-64.tar.xz'
|
url = 'https://download.calibre-ebook.com/travis/win-64.tar.xz'
|
||||||
printf('Downloading', url)
|
printf('Downloading', url)
|
||||||
tarball = subprocess.check_output(['curl.exe', '-fsSL', url])
|
tarball = subprocess.check_output(['curl.exe', '-fsSL', url])
|
||||||
with tarfile.open(fileobj=io.BytesIO(tarball)) as tf:
|
with tarfile.open(fileobj=io.BytesIO(tarball)) as tf:
|
||||||
@ -164,13 +181,16 @@ def sanitize_path():
|
|||||||
executables.remove(x)
|
executables.remove(x)
|
||||||
sw = os.environ['SW']
|
sw = os.environ['SW']
|
||||||
paths = r'{0}\private\python\DLLs {0}\private\python\Lib\site-packages\pywin32_system32 {0}\bin {0}\qt\bin C:\Windows\System32'.format(
|
paths = r'{0}\private\python\DLLs {0}\private\python\Lib\site-packages\pywin32_system32 {0}\bin {0}\qt\bin C:\Windows\System32'.format(
|
||||||
sw).split() + needed_paths
|
sw
|
||||||
|
).split() + needed_paths
|
||||||
os.environ[b'PATH'] = os.pathsep.join(paths).encode('ascii')
|
os.environ[b'PATH'] = os.pathsep.join(paths).encode('ascii')
|
||||||
|
|
||||||
|
|
||||||
def vcenv():
|
def vcenv():
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
env.update(vcvars())
|
env.update(vcvars())
|
||||||
return {str(k):str(v) for k, v in env.items()}
|
return {str(k): str(v) for k, v in env.items()}
|
||||||
|
|
||||||
|
|
||||||
def build():
|
def build():
|
||||||
sanitize_path()
|
sanitize_path()
|
||||||
@ -179,6 +199,7 @@ def build():
|
|||||||
p = subprocess.Popen(cmd, env=vcenv())
|
p = subprocess.Popen(cmd, env=vcenv())
|
||||||
raise SystemExit(p.wait())
|
raise SystemExit(p.wait())
|
||||||
|
|
||||||
|
|
||||||
def test():
|
def test():
|
||||||
sanitize_path()
|
sanitize_path()
|
||||||
cmd = [sys.executable, 'setup.py', 'test']
|
cmd = [sys.executable, 'setup.py', 'test']
|
||||||
@ -186,6 +207,7 @@ def test():
|
|||||||
p = subprocess.Popen(cmd)
|
p = subprocess.Popen(cmd)
|
||||||
raise SystemExit(p.wait())
|
raise SystemExit(p.wait())
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
q = sys.argv[-1]
|
q = sys.argv[-1]
|
||||||
if q == 'build':
|
if q == 'build':
|
||||||
@ -199,5 +221,6 @@ def main():
|
|||||||
raise SystemExit('Usage: win-ci.py sw|build|test')
|
raise SystemExit('Usage: win-ci.py sw|build|test')
|
||||||
raise SystemExit('%r is not a valid action' % sys.argv[-1])
|
raise SystemExit('%r is not a valid action' % sys.argv[-1])
|
||||||
|
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user