-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #7 from lennart-g/feat/improve_stability
Feat/improve stability
- Loading branch information
Showing
13 changed files
with
201 additions
and
58 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import os.path | ||
import shutil | ||
|
||
# files to include in the output zip file | ||
files = [ | ||
"util/MD2.py", | ||
"md2_importer/__init__.py", | ||
"md2_importer/blender_load_md2.py", | ||
"util/prepare_skin_paths.py" | ||
] | ||
|
||
# intermediary location for the directory to be zipped | ||
dest = "build/io_import_md2" | ||
|
||
if os.path.exists("build") and os.path.isdir("build"): | ||
shutil.rmtree("build") | ||
os.makedirs(dest) | ||
|
||
for file in files: | ||
shutil.copyfile(file, os.path.join(dest, os.path.basename(file))) | ||
|
||
# create zip file | ||
shutil.make_archive("blender-md2-importer", 'zip', "build") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
import os | ||
from util import MD2 | ||
import pytest | ||
|
||
|
||
def test_models(): | ||
data_dir = "tests/data" | ||
models = os.listdir(data_dir) | ||
models = [x for x in models if x.lower().endswith(".md2")] | ||
|
||
for model in models: | ||
MD2.load_file(os.path.join(data_dir, model)) | ||
assert True | ||
|
||
|
||
def test_wrong_format(): | ||
with pytest.raises(ValueError): | ||
MD2.load_file('tests/data/car.jpg') | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
from util.prepare_skin_paths import * | ||
|
||
|
||
def test_get_path_from_skin_name(): | ||
obj_path = "blender-md2-importer/tests/data/car.md2" | ||
skin_name = "'models/sk89q/w_sitters/car.jpg\x00ght.jpg\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00" | ||
|
||
skin_path = get_path_from_skin_name(obj_path, skin_name) | ||
print(skin_path) | ||
assert skin_path == "blender-md2-importer/tests/data/car.jpg\x00ght.jpg" | ||
|
||
|
||
def test_get_existing_skin_path(): | ||
args = { | ||
'skin_path': 'tests/data/car.jpg\x00ght.jpg'} | ||
out = get_existing_skin_path(**args) | ||
assert out is None | ||
|
||
args = { | ||
'skin_path': 'tests/data/car.bmp'} | ||
out = get_existing_skin_path(**args) | ||
assert out == "tests/data/car.jpg" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import os | ||
|
||
|
||
def get_path_from_skin_name(md2_path: str, skin_name: str): | ||
# strings are always stored as 64 bytes, so unused bytes are set to '\x00' | ||
first_stored_path = skin_name.rstrip("\x00") | ||
# only first stored path is used since Digital Paintball 2 only uses that one | ||
first_stored_path = first_stored_path.split("/")[-1] | ||
print(f'first_stored_path: {first_stored_path}') | ||
# absolute path is formed by using the given md2 object path | ||
absolute_first_stored_path = "/".join(md2_path.split("/")[:-1]) + "/" + first_stored_path | ||
print(f'absolute_first_stored_path: {absolute_first_stored_path}') | ||
skin_path = absolute_first_stored_path | ||
|
||
return skin_path | ||
|
||
|
||
def get_existing_skin_path(skin_path: str): | ||
""" | ||
Replaces the skin path extension with the one of an existing file of the same name. | ||
""" | ||
""" Look for existing file of given name and supported image format """ | ||
supported_image_formats = [".png", ".jpg", ".jpeg", ".tga", ".pcx"] # Order doesn't match DP2 image order | ||
skin_path_unextended = os.path.splitext(skin_path)[0] # remove extension (last one) | ||
print(f'skin_path_unextended: {skin_path_unextended}') | ||
for format in supported_image_formats: | ||
full_path = skin_path_unextended + format | ||
print(f'full_path: {full_path}') | ||
if os.path.isfile(full_path): | ||
skin_path = skin_path_unextended + format | ||
return skin_path |