Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Jampi0n committed Jul 2, 2021
0 parents commit 1596b0c
Show file tree
Hide file tree
Showing 39 changed files with 2,583 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
# Auto detect text files and perform LF normalization
* text=auto
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Release
1 change: 1 addition & 0 deletions Build Scripts/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
__pycache__
82 changes: 82 additions & 0 deletions Build Scripts/clean_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
import argparse
import os
import pathlib
import project_config


def clean_directory(args, config):
include = args.include.split(',') if args.include is not None else []
exclude = args.exclude.split(',') if args.exclude is not None else []
for mod_dir in config.mod_directories:
dir_path = pathlib.Path(mod_dir).joinpath(pathlib.Path(args.directory))
for root, dir_names, walk_files in os.walk(dir_path, topdown=False):
for file_name in walk_files:
include_file = False
if len(include) > 0:
for i in include:
if i[0] == '*':
if file_name.endswith(i[1:]):
include_file = True
break
else:
if file_name == i:
include_file = True
break
else:
include_file = True

if include_file:
if len(exclude) > 0:
for e in exclude:
if e[0] == '*':
if file_name.endswith(e[1:]):
include_file = False
break
else:
if file_name == e:
include_file = False
break

if include_file:
remove_path = os.path.join(root, file_name)
os.remove(remove_path)
for dir_name in dir_names:
try:
os.rmdir(os.path.join(root, dir_name))
except OSError:
pass
if args.root:
try:
os.rmdir(dir_path)
except OSError:
pass


def main():
parser = argparse.ArgumentParser()
parser.add_argument('directory', type=str, help='The directory, whose files are copied.')
parser.add_argument('-i', '--include', type=str,
help=' By default, all files are included.'
' Use * at the start to match suffixes:"*.txt".'
' Use , to combine included files:"*.txt,meta.ini"')
parser.add_argument('-e', '--exclude', type=str,
help=' By default, no files are excluded.'
' Use * at the start to match suffixes:"*.txt".'
' Use , to combine excluded files:"*.txt,meta.ini"')
parser.add_argument('-S', '--SE', action='store_true', help='Only copy for SE.')
parser.add_argument('-L', '--LE', action='store_true', help='Only copy for LE.')
parser.add_argument('-r', '--root', action='store_true', help='Removes the specified directory, if it is empty.')

args = parser.parse_args()

if not args.LE and not args.SE:
args.LE = True
args.SE = True

config = project_config.Config(args.LE, args.SE)

clean_directory(args, config)


if __name__ == '__main__':
main()
94 changes: 94 additions & 0 deletions Build Scripts/copy_files.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import argparse
import shutil
import os
import pathlib
import project_config

def copy_file(args, config):
for mod_dir in config.mod_directories:
path = mod_dir.joinpath(pathlib.Path(args.target))
if not os.path.exists(path):
os.makedirs(path)
shutil.copy(args.file, path)


def copy_directory(args, config):
include = args.include.split(',') if args.include is not None else []
exclude = args.exclude.split(',') if args.exclude is not None else []
files = []
for root, _, walk_files in os.walk(args.directory, topdown=False):
for file_name in walk_files:
include_file = False
if len(include) > 0:
for i in include:
if i[0] == '*':
if file_name.endswith(i[1:]):
include_file = True
break
else:
if file_name == i:
include_file = True
break
else:
include_file = True

if include_file:
if len(exclude) > 0:
for e in exclude:
if e[0] == '*':
if file_name.endswith(e[1:]):
include_file = False
break
else:
if file_name == e:
include_file = False
break

if include_file:
files.append(os.path.join(root, file_name))

for mod_dir in config.mod_directories:
for file in files:
rel_path = os.path.relpath(file, args.directory)
path = mod_dir.joinpath(pathlib.Path(args.target).joinpath(pathlib.Path(rel_path))).parent
if not os.path.exists(path):
os.makedirs(path)
shutil.copy(file, path)


