1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/PackageScript Sat Apr 16 00:41:25 2011 -0700
1.3 @@ -0,0 +1,120 @@
1.4 +# vim: set ts=2 sw=2 tw=99 noet ft=python:
1.5 +import os
1.6 +import shutil
1.7 +import ambuild.osutil as osutil
1.8 +from ambuild.command import Command
1.9 +
1.10 +job = AMBuild.AddJob('package')
1.11 +
1.12 +class DestroyPath(Command):
1.13 + def __init__(self, folder):
1.14 + Command.__init__(self)
1.15 + self.folder = folder
1.16 +
1.17 + def destroy(self, path):
1.18 + entries = os.listdir(path)
1.19 + for entry in entries:
1.20 + newpath = os.path.join(path, entry)
1.21 + if os.path.isdir(newpath):
1.22 + self.destroy(newpath)
1.23 + os.rmdir(newpath)
1.24 + elif os.path.isfile(newpath):
1.25 + os.remove(newpath)
1.26 +
1.27 + def run(self, runner, job):
1.28 + runner.PrintOut('rm -rf {0}/*'.format(self.folder))
1.29 + self.destroy(self.folder)
1.30 +
1.31 +class CreateFolders(Command):
1.32 + def __init__(self, folders):
1.33 + Command.__init__(self)
1.34 + self.folders = folders
1.35 +
1.36 + def run(self, runner, job):
1.37 + for folder in self.folders:
1.38 + path = os.path.join(*folder)
1.39 + runner.PrintOut('mkdir {0}'.format(path))
1.40 + os.makedirs(path)
1.41 +
1.42 +#Shallow folder copy
1.43 +class CopyFolder(Command):
1.44 + def __init__(self, fromList, toList, excludes = []):
1.45 + Command.__init__(self)
1.46 + self.fromPath = os.path.join(AMBuild.sourceFolder, *fromList)
1.47 + self.toPath = os.path.join(*toList)
1.48 + self.excludes = excludes
1.49 +
1.50 + def run(self, runner, job):
1.51 + entries = os.listdir(self.fromPath)
1.52 + for entry in entries:
1.53 + if entry in self.excludes:
1.54 + continue
1.55 + path = os.path.join(self.fromPath, entry)
1.56 + if not os.path.isfile(path):
1.57 + continue
1.58 + runner.PrintOut('copy {0} to {1}'.format(path, self.toPath))
1.59 + shutil.copy(path, self.toPath)
1.60 +
1.61 +#Single file copy
1.62 +class CopyFile(Command):
1.63 + def __init__(self, fromFile, toPath):
1.64 + Command.__init__(self)
1.65 + self.fromFile = fromFile
1.66 + self.toPath = toPath
1.67 +
1.68 + def run(self, runner, job):
1.69 + runner.PrintOut('copy {0} to {1}'.format(self.fromFile, self.toPath))
1.70 + shutil.copy(self.fromFile, self.toPath)
1.71 +
1.72 +
1.73 +folders = [['addons', 'metamod'],
1.74 + ['addons', 'stripper'],
1.75 + ['addons', 'stripper', 'bin'],
1.76 + ['addons', 'stripper', 'dumps'],
1.77 + ['addons', 'stripper', 'maps']]
1.78 +
1.79 +#Setup
1.80 +job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
1.81 +job.AddCommand(CreateFolders(folders))
1.82 +
1.83 +#Copiy Files
1.84 +job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'de_dust.cfg'),
1.85 + os.path.join('addons', 'stripper', 'maps')))
1.86 +job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'global_filters.cfg'),
1.87 + os.path.join('addons', 'stripper')))
1.88 +job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'stripper.vdf'),
1.89 + os.path.join('addons', 'metamod')))
1.90 +
1.91 +bincopies = []
1.92 +
1.93 +def AddNormalLibrary(name, dest):
1.94 + dest = os.path.join('addons', 'stripper', dest)
1.95 + bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
1.96 + pdb_list.append(name + '\\' + name + '.pdb')
1.97 +
1.98 +def AddHL2Library(name, dest):
1.99 + for i in Stripper.sdkInfo:
1.100 + sdk = Stripper.sdkInfo[i]
1.101 + if AMBuild.target['platform'] not in sdk['platform']:
1.102 + continue
1.103 + AddNormalLibrary(name + '.' + sdk['ext'], dest)
1.104 +
1.105 +pdb_list = []
1.106 +
1.107 +# Copy loader binaries
1.108 +if AMBuild.target['platform'] == 'linux':
1.109 + AddNormalLibrary('stripper_mm_i486', 'bin')
1.110 +else:
1.111 + AddNormalLibrary('stripper_mm', 'bin')
1.112 +AddNormalLibrary('stripper.core', 'bin')
1.113 +AddHL2Library('stripper', 'bin')
1.114 +
1.115 +job.AddCommandGroup(bincopies)
1.116 +
1.117 +if AMBuild.target['platform'] == 'windows':
1.118 + pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
1.119 + for pdb in pdb_list:
1.120 + pdblog.write(pdb + '\n')
1.121 + pdblog.close()
1.122 +
1.123 +