Skip to content

Commit f5411b2

Browse files
committed
it can make releases
1 parent b547360 commit f5411b2

File tree

3 files changed

+94
-26
lines changed

3 files changed

+94
-26
lines changed

README.md

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,8 @@
1-
# UIX-R
2-
Ultima IX: Redemption for Morrowind and OpenMW
1+
# Ultima IX: Redemption for Morrowind and OpenMW
2+
3+
Morrowind Mod UIX – landscape, story and music release – history of the mod and the team.:
4+
http://www.titansofether.com/uix/
5+
6+
##
7+
8+

make_release.py

Lines changed: 56 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,69 @@
11
#!/usr/bin/python
22
import csv
3+
import glob
4+
from nif_walker import walk_nif
35
import os
6+
import sys
47
import tarfile
58

69
RELEASE_PATH = "uixr-assets-cc0-1.0.tar.gz"
10+
ASSET_PATH = "../../../Private"
711

8-
with open("Manifests/UIXR.manifest") as f:
9-
uixr_data = csv.DictReader(f)
1012

11-
tar_ball = tarfile.open(RELEASE_PATH, "w:")
13+
def spinning_cursor():
14+
while True:
15+
for cursor in '|/-\\':
16+
yield cursor
17+
1218

19+
def get_filename(string):
20+
return os.path.basename(string.replace("\\", "/"))
21+
22+
23+
with open("Manifests/UIXR.manifest") as f:
24+
uixr_data = csv.DictReader(f)
25+
tar_ball = tarfile.open(RELEASE_PATH, "w:gz")
26+
spinner = spinning_cursor()
27+
additional_assets = []
28+
print("Gathering assets: ")
1329
for row in uixr_data:
1430
if row.get('license').upper() == 'CC0':
15-
tar_ball.add(os.path.join('../../../Private', row.get('asset')), row.get('asset'))
31+
sys.stdout.write("\033[K")
32+
sys.stdout.write(next(spinner))
33+
sys.stdout.write(" [{0}]".format(row.get('asset')))
34+
sys.stdout.flush()
35+
sys.stdout.write('\r\b')
36+
file_path = os.path.join(ASSET_PATH, row.get('asset'))
37+
tar_ball.add(file_path, row.get('asset'))
38+
39+
# check that we have all related assets
40+
nif_assets = walk_nif(nif_path=file_path, use_stdout=False)
41+
for asset_string in nif_assets:
42+
for asset in asset_string.split(', '):
43+
additional_assets.append(get_filename(asset))
44+
45+
additional_assets = set(additional_assets)
46+
47+
# remove blank entry in set
48+
if '' in additional_assets:
49+
additional_assets.remove('')
50+
51+
# iterate through all sub assets
52+
for nif_asset in additional_assets:
53+
for asset_path in glob.iglob(os.path.join(ASSET_PATH, "UIX", "**", nif_asset), recursive=True):
54+
relative_asset_path = os.path.relpath(os.path.realpath(asset_path), ASSET_PATH)
55+
if relative_asset_path in tar_ball.getnames():
56+
continue # file already exists, skip
57+
sys.stdout.write("\033[K")
58+
sys.stdout.write(next(spinner))
59+
sys.stdout.write(" [{0}]".format(relative_asset_path))
60+
sys.stdout.flush()
61+
sys.stdout.write('\r\b')
62+
if relative_asset_path == '.':
63+
import pdb; pdb.set_trace()
64+
continue # skip this before we pull in everything
65+
66+
tar_ball.add(asset_path, relative_asset_path)
67+
# print("Additional asset: {0}".format(relative_asset_path))
1668

1769
tar_ball.close()

nif_walker.py

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,10 @@
11
from pyffi.formats.nif import NifFormat
22
from os import path
3-
from sys import exit, stdout
3+
from sys import argv, exit, stdout
44

5-
UIX_PATH = "../../../Private/UIX/UIX FILES/Data Files/"
5+
# UIX_PATH = "../../../Private/UIX/UIX FILES/Data Files/"
66
# UIX_PATH = "../../../Private/UIX/UIX FILES/Data Files/Meshes/TOE/RedMoonGa01.NIF"
77

8-
if not path.exists(UIX_PATH):
9-
exit("Path `{0}` not found.".format(UIX_PATH))
10-
118

129
def find_external_assets(data, assets):
1310
""" recursively find any external assets linked into a nif"""
@@ -50,20 +47,33 @@ def find_external_assets(data, assets):
5047
find_external_assets(data.decal_3_texture.source, assets)
5148

5249

53-
for stream, data in NifFormat.walkData(UIX_PATH):
54-
try:
55-
print(stream.name, sep='', end=', ', file=stdout, flush=True)
56-
data.read(stream)
57-
assets = []
58-
find_external_assets(data.roots, assets)
59-
assets = set(assets) # remove duplicates
60-
assets_string = "{0}".format(b', '.join(assets).decode(encoding="ISO-8859-1"))
61-
print(assets_string, sep=', ', end='\n', file=stdout, flush=True)
62-
# import pdb; pdb.set_trace()
63-
except ValueError as ex:
64-
print(" Error: {0}".format(str(ex.args)), sep='', end='\n', file=stdout, flush=True)
65-
except Exception as ex:
66-
print(ex)
67-
raise
50+
def walk_nif(nif_path, use_stdout=True):
51+
if not path.exists(nif_path):
52+
exit("Path `{0}` not found.".format(nif_path))
53+
54+
all_assets = []
55+
for stream, data in NifFormat.walkData(nif_path):
56+
try:
57+
if use_stdout:
58+
print(stream.name, sep='', end=', ', file=stdout, flush=True)
59+
data.read(stream)
60+
assets = []
61+
find_external_assets(data.roots, assets)
62+
assets = set(assets) # remove duplicates
63+
assets_string = "{0}".format(b', '.join(assets).decode(encoding="ISO-8859-1"))
64+
all_assets.append(assets_string)
65+
if use_stdout:
66+
print(assets_string, sep=', ', end='\n', file=stdout, flush=True)
67+
except ValueError as ex:
68+
print(" Error with {0}: {1}".format(stream.name, str(ex.args)), sep='', end='\n', file=stdout, flush=True)
69+
except Exception as ex:
70+
print(ex)
71+
raise
72+
return all_assets
6873

6974

75+
if __name__ == "__main__":
76+
if len(argv) == 2:
77+
walk_nif(argv[1])
78+
else:
79+
exit("No path given.")

0 commit comments

Comments
 (0)