-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmake.py
59 lines (48 loc) · 1.93 KB
/
make.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
#!/usr/bin/env python3
# -*- coding: utf-8 -*-
"""
Script to build the mod into a zip archive for Factorio.
"""
import json
import os
import pathlib
import zipfile
info = {
"name": "LaNMod",
"version": "0.1.1",
"title": "LaNMod",
"author": "h4ck3r_d00d",
"description": "Losers and Nitwits' Mod: For us mere mortals, make the game short enough to finish in the duration of a LAN party.",
"dependencies": ["base >= 0.17"],
"homepage": "https://github.com/asher-m/Factorio-LaNMod",
"factorio_version": "0.17"
}
""" The mod's settings and properties. """
modroot = "source"
""" Where the mod lives in this directory. """
target = "_".join((info['name'], info['version']))
""" The target zip file for the mod. """
# Do the pack here:
def main():
# Look up all files in the subdir:
with zipfile.ZipFile(f'{target}.zip', 'w', zipfile.ZIP_DEFLATED) as z:
# Handle all files:
for root, dirs, files in os.walk(modroot):
for f in files:
if ".xcf" not in f:
z.write(os.path.join(root, f), dest(root, f))
# Handle info.json, changelog.txt, README.md, (when I write it):
z.writestr(os.path.join(target, 'info.json'), json.dumps(info, indent=4))
z.write('CHANGELOG.md', os.path.join(target, 'CHANGELOG.md'))
if os.path.exists('README.md'):
z.write('README.md', os.path.join(target, 'README.md'))
if os.path.exists('LICENSE'):
z.write('LICENSE', os.path.join(target, 'LICENSE'))
# 0.17 and up require a thumbnail, so include it as well:
z.write('thumbnail/thumbnail.png', os.path.join(target, 'thumbnail.png'))
def dest(root, file):
""" Cut out the modroot and append the target dir because Factorio requires
mods to be in a dir in the zipfile by the Name_version that they are. """
return os.path.join(target, *pathlib.Path(root).parts[1:], file)
if __name__ == "__main__":
main()