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