Skip to content

Commit

Permalink
Pylint fixes for build.py
Browse files Browse the repository at this point in the history
  • Loading branch information
Killswitch00 committed Feb 6, 2021
1 parent ba5c8ea commit 8caac1d
Showing 1 changed file with 39 additions and 25 deletions.
64 changes: 39 additions & 25 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,48 @@
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():
"""main"""
print("""
###################
# CBA Debug Build #
Expand All @@ -51,7 +63,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 +81,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

0 comments on commit 8caac1d

Please sign in to comment.