Update code to use SourceHooks function.
1 # vim: set ts=2 sw=2 tw=99 noet ft=python:
4 import ambuild.osutil as osutil
5 from ambuild.command import Command
7 job = AMBuild.AddJob('package')
9 class DestroyPath(Command):
10 def __init__(self, folder):
11 Command.__init__(self)
14 def destroy(self, path):
15 entries = os.listdir(path)
17 newpath = os.path.join(path, entry)
18 if os.path.isdir(newpath):
21 elif os.path.isfile(newpath):
24 def run(self, runner, job):
25 runner.PrintOut('rm -rf {0}/*'.format(self.folder))
26 self.destroy(self.folder)
28 class CreateFolders(Command):
29 def __init__(self, folders):
30 Command.__init__(self)
31 self.folders = folders
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))
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
47 def run(self, runner, job):
48 entries = os.listdir(self.fromPath)
50 if entry in self.excludes:
52 path = os.path.join(self.fromPath, entry)
53 if not os.path.isfile(path):
55 runner.PrintOut('copy {0} to {1}'.format(path, self.toPath))
56 shutil.copy(path, self.toPath)
59 class CopyFile(Command):
60 def __init__(self, fromFile, toPath):
61 Command.__init__(self)
62 self.fromFile = fromFile
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)
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']]
86 job.AddCommand(DestroyPath(os.path.join(AMBuild.outputFolder, 'package')))
87 job.AddCommand(CreateFolders(folders))
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')))
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')
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']:
116 AddNormalLibrary(name + '.' + sdk['ext'], dest)
120 # Copy loader binaries
121 AddNormalLibrary('cssdm.ext.2.css', 'extensions')
122 if AMBuild.target['platform'] != 'darwin':
123 AddNormalLibrary('cssdm.ext.2.csgo', 'extensions')
125 job.AddCommandGroup(bincopies)
127 if AMBuild.target['platform'] == 'windows':
128 pdblog = open(os.path.join(AMBuild.outputFolder, 'pdblog.txt'), 'wt')
130 pdblog.write(pdb + '\n')
139 'dm_spawn_protection'
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)