PackageScript
author dvander@linux32.localdomain
Sat Apr 16 00:41:25 2011 -0700 (2011-04-16)
changeset 59 41feee1fac07
child 60 3494bfad2033
permissions -rw-r--r--
Support for AMBuild.
     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 = [['addons', 'metamod'],
    71 				   ['addons', 'stripper'],
    72 					 ['addons', 'stripper', 'bin'],
    73 					 ['addons', 'stripper', 'dumps'],
    74 					 ['addons', 'stripper', 'maps']]
    75 
    76 #Setup
    77 job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
    78 job.AddCommand(CreateFolders(folders))
    79 
    80 #Copiy Files
    81 job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'de_dust.cfg'),
    82                         os.path.join('addons', 'stripper', 'maps')))
    83 job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'global_filters.cfg'),
    84                         os.path.join('addons', 'stripper')))
    85 job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'stripper.vdf'),
    86                         os.path.join('addons', 'metamod')))
    87 
    88 bincopies = []
    89 
    90 def AddNormalLibrary(name, dest):
    91 	dest = os.path.join('addons', 'stripper', dest)
    92 	bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
    93 	pdb_list.append(name + '\\' + name + '.pdb')
    94 
    95 def AddHL2Library(name, dest):
    96 	for i in Stripper.sdkInfo:
    97 		sdk = Stripper.sdkInfo[i]
    98 		if AMBuild.target['platform'] not in sdk['platform']:
    99 			continue
   100 		AddNormalLibrary(name + '.' + sdk['ext'], dest)
   101 
   102 pdb_list = []
   103 
   104 # Copy loader binaries
   105 if AMBuild.target['platform'] == 'linux':
   106 	AddNormalLibrary('stripper_mm_i486', 'bin')
   107 else:
   108 	AddNormalLibrary('stripper_mm', 'bin')
   109 AddNormalLibrary('stripper.core', 'bin')
   110 AddHL2Library('stripper', 'bin')
   111 
   112 job.AddCommandGroup(bincopies)
   113 
   114 if AMBuild.target['platform'] == 'windows':
   115 	pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
   116 	for pdb in pdb_list:
   117 		pdblog.write(pdb + '\n')
   118 	pdblog.close()
   119 
   120