PackageScript
author Dr!fter <drifter01620@gmail.com>
Sat Aug 16 22:29:47 2014 -0400 (2014-08-16)
changeset 79 c782ba2e5b1b
parent 32 4abb69efd473
permissions -rw-r--r--
Set temporary enviroment variables.
[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 = [['addons', 'metamod'],
[email protected]
    71
				   ['addons', 'stripper'],
[email protected]
    72
					 ['addons', 'stripper', 'bin'],
[email protected]
    73
					 ['addons', 'stripper', 'dumps'],
[email protected]
    74
					 ['addons', 'stripper', 'maps']]
[email protected]
    75
[email protected]
    76
#Setup
[email protected]
    77
job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
[email protected]
    78
job.AddCommand(CreateFolders(folders))
[email protected]
    79
[email protected]
    80
#Copiy Files
[email protected]
    81
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'de_dust.cfg'),
[email protected]
    82
                        os.path.join('addons', 'stripper', 'maps')))
[email protected]
    83
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'global_filters.cfg'),
[email protected]
    84
                        os.path.join('addons', 'stripper')))
[email protected]
    85
job.AddCommand(CopyFile(os.path.join(AMBuild.sourceFolder, 'stripper.vdf'),
[email protected]
    86
                        os.path.join('addons', 'metamod')))
[email protected]
    87
[email protected]
    88
bincopies = []
[email protected]
    89
[email protected]
    90
def AddNormalLibrary(name, dest):
[email protected]
    91
	dest = os.path.join('addons', 'stripper', dest)
[email protected]
    92
	bincopies.append(CopyFile(os.path.join('..', name, name + osutil.SharedLibSuffix()), dest))
[email protected]
    93
	pdb_list.append(name + '\\' + name + '.pdb')
[email protected]
    94
[email protected]
    95
def AddHL2Library(name, dest):
[email protected]
    96
	for i in Stripper.sdkInfo:
[email protected]
    97
		sdk = Stripper.sdkInfo[i]
[email protected]
    98
		if AMBuild.target['platform'] not in sdk['platform']:
[email protected]
    99
			continue
[email protected]
   100
		AddNormalLibrary(name + '.' + sdk['ext'], dest)
[email protected]
   101
[email protected]
   102
pdb_list = []
[email protected]
   103
[email protected]
   104
# Copy loader binaries
[email protected]
   105
if AMBuild.target['platform'] == 'linux':
[email protected]
   106
	AddNormalLibrary('stripper_mm_i486', 'bin')
[email protected]
   107
else:
[email protected]32
   108
	AddNormalLibrary('stripper_mm', 'bin')
[email protected]
   109
AddNormalLibrary('stripper.core', 'bin')
[email protected]
   110
AddHL2Library('stripper', 'bin')
[email protected]
   111
[email protected]
   112
job.AddCommandGroup(bincopies)
[email protected]
   113
[email protected]
   114
if AMBuild.target['platform'] == 'windows':
[email protected]
   115
	pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
[email protected]
   116
	for pdb in pdb_list:
[email protected]
   117
		pdblog.write(pdb + '\n')
[email protected]
   118
	pdblog.close()
[email protected]
   119
[email protected]
   120