summaryrefslogtreecommitdiffstats
path: root/utils/common/deploy.py
diff options
context:
space:
mode:
authorDominik Riebeling <Dominik.Riebeling@gmail.com>2019-11-17 11:55:46 +0100
committerDominik Riebeling <Dominik.Riebeling@gmail.com>2020-06-13 20:11:48 +0200
commit440791105a22c7c42ef0c57ef44e4e6f01fa00e9 (patch)
treeb9dd1ac3ebd8ee047042564053ca1ea7210dc936 /utils/common/deploy.py
parentaefbc13e19af974156e76f0b8184dad41982ebfb (diff)
downloadrockbox-440791105a22c7c42ef0c57ef44e4e6f01fa00e9.tar.gz
rockbox-440791105a22c7c42ef0c57ef44e4e6f01fa00e9.tar.bz2
rockbox-440791105a22c7c42ef0c57ef44e4e6f01fa00e9.zip
deploy: Fix various style issues.
Fix various pylint issues and some python3 compatibility. Change-Id: I2c35ccc5ad2d0902c229f9de57912cf6d5a83ece
Diffstat (limited to 'utils/common/deploy.py')
-rwxr-xr-xutils/common/deploy.py149
1 files changed, 75 insertions, 74 deletions
diff --git a/utils/common/deploy.py b/utils/common/deploy.py
index 571424756b..e0bb7029b8 100755
--- a/utils/common/deploy.py
+++ b/utils/common/deploy.py
@@ -43,21 +43,21 @@ import getopt
import time
import hashlib
import tempfile
-import gitscraper
from datetime import datetime
+import gitscraper
# modules that are not part of python itself.
cpus = 1
try:
import multiprocessing
cpus = multiprocessing.cpu_count()
- print "Info: %s cores found." % cpus
+ print("Info: %s cores found." % cpus)
except ImportError:
- print "Warning: multiprocessing module not found. Assuming 1 core."
+ print("Warning: multiprocessing module not found. Assuming 1 core.")
# == Global stuff ==
# DLL files to ignore when searching for required DLL files.
-systemdlls = [
+SYSTEMDLLS = [
'advapi32.dll',
'comdlg32.dll',
'crypt32.dll',
@@ -94,23 +94,23 @@ gitrepo = os.path.abspath(os.path.join(os.path.dirname(__file__), "../.."))
# == Functions ==
def usage(myself):
- print "Usage: %s [options]" % myself
- print " -q, --qmake=<qmake> path to qmake"
- print " -p, --project=<pro> path to .pro file for building with local tree"
- print " -t, --tag=<tag> use specified tag from svn"
- print " -a, --add=<file> add file to build folder before building"
- print " -s, --source-only only create source archive"
- print " -b, --binary-only only create binary archive"
+ print("Usage: %s [options]" % myself)
+ print(" -q, --qmake=<qmake> path to qmake")
+ print(" -p, --project=<pro> path to .pro file for building with local tree")
+ print(" -t, --tag=<tag> use specified tag from svn")
+ print(" -a, --add=<file> add file to build folder before building")
+ print(" -s, --source-only only create source archive")
+ print(" -b, --binary-only only create binary archive")
if nsisscript != "":
- print " -n, --makensis=<file> path to makensis for building Windows setup program."
+ print(" -n, --makensis=<file> path to makensis for building Windows setup program.")
if sys.platform != "darwin":
- print " -d, --dynamic link dynamically instead of static"
+ print(" -d, --dynamic link dynamically instead of static")
if sys.platform != "win32":
- print " -x, --cross= prefix to cross compile for win32"
- print " -k, --keep-temp keep temporary folder on build failure"
- print " -h, --help this help"
- print " If neither a project file nor tag is specified trunk will get downloaded"
- print " from svn."
+ print(" -x, --cross= prefix to cross compile for win32")
+ print(" -k, --keep-temp keep temporary folder on build failure")
+ print(" -h, --help this help")
+ print(" If neither a project file nor tag is specified trunk will get downloaded")
+ print(" from svn.")
def which(executable):
@@ -119,7 +119,7 @@ def which(executable):
fullpath = p + "/" + executable
if os.path.exists(fullpath):
return fullpath
- print "which: could not find " + executable
+ print("which: could not find " + executable)
return ""
@@ -152,7 +152,7 @@ def findversion(versionfile):
def findqt(cross=""):
'''Search for Qt4 installation. Return path to qmake.'''
- print "Searching for Qt"
+ print("Searching for Qt")
bins = [cross + "qmake", cross + "qmake-qt4"]
for binary in bins:
try:
@@ -162,7 +162,7 @@ def findqt(cross=""):
if not result == "":
return result
except:
- print sys.exc_value
+ print(sys.exc_value)
return ""
@@ -172,27 +172,27 @@ def checkqt(qmakebin):
result = ""
# check if binary exists
if not os.path.exists(qmakebin):
- print "Specified qmake path does not exist!"
+ print("Specified qmake path does not exist!")
return result
# check version
- output = subprocess.Popen([qmakebin, "-version"], stdout=subprocess.PIPE,
- stderr=subprocess.PIPE)
+ output = subprocess.Popen(
+ [qmakebin, "-version"], stdout=subprocess.PIPE, stderr=subprocess.PIPE)
cmdout = output.communicate()
# don't check the qmake return code here, Qt3 doesn't return 0 on -version.
for ou in cmdout:
r = re.compile("Qt[^0-9]+([0-9\.]+[a-z]*)")
m = re.search(r, ou)
if not m == None:
- print "Qt found: %s" % m.group(1)
+ print("Qt found: %s" % m.group(1))
s = re.compile("[45]\..*")
n = re.search(s, m.group(1))
- if not n == None:
+ if n is not None:
result = qmakebin
return result
def qmake(qmake, projfile, platform=sys.platform, wd=".", static=True, cross=""):
- print "Running qmake in %s..." % wd
+ print("Running qmake in %s..." % wd)
command = [qmake, "-config", "release", "-config", "noccache"]
if static == True:
command.extend(["-config", "-static"])
@@ -206,14 +206,14 @@ def qmake(qmake, projfile, platform=sys.platform, wd=".", static=True, cross="")
output = subprocess.Popen(command, stdout=subprocess.PIPE, cwd=wd)
output.communicate()
if not output.returncode == 0:
- print "qmake returned an error!"
+ print("qmake returned an error!")
return -1
return 0
def build(wd=".", platform=sys.platform, cross=""):
# make
- print "Building ..."
+ print("Building ...")
# use the current platforms make here, cross compiling uses the native make.
command = [make[sys.platform]]
if cpus > 1:
@@ -228,36 +228,36 @@ def build(wd=".", platform=sys.platform, cross=""):
sys.stdout.write("\n")
sys.stdout.flush()
if not output.returncode == 0:
- print "Build failed!"
+ print("Build failed!")
return -1
break
if platform != "darwin":
# strip. OS X handles this via macdeployqt.
- print "Stripping binary."
+ print("Stripping binary.")
output = subprocess.Popen([cross + "strip", progexe[platform]], \
stdout=subprocess.PIPE, cwd=wd)
output.communicate()
if not output.returncode == 0:
- print "Stripping failed!"
+ print("Stripping failed!")
return -1
return 0
def upxfile(wd=".", platform=sys.platform):
# run upx on binary
- print "UPX'ing binary ..."
+ print("UPX'ing binary ...")
output = subprocess.Popen(["upx", progexe[platform]], \
stdout=subprocess.PIPE, cwd=wd)
output.communicate()
if not output.returncode == 0:
- print "UPX'ing failed!"
+ print("UPX'ing failed!")
return -1
return 0
def runnsis(versionstring, nsis, script, srcfolder):
# run script through nsis to create installer.
- print "Running NSIS ..."
+ print("Running NSIS ...")
# Assume the generated installer gets placed in the same folder the nsi
# script lives in. This seems to be a valid assumption unless the nsi
@@ -276,7 +276,7 @@ def runnsis(versionstring, nsis, script, srcfolder):
stdout=subprocess.PIPE)
output.communicate()
if not output.returncode == 0:
- print "NSIS failed!"
+ print("NSIS failed!")
return -1
setupfile = program + "-" + versionstring + "-setup.exe"
# find output filename in nsis script file
@@ -285,7 +285,7 @@ def runnsis(versionstring, nsis, script, srcfolder):
if re.match(r'^[^;]*OutFile\s+', line) != None:
nsissetup = re.sub(r'^[^;]*OutFile\s+"(.+)"', r'\1', line).rstrip()
if nsissetup == "":
- print "Could not retrieve output file name!"
+ print("Could not retrieve output file name!")
return -1
shutil.copy(srcfolder + "/" + os.path.dirname(script) + "/" + nsissetup, \
setupfile)
@@ -330,29 +330,29 @@ def finddlls(program, extrapaths=[], cross=""):
# find DLLs in extrapaths and PATH environment variable.
dllpaths = []
for file in dlls:
- if file in systemdlls:
- print "System DLL: " + file
+ if file in SYSTEMDLLS:
+ print("System DLL: " + file)
continue
dllpath = ""
for path in extrapaths:
if os.path.exists(path + "/" + file):
dllpath = re.sub(r"\\", r"/", path + "/" + file)
- print file + ": found at " + dllpath
+ print(file + ": found at " + dllpath)
dllpaths.append(dllpath)
break
if dllpath == "":
try:
dllpath = re.sub(r"\\", r"/", which(file))
- print file + ": found at " + dllpath
+ print(file + ": found at " + dllpath)
dllpaths.append(dllpath)
except:
- print "MISSING DLL: " + file
+ print("MISSING DLL: " + file)
return dllpaths
def zipball(programfiles, versionstring, buildfolder, platform=sys.platform):
'''package created binary'''
- print "Creating binary zipball."
+ print("Creating binary zipball.")
archivebase = program + "-" + versionstring
outfolder = buildfolder + "/" + archivebase
archivename = archivebase + ".zip"
@@ -379,7 +379,7 @@ def zipball(programfiles, versionstring, buildfolder, platform=sys.platform):
def tarball(programfiles, versionstring, buildfolder):
'''package created binary'''
- print "Creating binary tarball."
+ print("Creating binary tarball.")
archivebase = program + "-" + versionstring
outfolder = buildfolder + "/" + archivebase
archivename = archivebase + ".tar.bz2"
@@ -404,7 +404,7 @@ def macdeploy(versionstring, buildfolder, platform=sys.platform):
# workaround to Qt issues when building out-of-tree. Copy files into bundle.
sourcebase = buildfolder + re.sub('[^/]+.pro$', '', project) + "/"
- print sourcebase
+ print(sourcebase)
for src in bundlecopy:
shutil.copy(sourcebase + src, appbundle + "/" + bundlecopy[src])
# end of Qt workaround
@@ -413,7 +413,7 @@ def macdeploy(versionstring, buildfolder, platform=sys.platform):
stdout=subprocess.PIPE, cwd=buildfolder)
output.communicate()
if not output.returncode == 0:
- print "macdeployqt failed!"
+ print("macdeployqt failed!")
return -1
# copy dmg to output folder
shutil.copy(buildfolder + "/" + program + ".dmg", dmgfile)
@@ -440,32 +440,33 @@ def filestats(filename):
if not os.path.exists(filename):
return
st = os.stat(filename)
- print filename, "\n", "-" * len(filename)
- print "Size: %i bytes" % st.st_size
+ print(filename, "\n", "-" * len(filename))
+ print("Size: %i bytes" % st.st_size)
h = filehashes(filename)
- print "md5sum: %s" % h[0]
- print "sha1sum: %s" % h[1]
- print "-" * len(filename), "\n"
+ print("md5sum: %s" % h[0])
+ print("sha1sum: %s" % h[1])
+ print("-" * len(filename), "\n")
def tempclean(workfolder, nopro):
if nopro == True:
- print "Cleaning up working folder %s" % workfolder
+ print("Cleaning up working folder %s" % workfolder)
shutil.rmtree(workfolder)
else:
- print "Project file specified or cleanup disabled!"
- print "Temporary files kept at %s" % workfolder
+ print("Project file specified or cleanup disabled!")
+ print("Temporary files kept at %s" % workfolder)
def deploy():
startup = time.time()
try:
- opts, args = getopt.getopt(sys.argv[1:], "q:p:t:a:n:sbdkx:i:h",
+ opts, args = getopt.getopt(
+ sys.argv[1:], "q:p:t:a:n:sbdkx:i:h",
["qmake=", "project=", "tag=", "add=", "makensis=", "source-only",
"binary-only", "dynamic", "keep-temp", "cross=", "buildid=", "help"])
- except getopt.GetoptError, err:
- print str(err)
+ except getopt.GetoptError as err:
+ print(str(err))
usage(sys.argv[0])
sys.exit(1)
qt = ""
@@ -516,17 +517,17 @@ def deploy():
sys.exit(0)
if source == False and binary == False:
- print "Building build neither source nor binary means nothing to do. Exiting."
+ print("Building build neither source nor binary means nothing to do. Exiting.")
sys.exit(1)
- print "Building " + progexe[platform] + " for " + platform
+ print("Building " + progexe[platform] + " for " + platform)
# search for qmake
if qt == "":
qm = findqt(cross)
else:
qm = checkqt(qt)
if qm == "":
- print "ERROR: No suitable Qt installation found."
+ print("ERROR: No suitable Qt installation found.")
sys.exit(1)
# create working folder. Use current directory if -p option used.
@@ -552,7 +553,7 @@ def deploy():
archivename = program + "-" + str(revision) + versionextra + "-src.tar.bz2"
ver = str(revision)
os.mkdir(sourcefolder)
- print "Version: %s" % revision
+ print("Version: %s" % revision)
else:
workfolder = "."
sourcefolder = "."
@@ -561,12 +562,12 @@ def deploy():
if proj == "":
proj = sourcefolder + project
# get sources and pack source tarball
- if not getsources(treehash, svnpaths, sourcefolder) == 0:
+ if getsources(treehash, svnpaths, sourcefolder) != 0:
tempclean(workfolder, cleanup and not keeptemp)
sys.exit(1)
# replace version strings.
- print "Updating version information in sources"
+ print("Updating version information in sources")
for f in regreplace:
infile = open(sourcefolder + "/" + f, "r")
incontents = infile.readlines()
@@ -590,7 +591,7 @@ def deploy():
outfile.close()
if source == True:
- print "Creating source tarball %s\n" % archivename
+ print("Creating source tarball %s\n" % archivename)
tf = tarfile.open(archivename, mode='w:bz2')
tf.add(sourcefolder, os.path.basename(re.subn('/$', '', sourcefolder)[0]))
tf.close()
@@ -607,7 +608,7 @@ def deploy():
# check project file
if not os.path.exists(proj):
- print "ERROR: path to project file wrong."
+ print("ERROR: path to project file wrong.")
sys.exit(1)
# copy specified (--add) files to working folder
@@ -615,8 +616,8 @@ def deploy():
shutil.copy(f, sourcefolder)
buildstart = time.time()
header = "Building %s %s" % (program, ver)
- print header
- print len(header) * "="
+ print(header)
+ print(len(header) * "=")
# build it.
if not qmake(qm, proj, platform, sourcefolder, static, cross) == 0:
@@ -649,8 +650,8 @@ def deploy():
if platform == "linux2":
for p in progfiles:
prog = sourcefolder + "/" + p
- output = subprocess.Popen(["file", prog],
- stdout=subprocess.PIPE)
+ output = subprocess.Popen(
+ ["file", prog], stdout=subprocess.PIPE)
res = output.communicate()
if re.findall("ELF 64-bit", res[0]):
ver += "-64bit"
@@ -663,7 +664,7 @@ def deploy():
# display summary
headline = "Build Summary for %s" % program
- print "\n", headline, "\n", "=" * len(headline)
+ print("\n", headline, "\n", "=" * len(headline))
if not archivename == "":
filestats(archivename)
filestats(archive)
@@ -672,10 +673,10 @@ def deploy():
dursecs = (int)(duration % 60)
buildmins = (int)(buildtime / 60)
buildsecs = (int)(buildtime % 60)
- print "Overall time %smin %ssec, building took %smin %ssec." % \
- (durmins, dursecs, buildmins, buildsecs)
+ print("Overall time %smin %ssec, building took %smin %ssec." % \
+ (durmins, dursecs, buildmins, buildsecs))
if __name__ == "__main__":
- print "You cannot run this module directly!"
- print "Set required environment and call deploy()."
+ print("You cannot run this module directly!")
+ print("Set required environment and call deploy().")