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 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247
|
from fabric.api import *
import tarfile
import os
import zipfile
import fabfile_settings
env.hosts = []
if hasattr(fabfile_settings, 'osx_host'):
osx_host = fabfile_settings.osx_host
env.hosts.append(osx_host)
if '@' in osx_host:
osx_host = osx_host.split('@')[1]
if ':' in osx_host:
osx_host = osx_host.split(':')[0]
else:
osx_host = ''
if hasattr(fabfile_settings, 'linux_host'):
linux_host = fabfile_settings.linux_host
env.hosts.append(linux_host)
if '@' in linux_host:
linux_host = linux_host.split('@')[1]
if ':' in linux_host:
linux_host = linux_host.split(':')[0]
else:
linux_host = ''
if hasattr(fabfile_settings, 'run_tests'):
run_tests = fabfile_settings.run_tests
else:
run_tests=False
import sys, os
sys.path.append("site_scons")
from defaults import productVersion
pv = productVersion.replace(' ', '_')
class TarWrapper():
def __init__(self, name, prefix=None):
self.prefix = prefix
self.tar = tarfile.open(name, 'w:gz')
def add(self, name, arcname=None):
if self.prefix is not None:
if arcname is not None:
arcname = os.path.join(self.prefix, arcname)
else:
arcname = os.path.join(self.prefix, name)
self.tar.add(name, arcname)
print(('Packing file: ' + name if arcname is None else arcname))
def close(self):
self.tar.close()
def pack():
tar = start_src_tar()
if env.host == linux_host:
tar.add('apbs_libs/linux/apbslib.py','pdb2pka/apbslib.py')
tar.add('apbs_libs/linux/_apbslib.so','pdb2pka/_apbslib.so')
elif env.host == osx_host:
tar.add('apbs_libs/osx/apbslib.py','pdb2pka/apbslib.py')
tar.add('apbs_libs/osx/_apbslib.so','pdb2pka/_apbslib.so')
tar.close()
@runs_once
def pack_for_nbcr():
create_dist_folder()
tar = start_src_tar('pdb2pqr-src-nbcr-'+pv+'.tar.gz', 'pdb2pqr-src-'+pv)
tar.add('apbs_libs/linux/apbslib.py','pdb2pka/apbslib.py')
tar.add('apbs_libs/linux/_apbslib.so','pdb2pka/_apbslib.so')
tar.close()
local("move pdb2pqr-src-nbcr-"+pv+'.tar.gz dist_files\\')
def start_src_tar(name='pdb2pqr.tgz', prefix=None):
file_list = local('git ls-tree -r --name-only HEAD', capture=True).split('\n')
tar = TarWrapper(name, prefix)
for f in file_list:
tar.add(f)
return tar
@runs_once
def create_dist_folder():
with settings(warn_only=True):
local('mkdir dist_files')
@runs_once
def pack_for_ditro():
create_dist_folder()
tar = start_src_tar('pdb2pqr-src-'+pv+'.tar.gz', 'pdb2pqr-src-'+pv)
tar.close()
local('copy Changelog.md "dist_files\PDB2PQR-' + pv + '-ReleaseNotes.txt"')
local("move pdb2pqr-src-"+pv+'.tar.gz dist_files\\')
def deploy():
python = 'python3'
put('pdb2pqr.tgz', '~/')
with settings(warn_only=True):
run('rm -rf tmp')
run('mkdir tmp')
with cd('~/tmp/'):
run('tar -zxvf ~/pdb2pqr.tgz')
run('scons')
if run_tests:
run('scons -j 4 pdb2pka-test')
run('scons -j 4 complete-test')
def install_on_deployed():
python = 'python3'
with settings(warn_only=True):
with cd('~/www/pdb2pqr'):
run('rm -rf *')
with cd('~/tmp/'):
configopts = ''
if hasattr(fabfile_settings, 'APBS'):
configopts += ' APBS='+fabfile_settings.APBS
if hasattr(fabfile_settings, 'URL'):
configopts += ' URL='+fabfile_settings.URL
if hasattr(fabfile_settings, 'PREFIX'):
configopts += ' PREFIX='+fabfile_settings.PREFIX
if hasattr(fabfile_settings, 'OPAL'):
configopts += ' OPAL='+fabfile_settings.OPAL
if hasattr(fabfile_settings, 'APBS_OPAL'):
configopts += ' APBS_OPAL='+fabfile_settings.APBS_OPAL
# if True:
# configopts += ' URL=http://PT24098/d3k084/pdb2pqr_opal'
# configopts += ' PREFIX=/Users/d3k084/www/pdb2pqr_opal/'
# configopts += ' APBS_OPAL=http://nbcr-222.ucsd.edu/opal2/services/apbs_1.3'
# configopts += ' OPAL=http://nbcr-222.ucsd.edu/opal2/services/pdb2pqr_2.0.0'
# else:
# configopts += ' PREFIX=/Users/d3k084/www/pdb2pqr/'
# configopts += ' URL=http://PT24098/d3k084/pdb2pqr'
run('scons ' + configopts)
run('scons install ' + configopts)
def build_binary_from_deploy():
create_dist_folder()
with cd('~/tmp/'):
os_string = 'NOT_SET_FIX_ME'
if env.host == linux_host:
os_string = 'linux'
if env.host == osx_host:
os_string = 'osx'
run('pyinstaller pdb2pqr.spec')
name = 'pdb2pqr-' + os_string + '-bin64-' + pv
run('mv dist/pdb2pqr dist/' + name)
with cd('dist/'):
run('tar -zcvf ' + name + '.tar.gz ' + name)
if run_tests:
with cd(name):
run('./pdb2pqr --ff=parse --verbose --ligand=examples/ligands/LIG_1ABF.mol2 1ABF 1ABF.pqr')
run('./pdb2pqr --with-ph=7.0 --ph-calc-method=pdb2pka --ff=parse --verbose 1a1p 1a1p.pqr')
get("~/tmp/dist/*.tar.gz","dist_files/")
def linux_bin_cross_platform_test():
'''
Push the linux bin to a host and test it.
'''
os_string = 'linux'
name = 'pdb2pqr-' + os_string + '-bin64-' + pv
put('dist_files/' + name + '.tar.gz', '~/')
run('tar -zxvf ~/' + name + '.tar.gz')
with cd(name):
run('./pdb2pqr --ff=parse --verbose --ligand=examples/ligands/LIG_1ABF.mol2 1ABF 1ABF.pqr')
run('./pdb2pqr --with-ph=7.0 --ph-calc-method=pdb2pka --ff=parse --verbose 1a1p 1a1p.pqr')
run('rm -rf '+name)
@runs_once
def build_windows():
local(r'copy apbs_libs\windows\* pdb2pka\\')
local(r'python3 scons\scons.py -c')
local(r'python3 scons\scons.py')
if run_tests:
local(r'python3 scons\scons.py -j 4 pdb2pka-test')
local(r'python3 scons\scons.py -j 7 complete-test')
build_windows_binary()
if run_tests:
test_windows_binary()
@runs_once
def test_windows_binary():
name = 'pdb2pqr-windows-bin64-' + pv
with lcd(r'dist\\' + name):
local(r'pdb2pqr --ff=parse --verbose --ligand=examples\ligands\LIG_1ABF.mol2 1ABF 1ABF.pqr')
local('pdb2pqr --with-ph=7.0 --ph-calc-method=pdb2pka --ff=parse --verbose 1a1p 1a1p.pqr')
@runs_once
def build_windows_binary():
with settings(warn_only=True):
local('del /Q /F dist')
local('pyinstaller pdb2pqr.spec')
name = 'pdb2pqr-windows-bin64-' + pv
local(r'move /Y dist\pdb2pqr dist\\' + name)
zip_file = zipfile.ZipFile(name + '.zip', 'w', zipfile.ZIP_DEFLATED)
for root, _, files in os.walk(r'dist\\'+name):
new_root = root.split('/', 1)[-1]
print(root)
for f in files:
zip_file_path = os.path.join(new_root,f)
real_file_path = os.path.join(root,f)
zip_file.write(real_file_path, zip_file_path)
print('Zipping ' + zip_file_path)
zip_file.close()
create_dist_folder()
local('move /Y ' + name + '.zip' + r' dist_files\\' + name + '.zip')
def build_all_tarballs():
pack_for_ditro()
pack_for_nbcr()
def build_all_binaries():
pack()
deploy()
build_binary_from_deploy()
build_windows()
def deploy_and_install():
pack()
deploy()
install_on_deployed()
|