Skip to content
This repository has been archived by the owner on Jul 17, 2020. It is now read-only.

Commit

Permalink
File Templating implemented
Browse files Browse the repository at this point in the history
  • Loading branch information
phumberdroz committed Mar 18, 2018
1 parent eaa08f7 commit 72c0e3f
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 4 deletions.
2 changes: 2 additions & 0 deletions .tf47Tools/.tf47Config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,5 @@ Info:
GitHub:
org: TaskForce47
repo: co40_domination_3_89_blufor.altis
Templates:
NAME_TPL: CO@64 Task Force Dagger Domination {ISLAND} Mod {VERSION}
45 changes: 41 additions & 4 deletions .tf47Tools/build.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@
cfg = yaml.load(ymlfile)
platform = sys.platform

label = sp.check_output(["git", "describe", "--tags"]).decode('ascii').strip().split("-")[0]
label = '{}-beta.{}'.format(label, os.environ["TRAVIS_BUILD_NUMBER"])


def createmapvariants():
path = '../.tf47MapVariants'
files = os.listdir(path)
for island in files:
if os.path.isdir(
os.path.join(os.path.abspath(path), island)): # check whether the current object is a folder or not
dest = "builds/{}.{}".format(cfg['Info']['project'], island)
dest = "builds/{}-{}.{}".format(cfg['Info']['project'], label, island)
# pathlib.Path().mkdir(parents=True, exist_ok=True)
shutil.copytree('../', dest,
ignore=shutil.ignore_patterns('.tf47Tools', '.tf47MapVariants', '.git', '.DS_Store',
'.gitignore', 'ma3a', '.tf47Attachments', '.travis.yml')

)


)
root_src_dir = os.path.join(os.path.abspath(path), island)
root_dst_dir = dest
for src_dir, dirs, files in os.walk(root_src_dir):
Expand All @@ -40,6 +41,32 @@ def createmapvariants():
shutil.copy(src_file, dst_dir)


def replaceTemplates():
path = 'builds'
files = ['mission.sqm', 'description.ext', 'x_client/x_intro.sqf']
cfg['Templates']['VERSION'] = label;
for island in os.listdir(path):
if os.path.isdir(os.path.join(os.path.abspath(path), island)):
cfg['Templates']['ISLAND'] = os.path.splitext(island)[1].strip('.').upper()
for file in files:
for template in cfg['Templates']:
filePath= "{}/{}/{}".format(path,island, file)
inplace_change(filePath, template, cfg['Templates'][template])


def inplace_change(filename, old_string, new_string):
with open(filename) as f:
s = f.read()
old_string = "{"+old_string+"}"
if old_string not in s:
print("\"{old_string}\" not found in {filename}.".format(**locals()))
return

with open(filename, 'w') as f:
s = s.replace(old_string, new_string)
f.write(s)


def createpbos():
path = 'builds'
files = os.listdir(path)
Expand Down Expand Up @@ -86,6 +113,16 @@ def main():
else:
print("created map variants")

print("\nUpdating Template Variables")
try:
replaceTemplates()
except:
print("could not update template variables")
print(traceback.format_exc())
exit(1)
else:
print("updated template variables")

print("\nCreating pbos")
try:
createpbos()
Expand Down

0 comments on commit 72c0e3f

Please sign in to comment.