Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pylint fixes for build.py #1416

Merged
merged 1 commit into from
Feb 6, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
65 changes: 39 additions & 26 deletions tools/build.py
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#!/usr/bin/env python3

"""CBA Debug Build"""

import os
import sys
import subprocess
Expand All @@ -9,38 +11,47 @@
PREFIX = "cba_"
##########################

def tryHemttBuild(projectpath):
hemttExe = os.path.join(projectpath, "hemtt.exe")
if os.path.isfile(hemttExe):
def try_hemtt_build(projectpath):
"""Try building with hemtt"""
hemtt = os.path.join(projectpath, "hemtt.exe")
if os.path.isfile(hemtt):
os.chdir(projectpath)
ret = subprocess.call([hemttExe, "pack"], stderr=subprocess.STDOUT)
print("Using hemtt: {}".format(ret));
ret = subprocess.call([hemtt, "pack"], stderr=subprocess.STDOUT)
print("Using hemtt: {}".format(ret))
return True
else:
print("hemtt not installed");

print("hemtt not installed")
return False

def mod_time(path):
"""Return time of last modification of a file or directory

If the path is a directory, return the time of modification of
the most recently modified file in the directory.
"""
if not os.path.isdir(path):
return os.path.getmtime(path)
maxi = os.path.getmtime(path)
for p in os.listdir(path):
maxi = max(mod_time(os.path.join(path, p)), maxi)
for name in os.listdir(path):
maxi = max(mod_time(os.path.join(path, name)), maxi)
return maxi


def check_for_changes(addonspath, module):
if not os.path.exists(os.path.join(addonspath, "{}{}.pbo".format(PREFIX,module))):
"""Return True if the sources of an addon have been changed since it was last built"""
file = os.path.join(addonspath, "{}{}.pbo".format(PREFIX, module))
if not os.path.exists(file):
return True
return mod_time(os.path.join(addonspath, module)) > mod_time(os.path.join(addonspath, "{}{}.pbo".format(PREFIX,module)))
return mod_time(os.path.join(addonspath, module)) > mod_time(file)

def check_for_obsolete_pbos(addonspath, file):
"""Return True if the source directory for addon no longer exists"""
module = file[len(PREFIX):-4]
if not os.path.exists(os.path.join(addonspath, module)):
return True
return False

def main():
def main(): # pylint: disable=missing-function-docstring
print("""
###################
# CBA Debug Build #
Expand All @@ -51,7 +62,8 @@ def main():
projectpath = os.path.dirname(os.path.dirname(scriptpath))
addonspath = os.path.join(projectpath, "addons")

if (tryHemttBuild(projectpath)): return
if try_hemtt_build(projectpath):
return

os.chdir(addonspath)

Expand All @@ -68,42 +80,43 @@ def main():
os.remove(file)
print("")

for p in os.listdir(addonspath):
path = os.path.join(addonspath, p)
for name in os.listdir(addonspath):
path = os.path.join(addonspath, name)
if not os.path.isdir(path):
continue
if p[0] == ".":
if name[0] == ".":
continue
if not check_for_changes(addonspath, p):
if not check_for_changes(addonspath, name):
skipped += 1
print(" Skipping {}.".format(p))
print(" Skipping {}.".format(name))
continue

print("# Making {} ...".format(p))
print("# Making {} ...".format(name))

usescriptsfolder = os.path.join(path, "$SCRIPTSFOLDER$")
if os.path.isfile(usescriptsfolder):
pbopath = "-@=userconfig"
else:
pbopath = "-@={}\\{}\\addons\\{}".format(MAINPREFIX,PREFIX.rstrip("_"),p)
pbopath = "-@={}\\{}\\addons\\{}".format(MAINPREFIX, PREFIX.rstrip("_"), name)

try:
subprocess.check_output([
"makepbo",
"-NUP",
pbopath,
p,
"{}{}.pbo".format(PREFIX,p)
name,
"{}{}.pbo".format(PREFIX, name)
], stderr=subprocess.STDOUT)
except:
except subprocess.CalledProcessError as err:
failed += 1
print(" Failed to make {}.".format(p))
print(" Failed to make {} ({}).".format(name, err))
else:
made += 1
print(" Successfully made {}.".format(p))
print(" Successfully made {}.".format(name))

print("\n# Done.")
print(" Made {}, skipped {}, removed {}, failed to make {}.".format(made, skipped, removed, failed))
print(" Made {}, skipped {}, removed {}, failed to make {}.".format(made, skipped,
removed, failed))


if __name__ == "__main__":
Expand Down