-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpulley.py
99 lines (75 loc) · 3.88 KB
/
pulley.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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
# Pulley
# A tool to import content from Source Engine games into other Source Engine games
# Pulley is licensed under GNU GPLv3.
import json
import pathlib
import os
import vpk
import PulleyLib.Logging as PulleyLog
import PulleyLib.Importers.VPK.MDL as PulleyVPK_MDLImport
import PulleyLib.Importers.VPK.Other as PulleyVPK_OtherImport
import PulleyLib.Importers.FS.MDL as PulleyFS_MDLImport
import PulleyLib.Importers.FS.Other as PulleyFS_OtherImport
print("== Pulley v1.0 ==\n=== By AyeTSG ===\n")
# PulleyLog.General("Using profile " + PROFILE)
# Read the content config JSON
with open("pulley_config.json", "r") as file:
content_config = json.load(file)
DEPOT_PATH = content_config["config"]["paths"]["depots"]
# Function: Import a file from a VPK archive
def import_vpk_file(import_path, profile_name):
# Print some debug info
PulleyLog.VPKImport("Attempting to import '" + import_path + "'")
# Get the file extension
file_ext = pathlib.Path(import_path).suffix
# Open the VPK for reading
vpk_file = vpk.open(content_config["profiles"][profile_name]["content_dir"])
# Special cases
if (file_ext == ".mdl"):
PulleyVPK_MDLImport.import_file(import_path, vpk_file, DEPOT_PATH, content_config, profile_name)
return
# If it didn't match the above cases, use general importing
PulleyVPK_OtherImport.import_file(import_path, vpk_file, DEPOT_PATH, content_config, profile_name)
return
# Function: Import a file from FS
def import_fs_file(import_path, profile_name):
# Print some debug info
PulleyLog.FSImport("Attempting to import '" + import_path + "'")
# Get the file extension
file_ext = pathlib.Path(import_path).suffix
# Special cases
if (file_ext == ".mdl"):
PulleyFS_MDLImport.import_file(import_path, DEPOT_PATH, content_config, profile_name)
return
# General import the file
PulleyFS_OtherImport.import_file(import_path, DEPOT_PATH, content_config, profile_name)
return
# Function: Process a pulley profile
def process_profile(profile_name):
# Check if we use VPK's in this profile
if (content_config["profiles"][profile_name]["uses_vpk"] == True):
# Print some debug info
PulleyLog.General("Importing content into the '" + content_config["profiles"][profile_name]["depot_to_import_to"] + "' depot\n")
# Check if the depot exists
if (os.path.exists(DEPOT_PATH + content_config["profiles"][profile_name]["depot_to_import_to"]) == False):
print("DepotCheck: Creating depot '" + content_config["profiles"][profile_name]["depot_to_import_to"] + "'... Don't forget to add it to gameinfo.txt\n")
os.mkdir(DEPOT_PATH + content_config["profiles"][profile_name]["depot_to_import_to"])
# Loop over each importing file
for import_file in content_config["profiles"][profile_name]["content_to_import"]:
import_vpk_file(import_file, profile_name)
else:
#print("ERROR: Non-VPK importing not yet implemented!")
#exit()
# Print some debug info
PulleyLog.General("Importing content into the '" + content_config["profiles"][profile_name]["depot_to_import_to"] + "' depot\n")
# Check if the depot exists
if (os.path.exists(DEPOT_PATH + content_config["profiles"][profile_name]["depot_to_import_to"]) == False):
print("DepotCheck: Creating depot '" + content_config["profiles"][profile_name]["depot_to_import_to"] + "'... Don't forget to add it to gameinfo.txt\n")
os.mkdir(DEPOT_PATH + content_config["profiles"][profile_name]["depot_to_import_to"])
# Loop over each importing file
for import_file in content_config["profiles"][profile_name]["content_to_import"]:
import_fs_file(import_file, profile_name)
# For each profile
for profile in content_config["config"]["profiles_to_run"]:
# Process the profile
process_profile(profile)