| 1 |
#! /usr/bin/env python3 |
| 2 |
|
| 3 |
## ____ _ __ |
| 4 |
## / __ )____ _____ | | / /___ ___________ |
| 5 |
## / __ / __ \/ ___/ | | /| / / __ `/ ___/ ___/ |
| 6 |
## / /_/ / /_/ (__ ) | |/ |/ / /_/ / / (__ ) |
| 7 |
## /_____/\____/____/ |__/|__/\__,_/_/ /____/ |
| 8 |
## |
| 9 |
## A futuristic real-time strategy game. |
| 10 |
## This file is part of Bos Wars. |
| 11 |
## |
| 12 |
## Script that generates all the distribution packages. |
| 13 |
## (c) Copyright 2007-2023 by Francois Beerten |
| 14 |
## |
| 15 |
## Stratagus is free software; you can redistribute it and/or modify |
| 16 |
## it under the terms of the GNU General Public License as published |
| 17 |
## by the Free Software Foundation; only version 2 of the License. |
| 18 |
## |
| 19 |
## Stratagus is distributed in the hope that it will be useful, |
| 20 |
## but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
## GNU General Public License for more details. |
| 23 |
|
| 24 |
import sys |
| 25 |
import os |
| 26 |
import tarfile |
| 27 |
import zipfile |
| 28 |
import time |
| 29 |
|
| 30 |
def printDot(): |
| 31 |
sys.stdout.write('.') |
| 32 |
sys.stdout.flush() |
| 33 |
|
| 34 |
def createTarArchive(archivename, namelist): |
| 35 |
print("\nCreating %s.tar.gz" % archivename) |
| 36 |
tar = tarfile.open(archivename + ".tar.gz", "w:gz") |
| 37 |
for name in namelist: |
| 38 |
tarinfo = tar.gettarinfo(name, archivename + "/" + name) |
| 39 |
tarinfo.uid = 500 |
| 40 |
tarinfo.gid = 500 |
| 41 |
tarinfo.uname = "user" |
| 42 |
tarinfo.gname = "user" |
| 43 |
printDot() |
| 44 |
tar.addfile(tarinfo, open(name, 'rb')) |
| 45 |
tar.close() |
| 46 |
print |
| 47 |
|
| 48 |
def createZipArchive(archivename, namelist): |
| 49 |
print("\nCreating %s.zip" % archivename) |
| 50 |
z = zipfile.ZipFile(archivename + ".zip", "w", zipfile.ZIP_DEFLATED) |
| 51 |
for name in namelist: |
| 52 |
z.write(name, archivename + "/" + name) |
| 53 |
printDot() |
| 54 |
z.close() |
| 55 |
print |
| 56 |
|
| 57 |
def listGitFiles(): |
| 58 |
entries = os.popen('git ls-files').readlines() |
| 59 |
return [i.strip() for i in entries] |
| 60 |
|
| 61 |
def listSvnFiles(): |
| 62 |
entries = os.popen('svn ls -R').readlines() |
| 63 |
files = [] |
| 64 |
for e in entries: |
| 65 |
e = e.strip() |
| 66 |
if not e.endswith('/'): |
| 67 |
files.append(e) |
| 68 |
return files |
| 69 |
|
| 70 |
def listFilesInDirectories(): |
| 71 |
raise RuntimeError("Not implemented") |
| 72 |
|
| 73 |
def listFiles(): |
| 74 |
if os.access('.git', os.F_OK): |
| 75 |
return listGitFiles() |
| 76 |
elif os.access('.svn', os.F_OK): |
| 77 |
return listSvnFiles() |
| 78 |
else: |
| 79 |
return listFilesInDirectories() |
| 80 |
|
| 81 |
def buildDefaultVersionName(): |
| 82 |
t = time.time() |
| 83 |
v = time.strftime('%Y%m%d', time.gmtime(t)) |
| 84 |
return v |
| 85 |
|
| 86 |
def buildVersionName(): |
| 87 |
if len(sys.argv) > 1: |
| 88 |
return sys.argv[1] |
| 89 |
else: |
| 90 |
return buildDefaultVersionName() |
| 91 |
|
| 92 |
def filterDirectories(files): |
| 93 |
return [x for x in files if not x.endswith('/')] |
| 94 |
|
| 95 |
def filterSources(files): |
| 96 |
buildfiles = ['bos.sln', 'make.py', 'fabricate.py'] |
| 97 |
def isGoodFile(f): |
| 98 |
return (not f.startswith('engine/') and not f.startswith('tools/') and |
| 99 |
f not in buildfiles) |
| 100 |
return [x for x in files if isGoodFile(x)] |
| 101 |
|
| 102 |
|
| 103 |
|
| 104 |
def buildPackages(): |
| 105 |
name = 'boswars-' + buildVersionName() + '-%s' |
| 106 |
|
| 107 |
os.chdir('../..') |
| 108 |
files = listFiles() |
| 109 |
files = filterDirectories(files) |
| 110 |
|
| 111 |
# create source packages |
| 112 |
createTarArchive(name % 'src', files) |
| 113 |
createZipArchive(name % 'src', files) |
| 114 |
|
| 115 |
# create binary packages |
| 116 |
# FIXME: automatically build a "static" boswars executable ? |
| 117 |
binarydistfiles = filterSources(files) |
| 118 |
linuxfiles = binarydistfiles[:] |
| 119 |
linuxfiles.append('boswars') |
| 120 |
createTarArchive(name % 'linux', linuxfiles) |
| 121 |
if os.access('boswars.exe', os.F_OK): |
| 122 |
winfiles = binarydistfiles[:] |
| 123 |
winfiles.append('boswars.exe') |
| 124 |
createZipArchive(name % 'win32', winfiles) |
| 125 |
|
| 126 |
|
| 127 |
if __name__ == '__main__': |
| 128 |
buildPackages() |
| 129 |
|
| 130 |
|
| 131 |
|
| 132 |
|
| 133 |
|