-
-
Notifications
You must be signed in to change notification settings - Fork 203
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
builds
committed
Jan 22, 2023
1 parent
0f9ec96
commit 27f451a
Showing
2 changed files
with
153 additions
and
160 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,153 @@ | ||
#!/usr/bin/env python3 | ||
# vim: set ts=4 sw=4 tw=99 et: | ||
import argparse | ||
import datetime | ||
import ftplib | ||
import os | ||
import platform | ||
import re | ||
import shutil | ||
import subprocess | ||
import time | ||
|
||
kPackages = ['base', 'cstrike', 'dod', 'esf', 'ns', 'tfc', 'ts'] | ||
kMacExclude = set(['esf', 'ns', 'ts']) | ||
|
||
class PackageBuilder(object): | ||
def __init__(self, args): | ||
self.args_ = args | ||
|
||
if platform.system() == 'Linux': | ||
self.os_ = 'linux' | ||
elif platform.system() == 'Windows': | ||
self.os_ = 'windows' | ||
elif platform.system() == 'Darwin': | ||
self.os_ = 'mac' | ||
else: | ||
raise Exception('Unknown platform: {}'.format(platform.system())) | ||
|
||
if self.os_ == 'linux': | ||
self.archive_type_ = 'tar.gz' | ||
else: | ||
self.archive_type_ = 'zip' | ||
self.packages_ = [] | ||
|
||
def run(self): | ||
self.read_ftp_info() | ||
self.read_product_version() | ||
|
||
# Switch to the output folder. | ||
with Chdir(os.path.join('..', 'OUTPUT')): | ||
self.build() | ||
self.upload() | ||
|
||
def build(self): | ||
print("Creating package for {}".format(self.version_)) | ||
|
||
for package in kPackages: | ||
if self.os_ == 'mac' and package in kMacExclude: | ||
continue | ||
|
||
package_dir = os.path.join('packages', package) | ||
with Chdir(package_dir): | ||
package_name, alt_name = self.build_package(package) | ||
|
||
if os.path.exists(package_name): | ||
os.unlink(package_name) | ||
|
||
src_path = os.path.join(package_dir, package_name) | ||
shutil.move(src_path, package_name) | ||
|
||
self.packages_.append((package_name, alt_name)) | ||
|
||
def upload(self): | ||
|
||
m = re.search("^(\d+)\.(\d+)", self.version_) | ||
ftp_path = '{}/{}.{}'.format(self.ftp_path_, m.group(1), m.group(2)) | ||
|
||
print("Connecting to drop site: {}".format(ftp_path)) | ||
ftp = ftplib.FTP(self.ftp_host_) | ||
ftp.login(self.ftp_user_, self.ftp_pass_) | ||
ftp.set_pasv(True) | ||
ftp.cwd(ftp_path) | ||
|
||
for package_file, alt_file in self.packages_: | ||
self.upload_package(ftp, package_file, package_file) | ||
self.upload_package(ftp, package_file, alt_file) | ||
|
||
print("Files sent to drop site -- build succeeded.") | ||
|
||
def upload_package(self, ftp, package_file, dest_name): | ||
with open(package_file, 'rb') as fp: | ||
print("Sending {} as {}".format(package_file, dest_name)) | ||
ftp.storbinary('STOR {}'.format(dest_name), fp) | ||
|
||
def build_package(self, package): | ||
package_file = 'amxmodx-{}-{}-{}.{}'.format(self.version_, package, self.os_, | ||
self.archive_type_) | ||
if os.path.exists(package_file): | ||
os.unlink(package_file) | ||
|
||
if self.archive_type_ == 'tar.gz': | ||
Run(['tar', 'zcvf', package_file, 'addons']) | ||
else: | ||
Run(['zip', '-r', package_file, 'addons']) | ||
|
||
alt_name = 'amxmodx-latest-{}-{}.{}'.format(package, self.os_, self.archive_type_) | ||
return package_file, alt_name | ||
|
||
def read_ftp_info(self): | ||
with open(self.args_.ftp_file, 'rt') as fp: | ||
lines = [line.strip() for line in fp.read().splitlines()] | ||
self.ftp_host_ = lines[0] | ||
self.ftp_user_ = lines[1] | ||
self.ftp_pass_ = lines[2] | ||
self.ftp_path_ = lines[3] | ||
|
||
def read_product_version(self): | ||
with open('product.version', 'rt') as fp: | ||
self.version_ = fp.read().strip() | ||
|
||
output = subprocess.check_output(['git', 'rev-list', '--count', 'HEAD'], | ||
universal_newlines = True, | ||
stderr = subprocess.STDOUT) | ||
output = output.strip() | ||
if output: | ||
self.version_ += '-git' + output | ||
|
||
def main(): | ||
parser = argparse.ArgumentParser() | ||
parser.add_argument('ftp_file', type = str, help = 'FTP config file') | ||
|
||
args = parser.parse_args() | ||
|
||
builder = PackageBuilder(args) | ||
builder.run() | ||
|
||
class Chdir(object): | ||
def __init__(self, target): | ||
self.prevdir_ = None | ||
self.target_ = target | ||
|
||
def __enter__(self): | ||
prevdir = os.getcwd() | ||
os.chdir(self.target_) | ||
self.prevdir_ = prevdir | ||
return self | ||
|
||
def __exit__(self, exc_type, exc_value, traceback): | ||
if self.prevdir_: | ||
os.chdir(self.prevdir_) | ||
return False | ||
|
||
def Run(argv): | ||
try: | ||
output = subprocess.check_output(argv, stderr = subprocess.STDOUT, | ||
universal_newlines = True) | ||
print(output) | ||
except subprocess.CalledProcessError as e: | ||
print(e.output.decode('utf-8')) | ||
raise | ||
|
||
if __name__ == '__main__': | ||
main() |
27f451a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Build failed: modules/sqlite/sqlite_amxx_i386/_third_party_sqlite_sqlite3.o
Error: Process completed with exit code 1.
Merge SQLite files from my branch so you can build both OSX and Linux.
27f451a
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi, it's been a while since then,
I suggest you create a new pull request with the sqlite specific changes to merge. if not, it will be forgotten. I recently ran into the same detail and had to skip it in order to compile.I invoke @dvander seems to be the most active member of the project, maybe he can continue with the update.