PackageScript
author Ruben Gonzalez <drifter01620@gmail.com>
Wed Oct 01 11:50:24 2014 -0400 (2014-10-01)
changeset 193 277c856152b0
parent 102 3350a5f84424
permissions -rw-r--r--
Update linix CS:GO gamedata
[email protected]
     1
# vim: set ts=2 sw=2 tw=99 noet ft=python: 
[email protected]
     2
import os
[email protected]
     3
import shutil
[email protected]
     4
import ambuild.osutil as osutil
[email protected]
     5
from ambuild.command import Command
[email protected]
     6
[email protected]
     7
job = AMBuild.AddJob('package')
[email protected]
     8
[email protected]
     9
class DestroyPath(Command):
[email protected]
    10
	def __init__(self, folder):
[email protected]
    11
		Command.__init__(self)
[email protected]
    12
		self.folder = folder
[email protected]
    13
[email protected]
    14
	def destroy(self, path):
[email protected]
    15
		entries = os.listdir(path)
[email protected]
    16
		for entry in entries:
[email protected]
    17
			newpath = os.path.join(path, entry)
[email protected]
    18
			if os.path.isdir(newpath):
[email protected]
    19
				self.destroy(newpath)
[email protected]
    20
				os.rmdir(newpath)
[email protected]
    21
			elif os.path.isfile(newpath):
[email protected]
    22
				os.remove(newpath)
[email protected]
    23
[email protected]
    24
	def run(self, runner, job):
[email protected]
    25
		runner.PrintOut('rm -rf {0}/*'.format(self.folder))
[email protected]
    26
		self.destroy(self.folder)
[email protected]
    27
[email protected]
    28
class CreateFolders(Command):
[email protected]
    29
	def __init__(self, folders):
[email protected]
    30
		Command.__init__(self)
[email protected]
    31
		self.folders = folders
[email protected]
    32
	
[email protected]
    33
	def run(self, runner, job):
[email protected]
    34
		for folder in self.folders:
[email protected]
    35
			path = os.path.join(*folder)
[email protected]
    36
			runner.PrintOut('mkdir {0}'.format(path))
[email protected]
    37
			os.makedirs(path)
[email protected]
    38
[email protected]
    39
#Shallow folder copy
[email protected]
    40
class CopyFolder(Command):
[email protected]
    41
	def __init__(self, fromList, toList, excludes = []):
[email protected]
    42
		Command.__init__(self)
[email protected]
    43
		self.fromPath = os.path.join(AMBuild.sourceFolder, *fromList)
[email protected]
    44
		self.toPath = os.path.join(*toList) 
[email protected]
    45
		self.excludes = excludes
[email protected]
    46
	
[email protected]
    47
	def run(self, runner, job):
[email protected]
    48
		entries = os.listdir(self.fromPath)
[email protected]
    49
		for entry in entries:
[email protected]
    50
			if entry in self.excludes:
[email protected]
    51
				continue
[email protected]
    52
			path = os.path.join(self.fromPath, entry)
[email protected]
    53
			if not os.path.isfile(path):
[email protected]
    54
				continue
[email protected]
    55
			runner.PrintOut('copy {0} to {1}'.format(path, self.toPath))
[email protected]
    56
			shutil.copy(path, self.toPath)
[email protected]
    57
[email protected]
    58
#Single file copy
[email protected]
    59
class CopyFile(Command):
[email protected]
    60
	def __init__(self, fromFile, toPath):
[email protected]
    61
		Command.__init__(self)
[email protected]
    62
		self.fromFile = fromFile
[email protected]
    63
		self.toPath = toPath
[email protected]
    64
[email protected]
    65
	def run(self, runner, job):
[email protected]
    66
		runner.PrintOut('copy {0} to {1}'.format(self.fromFile, self.toPath))
[email protected]
    67
		shutil.copy(self.fromFile, self.toPath)
[email protected]
    68
[email protected]
    69
[email protected]
    70
folders = [['cfg'],
[email protected]
    71
					 ['cfg', 'cssdm'],
[email protected]
    72
					 ['cfg', 'cssdm', 'extra'],
[email protected]
    73
					 ['cfg', 'cssdm', 'maps'],
[email protected]
    74
					 ['cfg', 'cssdm', 'spawns', 'cstrike'],
[email protected]
    75
					 ['cfg', 'cssdm', 'spawns', 'csgo'],
[email protected]
    76
				   ['addons', 'sourcemod'],
[email protected]
    77
					 ['addons', 'sourcemod', 'extensions'],
[email protected]
    78
					 ['addons', 'sourcemod', 'gamedata'],
[email protected]
    79
					 ['addons', 'sourcemod', 'plugins'],
[email protected]
    80
					 ['addons', 'sourcemod', 'plugins', 'cssdm'],
[email protected]
    81
					 ['addons', 'sourcemod', 'scripting'],
[email protected]
    82
					 ['addons', 'sourcemod', 'scripting', 'include'],
[email protected]
    83
					 ['addons', 'sourcemod', 'translations']]
