2019-11-24 01:05:25 +01:00
|
|
|
#!/usr/bin/env python
|
|
|
|
|
|
|
|
# This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
|
|
|
# file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
|
|
|
|
|
|
|
EnsureSConsVersion(0, 98, 1)
|
|
|
|
|
|
|
|
import sys
|
|
|
|
import os
|
|
|
|
import subprocess
|
|
|
|
import json
|
|
|
|
import shutil
|
|
|
|
|
2019-12-01 23:32:36 +01:00
|
|
|
repository_index = 0
|
2019-11-24 01:05:25 +01:00
|
|
|
module_clone_path = '/modules/'
|
|
|
|
clone_command = 'git clone {0} {1}'
|
|
|
|
|
2019-12-01 23:32:36 +01:00
|
|
|
engine_repository = [ ['https://github.com/godotengine/godot.git', 'https://github.com/godotengine/godot.git'], 'engine', '' ]
|
2019-11-24 01:05:25 +01:00
|
|
|
|
|
|
|
module_repositories = [
|
2019-12-01 23:32:36 +01:00
|
|
|
[ ['https://github.com/Relintai/world_generator.git', 'git@github.com:Relintai/world_generator.git'], 'world_generator', '' ],
|
|
|
|
[ ['https://github.com/Relintai/entity_spell_system.git', 'git@github.com:Relintai/entity_spell_system.git'], 'entity_spell_system', '' ],
|
|
|
|
[ ['https://github.com/Relintai/ui_extensions.git', 'git@github.com:Relintai/ui_extensions.git'], 'ui_extensions', '' ],
|
|
|
|
[ ['https://github.com/Relintai/voxelman.git', 'git@github.com:Relintai/voxelman.git'], 'voxelman', '' ],
|
|
|
|
[ ['https://github.com/Relintai/texture_packer.git', 'git@github.com:Relintai/texture_packer.git'], 'texture_packer', '' ],
|
|
|
|
[ ['https://github.com/Relintai/godot_fastnoise.git', 'git@github.com:Relintai/godot_fastnoise.git'], 'fastnoise', '' ],
|
2019-11-24 01:05:25 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
addon_repositories = [
|
2019-12-01 23:32:36 +01:00
|
|
|
[['https://github.com/Relintai/entity-spell-system-addons.git', 'git@github.com:Relintai/entity-spell-system-addons.git'], 'entity-spell-system-addons', 'addons' ],
|
2019-11-24 01:05:25 +01:00
|
|
|
]
|
|
|
|
|
|
|
|
third_party_addon_repositories = [
|
|
|
|
]
|
|
|
|
|
|
|
|
target_commits = {}
|
|
|
|
|
|
|
|
def load_target_commits_array():
|
2019-12-03 19:30:12 +01:00
|
|
|
global target_commits
|
|
|
|
|
2019-11-24 01:05:25 +01:00
|
|
|
if os.path.isfile('./HEADS'):
|
|
|
|
with open('./HEADS', 'r') as infile:
|
|
|
|
target_commits = json.load(infile)
|
|
|
|
else:
|
2019-12-03 19:30:12 +01:00
|
|
|
target_commits = {}
|
2019-11-24 01:05:25 +01:00
|
|
|
|
|
|
|
def save_target_commits_array():
|
|
|
|
with open('./HEADS', 'w') as outfile:
|
|
|
|
json.dump(target_commits, outfile)
|
|
|
|
|
|
|
|
def update_repository(data, clone_path):
|
|
|
|
cwd = os.getcwd()
|
|
|
|
|
|
|
|
full_path = cwd + clone_path + data[1] + '/'
|
|
|
|
|
|
|
|
if not os.path.isdir(full_path):
|
|
|
|
os.chdir(cwd + clone_path)
|
|
|
|
|
2019-12-01 23:32:36 +01:00
|
|
|
subprocess.call(clone_command.format(data[0][repository_index], data[1]), shell=True)
|
2019-11-24 01:05:25 +01:00
|
|
|
|
|
|
|
os.chdir(full_path)
|
|
|
|
|
|
|
|
subprocess.call('git reset --hard', shell=True)
|
|
|
|
subprocess.call('git pull origin master', shell=True)
|
|
|
|
subprocess.call('git checkout master', shell=True)
|
|
|
|
subprocess.call('git reset --hard', shell=True)
|
|
|
|
|
|
|
|
process = subprocess.Popen('git rev-parse HEAD', shell=True, stdout=subprocess.PIPE, stderr=subprocess.STDOUT)
|
|
|
|
output = process.communicate()[0].decode().strip()
|
|
|
|
target_commits[data[1]] = output
|
|
|
|
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
|
|
def setup_repository(data, clone_path):
|
|
|
|
cwd = os.getcwd()
|
|
|
|
|
|
|
|
full_path = cwd + clone_path + data[1] + '/'
|
|
|
|
|
|
|
|
if not os.path.isdir(full_path):
|
|
|
|
os.chdir(cwd + clone_path)
|
|
|
|
|
2019-12-01 23:32:36 +01:00
|
|
|
subprocess.call(clone_command.format(data[0][repository_index], data[1]), shell=True)
|
2019-11-24 01:05:25 +01:00
|
|
|
|
|
|
|
os.chdir(full_path)
|
|
|
|
|
|
|
|
subprocess.call('git reset --hard', shell=True)
|
|
|
|
subprocess.call('git pull origin master', shell=True)
|
|
|
|
|
|
|
|
target = 'master'
|
|
|
|
|
|
|
|
if data[1] in target_commits:
|
|
|
|
target = target_commits[data[1]]
|
|
|
|
|
|
|
|
subprocess.call('git checkout ' + target, shell=True)
|
|
|
|
subprocess.call('git reset --hard', shell=True)
|
|
|
|
|
|
|
|
os.chdir(cwd)
|
|
|
|
|
|
|
|
def copy_repository(data, target_folder, clone_path):
|
2019-11-24 17:00:16 +01:00
|
|
|
copytree(os.path.abspath(clone_path + data[1] + '/' + data[2]), os.path.abspath(target_folder + data[1]))
|
|
|
|
|
|
|
|
def copy_addon_repository(data, target_folder, clone_path):
|
2019-11-24 01:05:25 +01:00
|
|
|
copytree(os.path.abspath(clone_path + data[1] + '/' + data[2]), os.path.abspath(target_folder))
|
|
|
|
|
|
|
|
def copytree(src, dst):
|
|
|
|
for item in os.listdir(src):
|
|
|
|
sp = os.path.join(src, item)
|
|
|
|
dp = os.path.join(dst, item)
|
|
|
|
|
|
|
|
if os.path.isdir(sp):
|
|
|
|
if os.path.isdir(dp):
|
|
|
|
shutil.rmtree(dp)
|
|
|
|
|
|
|
|
shutil.copytree(sp, dp)
|
|
|
|
else:
|
|
|
|
shutil.copy2(sp, dp)
|
|
|
|
|
|
|
|
def update_engine():
|
|
|
|
update_repository(engine_repository, '/')
|
|
|
|
|
|
|
|
def update_modules():
|
|
|
|
for rep in module_repositories:
|
|
|
|
update_repository(rep, module_clone_path)
|
|
|
|
copy_repository(rep, './engine/modules/', '.' + module_clone_path)
|
|
|
|
|
|
|
|
def update_addons():
|
|
|
|
for rep in addon_repositories:
|
|
|
|
update_repository(rep, module_clone_path)
|
2019-11-24 17:00:16 +01:00
|
|
|
copy_addon_repository(rep, './game/addons/', '.' + module_clone_path)
|
2019-11-24 01:05:25 +01:00
|
|
|
|
|
|
|
def update_addons_third_party_addons():
|
|
|
|
for rep in third_party_addon_repositories:
|
|
|
|
update_repository(rep, module_clone_path)
|
2019-11-24 17:00:16 +01:00
|
|
|
copy_addon_repository(rep, './game/addons/', '.' + module_clone_path)
|
2019-11-24 01:05:25 +01:00
|
|
|
|
|
|
|
def update_all():
|
|
|
|
update_engine()
|
|
|
|
update_modules()
|
|
|
|
update_addons()
|
|
|
|
update_addons_third_party_addons()
|
|
|
|
|
|
|
|
save_target_commits_array()
|
|
|
|
|
|
|
|
|
|
|
|
def setup_engine():
|
|
|
|
setup_repository(engine_repository, '/')
|
|
|
|
|
|
|
|
def setup_modules():
|
|
|
|
for rep in module_repositories:
|
|
|
|
setup_repository(rep, module_clone_path)
|
|
|
|
copy_repository(rep, './engine/modules/', '.' + module_clone_path)
|
|
|
|
|
|
|
|
def setup_addons():
|
|
|
|
for rep in addon_repositories:
|
|
|
|
setup_repository(rep, module_clone_path)
|
2019-11-24 17:00:16 +01:00
|
|
|
copy_addon_repository(rep, './game/addons/', '.' + module_clone_path)
|
2019-11-24 01:05:25 +01:00
|
|
|
|
|
|
|
def setup_addons_third_party_addons():
|
|
|
|
for rep in third_party_addon_repositories:
|
|
|
|
setup_repository(rep, module_clone_path)
|
2019-11-24 17:00:16 +01:00
|
|
|
copy_addon_repository(rep, './game/addons/', '.' + module_clone_path)
|
2019-11-24 01:05:25 +01:00
|
|
|
|
|
|
|
def setup_all():
|
|
|
|
setup_engine()
|
|
|
|
setup_modules()
|
|
|
|
setup_addons()
|
|
|
|
setup_addons_third_party_addons()
|
|
|
|
|
|
|
|
env = Environment()
|
|
|
|
opts = Variables(args=ARGUMENTS)
|
|
|
|
|
|
|
|
opts.Add('a', 'What to do', '')
|
|
|
|
opts.Add(EnumVariable('action', 'What to do', 'setup', ('setup', 'update')))
|
|
|
|
opts.Add('t', 'Action target', '')
|
|
|
|
opts.Add(EnumVariable('target', 'Action target', 'all', ('all', 'engine', 'modules', 'all_addons', 'addons', 'third_party_addons')))
|
2019-12-01 23:32:36 +01:00
|
|
|
opts.Add(EnumVariable('repository_type', 'Type of repositories to clone from first', 'http', ('http', 'ssh')))
|
2019-11-24 01:05:25 +01:00
|
|
|
|
|
|
|
opts.Update(env)
|
|
|
|
Help(opts.GenerateHelpText(env))
|
|
|
|
|
2019-12-03 19:30:12 +01:00
|
|
|
load_target_commits_array()
|
|
|
|
|
2019-12-01 23:38:22 +01:00
|
|
|
rt = env['repository_type']
|
2019-12-01 23:32:36 +01:00
|
|
|
|
|
|
|
if rt == 'ssh':
|
|
|
|
repository_index = 1
|
|
|
|
|
2019-11-24 01:05:25 +01:00
|
|
|
action = env['action']
|
|
|
|
target = env['target']
|
|
|
|
|
|
|
|
if env['a']:
|
|
|
|
action = env['a']
|
|
|
|
|
|
|
|
if env['t']:
|
|
|
|
target = env['t']
|
|
|
|
|
|
|
|
if not os.path.isdir('./modules'):
|
|
|
|
os.mkdir('./modules')
|
|
|
|
|
|
|
|
|
|
|
|
if action == 'setup' or action == 's':
|
|
|
|
if target == 'all':
|
|
|
|
setup_all()
|
|
|
|
elif target == 'engine':
|
|
|
|
setup_engine()
|
|
|
|
elif target == 'modules':
|
|
|
|
setup_modules()
|
|
|
|
elif target == 'all_addons':
|
|
|
|
setup_addons()
|
|
|
|
setup_addons_third_party_addons()
|
|
|
|
elif target == 'addons':
|
|
|
|
setup_addons()
|
|
|
|
elif target == 'third_party_addons':
|
|
|
|
setup_addons_third_party_addons()
|
|
|
|
elif action == 'update' or action == 'u':
|
|
|
|
if target == 'all':
|
|
|
|
update_all()
|
|
|
|
elif target == 'engine':
|
|
|
|
update_engine()
|
2019-11-25 12:11:41 +01:00
|
|
|
save_target_commits_array()
|
2019-11-24 01:05:25 +01:00
|
|
|
elif target == 'modules':
|
|
|
|
update_modules()
|
2019-11-25 12:11:41 +01:00
|
|
|
save_target_commits_array()
|
2019-11-24 01:05:25 +01:00
|
|
|
elif target == 'all_addons':
|
|
|
|
update_addons()
|
|
|
|
update_addons_third_party_addons()
|
2019-11-25 12:11:41 +01:00
|
|
|
save_target_commits_array()
|
2019-11-24 01:05:25 +01:00
|
|
|
elif target == 'addons':
|
|
|
|
update_addons()
|
2019-11-25 12:11:41 +01:00
|
|
|
save_target_commits_array()
|
2019-11-24 01:05:25 +01:00
|
|
|
elif target == 'third_party_addons':
|
|
|
|
update_addons_third_party_addons()
|
2019-11-25 12:11:41 +01:00
|
|
|
save_target_commits_array()
|
|
|
|
|