def main():
parser = argparse.ArgumentParser()
parser.add_argument('-f', '--file', type=str, help='The file to copy.')
parser.add_argument('-d', '--directory', type=str, help='The directory, whose files are copied.')
parser.add_argument('-t', '--target', type=str, help='The target location in which files are copied.')
parser.add_argument('-i', '--include', type=str,
help='If a directory is copied, these files will be included.'
' By default, all files are included.'
' Use * at the start to match suffixes:"*.txt".'
' Use , to combine included files:"*.txt,meta.ini"')
parser.add_argument('-e', '--exclude', type=str,
help='If a directory is copied, these files will be excluded.'
' By default, no files are excluded.'
' Use * at the start to match suffixes:"*.txt".'
' Use , to combine excluded files:"*.txt,meta.ini"')
parser.add_argument('-S', '--SE', action='store_true', help='Only copy for SE.')
parser.add_argument('-L', '--LE', action='store_true', help='Only copy for LE.')

args = parser.parse_args()

if not args.LE and not args.SE:
args.LE = True
args.SE = True

config = project_config.Config(args.LE, args.SE)

if args.file is not None and args.directory is None:
copy_file(args, config)
elif args.file is None and args.directory is not None:
copy_directory(args, config)
else:
print('Provide either a directory or file to copy.')


if __name__ == '__main__':
main()
29 changes: 29 additions & 0 deletions Build Scripts/project_config.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
import os
import pathlib
import json

class Config:
def __init__(self, le, se):
self.project_dir = pathlib.Path(__file__).parent

with open(self.project_dir.parent.joinpath(pathlib.Path('project.json'))) as f:
data = json.load(f)
self.version = data['version']
self.mod_name = data['name']
self.output = data['output']
self.identifier = data['identifier']

self.le = le
self.se = se

self.mod_directories = []


if le:
le_path = os.environ['SkyrimLEModPath']
assert le_path != "", "Set environment variable " + "SkyrimLEModPath" + "!"
self.mod_directories.append(pathlib.Path(le_path).joinpath(pathlib.Path(self.output)))
if se:
se_path = os.environ['SkyrimSEModPath']
assert se_path != "", "Set environment variable " + "SkyrimSEModPath" + "!"
self.mod_directories.append(pathlib.Path(se_path).joinpath(pathlib.Path(self.output)))
63 changes: 63 additions & 0 deletions Build Scripts/release.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
import zipfile
import os
import project_config
import argparse
import pathlib

def pack(name, env, dir_name):
prev_dir = os.getcwd()
path = os.environ[env]
assert path != "", "Set environment variable " + env + "!"
path = os.path.join(path, dir_name)
ignore_txt = str(pathlib.Path(__file__).parent.joinpath(pathlib.Path('release_ignore.txt')))
ignore_list_file = open(ignore_txt)
ignore_list = ignore_list_file.readlines()
ignore_list_file.close()

ignore_files = []
ignore_extensions = []

for line in ignore_list:
line = line[:-1]
if line.startswith('*.'):
ignore_extensions.append(line[1:])
else:
ignore_files.append(line)

pack_files = []

for root, _, files in os.walk(path, topdown=False):
for file_name in files:
ext = os.path.splitext(file_name)[1]
if ext not in ignore_extensions and file_name not in ignore_files:
pack_files.append(os.path.relpath(os.path.join(root, file_name), path))

zip_path = os.path.join(os.getcwd(), "Release", name)
pathlib.Path(os.path.join(os.getcwd(), "Release")).mkdir(exist_ok=True)
os.chdir(path)
with zipfile.ZipFile(zip_path, 'w') as zip_file:
for file in pack_files:
print(file)
zip_file.write(file)
os.chdir(prev_dir)


def main():
parser = argparse.ArgumentParser()
parser.add_argument('-S', '--SE', action='store_true', help='Only copy for SE.')
parser.add_argument('-L', '--LE', action='store_true', help='Only copy for LE.')
args = parser.parse_args()

if not args.LE and not args.SE:
args.LE = True
args.SE = True

config = project_config.Config(args.LE, args.SE)

if config.le:
pack(config.mod_name + ' LE ' + config.version + '.zip', 'SkyrimLEModPath', config.output)
if config.se:
pack(config.mod_name + ' SE ' + config.version + '.zip', 'SkyrimSEModPath', config.output)

if __name__ == '__main__':
main()
1 change: 1 addition & 0 deletions Build Scripts/release_ignore.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
meta.ini
Loading

0 comments on commit 1596b0c

Please sign in to comment.