Menu

[ee7d4c]: / build / release.py  Maximize  Restore  History

Download this file

111 lines (97 with data), 4.1 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
#!/usr/bin/env python
'''
owlcpp/build/release.py is part of owlcpp project
Distributed under the Boost Software License, Version 1.0; see doc/license.txt.
Copyright Mikhail K Levin 2013
'''
import os, subprocess, sys, shutil, re, zipfile, tarfile
def convert_crlf(src_file, dst, target_os):
s = open(src_file, 'rb').read()
if '\0' not in s:
if target_os == 'unix':
s = s.replace('\r\n', '\n')
s = s.replace('\r', '\n')
if target_os == 'dos':
s = s.replace('\r\n', '\n')
s = s.replace('\r', '\n')
s = s.replace('\n', '\r\n')
else: print src_file + ' binary'
if os.path.isdir(dst): dst = os.path.join(dst, os.path.basename(src_file))
open(dst, 'wb').write(s)
def convert_tree_crlf(src, dst, target_os):
if os.path.isfile(src):
convert_crlf(src, dst, target_os)
return
for dir, sub, files in os.walk(src):
reldir = os.path.relpath(dir, src)
dstdir = os.path.join(dst, reldir)
os.makedirs(dstdir)
for file in files:
if file[0] == '.': continue
if re.search(r'\.pyc$', file): continue
src_file = os.path.join(dir, file)
dst_file = os.path.join(dstdir, file)
convert_crlf(src_file, dst_file, target_os)
def get_version():
# use '~' dirty marker, not '*', to be able to use version string as directory name
v_str = subprocess.check_output(
args=['git', 'describe', '--always', '--dirty=~'] # use ~, not *
)
t = re.match(
'v(\d+)\.(\d+).(\d+)((?:-\d+-g[\dabcdef]+)?\~?)\s*',
v_str
).groups()
return t
def src_compress(out_path, rel_name, target_os):
rel_path = os.path.join(out_path, rel_name)
if target_os == 'dos':
z = zipfile.ZipFile(rel_path + '.zip', 'w', zipfile.ZIP_DEFLATED)
for dir, sub, files in os.walk(rel_path):
reldir = os.path.relpath(dir, out_path)
for file in files:
z.write(os.path.join(dir, file), os.path.join(reldir, file))
z.close()
elif target_os == 'unix':
b = tarfile.open(rel_path + '.tar.bz2', 'w|bz2')
for dir, sub, files in os.walk(rel_path):
reldir = os.path.relpath(dir, out_path)
for file in files:
b.add(os.path.join(dir, file), os.path.join(reldir, file))
b.close()
def src_release(root_path, out_path, name, rel_version, target_os):
rel_name = name + '-' + rel_version
print 'making ' + target_os + ' version'
rel_path = os.path.join(out_path, rel_name)
if os.path.exists(rel_path): shutil.rmtree(rel_path)
os.makedirs(rel_path)
obj_list = [
'apps', 'binding', 'include', 'lib', 'build',
'doc', 'external', 'sample_data',
'readme.txt', 'jamroot.jam'
]
for obj in obj_list:
src = os.path.join(root_path, obj)
dst = os.path.join(rel_path, obj)
convert_tree_crlf(src, dst, target_os)
s = open(os.path.join(rel_path, obj_list[-1]), 'r').read()
patt = re.compile(r'(constant\s+OWLCPP_VERSION\s+:\s+)(\[[^[]+\])')
repl = r'\1"' + rel_version + '"'
t = re.subn(patt, repl, s)
open(os.path.join(rel_path, obj_list[-1]), 'w').write(t[0])
s = open(os.path.join(rel_path, obj_list[-2]), 'r').read()
s = name + ' version ' + rel_version + s
open(os.path.join(rel_path, obj_list[-2]), 'w').write(s)
src_compress(out_path, rel_name, target_os)
if __name__ == '__main__':
root_path = sys.argv[1]
out_path = os.path.join(root_path, 'out', 'release')
if os.path.exists(out_path): shutil.rmtree(out_path)
rel_version = ''
if len(sys.argv) > 2: rel_version = sys.argv[2]
else:
v = get_version()
rel_version = 'v%s.%s.%s%s' % v
rel_name = 'owlcpp'
print 'release ' + rel_name + ' ' + rel_version
src_release(root_path, out_path, rel_name, rel_version, 'dos')
src_release(root_path, out_path, rel_name, rel_version, 'unix')
Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.