[email protected]
    84
[email protected]
    85
#Setup
[email protected]
    86
job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
[email protected]
    87
job.AddCommand(CreateFolders(folders))
[email protected]
    88
[email protected]
    89
#Copy Files
[email protected]
    90
job.AddCommand(CopyFolder(['gamedata'], ['addons', 'sourcemod', 'gamedata']))
[email protected]
    91
job.AddCommand(CopyFolder(['scripting'], ['addons', 'sourcemod', 'scripting']))
[email protected]
    92
job.AddCommand(CopyFolder(['scripting', 'include'], ['addons', 'sourcemod', 'scripting', 'include']))
[email protected]
    93
job.AddCommand(CopyFolder(['translations'], ['addons', 'sourcemod', 'translations']))
[email protected]
    94
job.AddCommand(CopyFolder(['cfg'], ['cfg', 'cssdm']))
[email protected]
    95
job.AddCommand(CopyFolder(['cfg', 'spawns', 'cstrike'], ['cfg', 'cssdm', 'spawns', 'cstrike']))
[email protected]
    96
job.AddCommand(CopyFolder(['cfg', 'spawns', 'csgo'], ['cfg', 'cssdm', 'spawns', 'csgo']))
[email protected]
    97
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'license.txt'),
[email protected]
    98
												os.path.join('cfg', 'cssdm', 'extra')))
[email protected]
    99
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'changelog.txt'),
[email protected]
   100
												os.path.join('cfg', 'cssdm', 'extra')))
[email protected]
   101
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'credits.txt'),
[email protected]
   102
												os.path.join('cfg', 'cssdm', 'extra')))
[email protected]
   103
[email protected]
   104
bincopies = []
[email protected]
   105
[email protected]
   106
def AddNormalLibrary(name, dest):
[email protected]
   107
	dest = os.path.join('addons', 'sourcemod', dest)
[email protected]
   108
	bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
[email protected]
   109
	pdb_list.append(name + '\\' + name + '.pdb')
[email protected]
   110
[email protected]
   111
def AddHL2Library(name, dest):
[email protected]
   112
	for i in CSSDM.sdkInfo:
[email protected]
   113
		sdk = CSSDM.sdkInfo[i]
[email protected]
   114
		if AMBuild.target['platform'] not in sdk['platform']:
[email protected]
   115
			continue
[email protected]
   116
		AddNormalLibrary(name + '.' + sdk['ext'], dest)
[email protected]
   117
[email protected]
   118
pdb_list = []
[email protected]
   119
[email protected]
   120
# Copy loader binaries
[email protected]
   121
AddNormalLibrary('cssdm.ext.2.css', 'extensions')
[email protected]
   122
if AMBuild.target['platform'] != 'darwin':
[email protected]
   123
	AddNormalLibrary('cssdm.ext.2.csgo', 'extensions')
[email protected]
   124
[email protected]
   125
job.AddCommandGroup(bincopies)
[email protected]
   126
[email protected]
   127
if AMBuild.target['platform'] == 'windows':
[email protected]
   128
	pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
[email protected]
   129
	for pdb in pdb_list:
[email protected]
   130
		pdblog.write(pdb + '\n')
[email protected]
   131
	pdblog.close()
[email protected]
   132
[email protected]
   133
# Copy plugins
[email protected]
   134
plugins = [
[email protected]
   135
		'dm_basics',
[email protected]
   136
		'dm_bot_quotas',
[email protected]
   137
		'dm_equipment',
[email protected]
   138
		'dm_preset_spawns',
[email protected]
   139
		'dm_spawn_protection'
[email protected]
   140
]
[email protected]
   141
[email protected]
   142
commands = []
[email protected]
   143
for plugin in plugins:
[email protected]
   144
	commands.append(CopyFile(os.path.join('..', 'plugins', plugin + '.smx'),
[email protected]
   145
													 os.path.join('addons', 'sourcemod', 'plugins', 'cssdm')))
[email protected]
   146
job.AddCommandGroup(commands)
[email protected]
   147