-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathExportLibraries.py
94 lines (77 loc) · 3.16 KB
/
ExportLibraries.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
'''
* File: ExportLibraries.py
* Copyright (c) 2023 Loupe
* https://loupe.team
*
* This file is part of ASPython, licensed under the MIT License.
'''
"""
@title ExportLibraries
@description This file parses parameters from a file and uses them to
export libraries from an AS project
"""
import ASTools
import logging
import os.path
import shutil
import json
import sys
import copy
import ctypes
from _version import __version__
# TODO: Better support command line arguments
# TODO: Add option to support user input
if __name__ == "__main__":
default = {
"projectPath": "",
"buildMode": "Rebuild",
"Configs": [],
"exportPath": "",
"versionSubFolders": False,
"ignoreLibraries": []
}
paramFileName = 'ExportLibrariesParam.json'
# Set up logging and color-coding
logging.basicConfig(stream=sys.stderr, level=logging.INFO)
kernel32 = ctypes.windll.kernel32
kernel32.SetConsoleMode(kernel32.GetStdHandle(-11), 7)
# Write default params if none exist
if not os.path.exists(paramFileName):
logging.info('Parameter file: %s, not found. Creating file.', paramFileName)
with open(paramFileName, 'x') as f:
f.write(json.dumps(default, indent=2))
input("Please modify %s with desired params. Press Enter to continue..." % paramFileName)
try:
data = copy.deepcopy(default) # Use deep copy instead of copy so that we don't modify default's non primitive values
# Read parameters
with open(paramFileName) as param:
data.update(json.load(param))
# Parse project
project = ASTools.Project(data.get('projectPath'))
if not data.get('Configs'):
data['Configs'] = project.buildConfigNames
# Update parameters with missing keys
with open(paramFileName, 'w') as param:
param.write(json.dumps(data, indent=2))
# Build project
if data.get('buildMode') != 'None':
process = project.build(*data.get('Configs'), buildMode=data.get('buildMode'))
logging.info('Project batch build complete, code %d', process.returncode)
if process.returncode > ASTools.ASReturnCodes["Warnings"]:
sys.exit(process.returncode)
# Export
results = project.exportLibraries(data.get('exportPath'), overwrite=True, ignores=data.get('ignoreLibraries'), includeVersion=data.get('versionSubFolders'))
for result in results.failed:
logging.error('\033[31mFailed to export %s to %s because %s\033[0m', result.name, result.path, result.exception)
# Remove libraries that failed exports
try:
shutil.rmtree(result.path, onerror=ASTools.Library._rmtreeOnError)
except FileNotFoundError as identifier:
logging.debug('Failed to delete fail export lib, does not exist: %s', result.path)
except:
logging.exception('Failed to delete: %s, because %s', result.path, sys.exc_info()[0])
logging.info('Export Complete!')
except:
logging.exception('Error occurred: %s', sys.exc_info()[0])
pass
sys.exit(0)