浏览代码

Python script to manage sub-packages

/main
Peter Bay Bastian 7 年前
当前提交
4bf904de
共有 10 个文件被更改,包括 158 次插入0 次删除
  1. 4
      ScriptableRenderPipeline/Core/sub-package.json
  2. 7
      ScriptableRenderPipeline/Core/sub-package.json.meta
  3. 7
      ScriptableRenderPipeline/HDRenderPipeline/sub-package.json
  4. 7
      ScriptableRenderPipeline/HDRenderPipeline/sub-package.json.meta
  5. 7
      ScriptableRenderPipeline/LightweightPipeline/sub-package.json
  6. 7
      ScriptableRenderPipeline/LightweightPipeline/sub-package.json.meta
  7. 7
      ScriptableRenderPipeline/master-package.json
  8. 7
      ScriptableRenderPipeline/master-package.json.meta
  9. 98
      subpackage.py
  10. 7
      subpackage.py.meta

4
ScriptableRenderPipeline/Core/sub-package.json


{
"name": "com.unity.render-pipelines.core",
"description": "Core library for Unity render pipelines."
}

7
ScriptableRenderPipeline/Core/sub-package.json.meta


fileFormatVersion: 2
guid: 19cc002a0d5c3344abceed8a406f9296
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
ScriptableRenderPipeline/HDRenderPipeline/sub-package.json


{
"name": "com.unity.render-pipelines.high-quality",
"description": "High Quality Render Pipeline for Unity.",
"subDependencies": [
"com.unity.render-pipelines.core"
]
}

7
ScriptableRenderPipeline/HDRenderPipeline/sub-package.json.meta


fileFormatVersion: 2
guid: f8cbf85f29fda9b428c69f2db95d6586
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
ScriptableRenderPipeline/LightweightPipeline/sub-package.json


{
"name": "com.unity.render-pipelines.lightweight",
"description": "Lightweight Render Pipeline for Unity.",
"subDependencies": [
"com.unity.render-pipelines.core"
]
}

7
ScriptableRenderPipeline/LightweightPipeline/sub-package.json.meta


fileFormatVersion: 2
guid: c82f6b5803136ae4dad320ae444c5bae
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

7
ScriptableRenderPipeline/master-package.json


{
"version": "0.1.6",
"unity": "2018.1",
"dependencies": {
"com.unity.postprocessing": "0.1.2"
}
}

7
ScriptableRenderPipeline/master-package.json.meta


fileFormatVersion: 2
guid: bfb9f6845cd8f864dabdaab6815b2ec4
TextScriptImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:

98
subpackage.py


import argparse
import os
import json
import textwrap
from pprint import pprint
def main():
parser = argparse.ArgumentParser()
parser.add_argument("folder", help="the folder containing master-package.json and the sub-package folders")
parser.add_argument("-v", "--verbose", action="store_true", help="tell me what's going on here")
args = parser.parse_args()
verbose = args.verbose
base_folder = os.path.realpath(args.folder)
def error_print(msg):
print("[ERROR] {}".format(msg))
def warning_print(msg):
print("[WARNING] {}".format(msg))
def info_print(msg):
if verbose:
print(msg)
info_print("Using folder: {}".format(base_folder))
file_path = os.path.join(base_folder, "master-package.json")
if os.path.isfile(file_path):
info_print("Found master package file: {}".format(file_path))
with open(file_path) as file:
try:
master_package = json.load(file)
except json.JSONDecodeError as e:
error_print("Error: {}".format(e))
exit(1)
sub_packages = []
sub_package_folders = []
for item in os.listdir(base_folder):
file_path = os.path.join(base_folder, item, "sub-package.json")
if os.path.isfile(file_path):
info_print("Found sub-package file: {}".format(file_path))
with open(file_path) as file:
try:
sub_packages.append(json.load(file))
sub_package_folders.append(os.path.join(base_folder, item))
except json.JSONDecodeError as e:
error_print("Error: {}".format(e))
if not sub_packages:
error_print("Error: No sub-packages found.")
exit(1)
if "version" not in master_package:
error_print("Master package must contain a \"version\" field")
exit(1)
info_print("Propagating master package version to sub-packages")
for sub_package in sub_packages:
sub_package["version"] = master_package["version"]
if "unity" in master_package:
info_print("Propagating master package Unity version to sub-packages")
for sub_package in sub_packages:
sub_package["unity"] = master_package["unity"]
if "dependencies" in master_package and master_package["dependencies"]:
info_print("Propagating shared dependencies:")
for name, version in master_package["dependencies"].items():
info_print("\t{}@{}".format(name, version))
for sub_package in sub_packages:
if "dependencies" not in sub_package or not sub_package["dependencies"]:
sub_package["dependencies"] = {}
for name, version in master_package["dependencies"].items():
sub_package["dependencies"][name] = version
info_print("Resolving dependencies between sub-packages:")
for sub_package in sub_packages:
if "dependencies" not in sub_package or not sub_package["dependencies"]:
sub_package["dependencies"] = {}
if "subDependencies" in sub_package and sub_package["subDependencies"]:
info_print("\t{}:".format(sub_package["name"]))
for sub_dependency in sub_package["subDependencies"]:
sub_package["dependencies"][sub_dependency] = master_package["version"]
info_print("\t\t{}@{}".format(sub_dependency, sub_package["dependencies"][sub_dependency]))
del sub_package["subDependencies"]
info_print("Writing package files:")
for i, sub_package in enumerate(sub_packages):
package_path = os.path.join(sub_package_folders[i], "package.json")
info_print("\t{}".format(package_path))
with open(package_path, 'w') as file:
json.dump(sub_package, file, indent=4)
if __name__ == "__main__":
main()

7
subpackage.py.meta


fileFormatVersion: 2
guid: 3d3df49a7b5058140930a337930ab97c
DefaultImporter:
externalObjects: {}
userData:
assetBundleName:
assetBundleVariant:
正在加载...
取消
保存