def clear_folders(): # Clear build folders if is_path(BUILD_DIR): command('rm -rf %s' % BUILD_DIR) if is_path(DIST_DIR): command('rm -rf %s' % DIST_DIR) if not is_path(RELEASE_DIR): os.makedirs(RELEASE_DIR)
def rebuild_images(): command('docker rm $(docker ps -a -q) 2> /dev/null') command('docker rmi $(docker images -a -q) 2> /dev/null') for image in IMAGES[:-1]: echo_msg('Rebuilding %s%s image' % (IMAGE_PREFIX, image), code=STDOUT_MAGENTA) dockerfile = os.path.join(PROJECT_DIR, 'infra', 'bbox', 'docker', image) command('docker build -t %s%s %s' % (IMAGE_PREFIX, image, dockerfile)) if not command('docker push %s%s' % (IMAGE_PREFIX, image)): command('docker rmi $(docker images -a -q)')
def run_build(locally=False, stop_on_error=True): echo_msg('Project %s build started' % PROJECT, code=STDOUT_MAGENTA) echo_msg('=' * 35, code=STDOUT_MAGENTA) if not locally: set_build_stamp() if is_path(RELEASE_DIR): command('sudo rm -rf %s' % RELEASE_DIR) if is_path(LOCALES_DIR): command('sudo rm -rf %s' % LOCALES_DIR) for image in IMAGES if not locally else LOCAL_IMAGES: os_name = image.capitalize().replace('_', ' ') msg = 'Build on %s' % os_name echo_msg(msg + ' ' * (35 - len(msg)) + '...', newline=False) output = ' 1> /dev/null 2> /dev/null' if not DEBUG_MODE else '' cmd = '/vagrant/bbox.py build_package --project=%s' % PROJECT if image == 'packager': cmd = '/vagrant/bbox.py packaging --project=%s' % PROJECT if RELEASE: cmd += ' --release=1' if shell( 'docker run --rm -v %s:%s %s%s %s %s' % (PROJECT_DIR, VAGRANT_DIR, IMAGE_PREFIX, image, cmd, output), 2): echo_msg('[ FAIL ]', code=STDOUT_FAIL) if stop_on_error or not locally: sys.exit(1) else: echo_msg('[ OK ]', code=STDOUT_GREEN) if not locally and PUBLISH: msg = 'Publishing result' msg = msg + ' ' * (35 - len(msg)) + '...' echo_msg(msg, newline=False) folder = PROJECT + '-release' if RELEASE else PROJECT if os.system('sshpass -e rsync -a --delete-after -e ' '\'ssh -o StrictHostKeyChecking=no -o ' 'UserKnownHostsFile=/dev/null -p 22\' ' './release/ `echo $RHOST`%s/ ' '1> /dev/null 2> /dev/null' % folder): echo_msg('[ FAIL ]', code=STDOUT_FAIL) sys.exit(1) echo_msg('[ OK ]', code=STDOUT_GREEN) echo_msg('=' * 35, code=STDOUT_MAGENTA)
def build_package(): mint_folder = os.path.join(RELEASE_DIR, 'LinuxMint') eos_folder = os.path.join(RELEASE_DIR, 'elementaryOS') mx_folder = os.path.join(RELEASE_DIR, 'MX_Linux') copies = [] out = ' 1> /dev/null 2> /dev/null' if not DEBUG_MODE else '' clear_folders() if SYSFACTS.is_deb: echo_msg('Building DEB package') command('cd %s;python3 %s bdist_deb%s' % (PROJECT_DIR, SCRIPT, out)) old_name = bbox.get_package_name(DIST_DIR) prefix, suffix = old_name.split('_') new_name = prefix + bbox.get_marker(not RELEASE) + suffix prefix += '_' + bbox.TIMESTAMP if not RELEASE else '' if SYSFACTS.is_ubuntu and SYSFACTS.version == '14.04': copies.append((prefix + '_mint_17_' + suffix, mint_folder)) if SYSFACTS.is_64bit: copies.append( (prefix + '_elementary0.3_' + suffix, eos_folder)) elif SYSFACTS.is_ubuntu and SYSFACTS.version == '16.04': copies.append((prefix + '_mint_18_' + suffix, mint_folder)) if SYSFACTS.is_64bit: copies.append( (prefix + '_elementary0.4_' + suffix, eos_folder)) elif SYSFACTS.is_ubuntu and SYSFACTS.version == '18.04': copies.append((prefix + '_mint_19_' + suffix, mint_folder)) if SYSFACTS.is_64bit: copies.append( (prefix + '_elementary5.0_' + suffix, eos_folder)) elif SYSFACTS.is_ubuntu and SYSFACTS.version == '20.04': copies.append((prefix + '_mint_20_' + suffix, mint_folder)) elif SYSFACTS.is_debian: ver = SYSFACTS.version.split('.')[0] if ver == '8': copies.append((prefix + '_mx15_' + suffix, mx_folder)) copies.append((prefix + '_mx16_' + suffix, mx_folder)) elif ver == '9': copies.append((prefix + '_mx17_' + suffix, mx_folder)) copies.append((prefix + '_mx18_' + suffix, mx_folder)) elif ver == '10': copies.append((prefix + '_mx19_' + suffix, mx_folder)) elif SYSFACTS.is_rpm: echo_msg('Building RPM package') command('cd %s;python3 %s bdist_rpm%s' % (PROJECT_DIR, SCRIPT, out)) old_name = bbox.get_package_name(DIST_DIR) items = old_name.split('.') marker = bbox.get_marker(not RELEASE) new_name = '.'.join(items[:-2] + [ marker, ] + items[-2:]) else: echo_msg('Unsupported distro!', code=STDOUT_FAIL) sys.exit(1) distro_folder = os.path.join(RELEASE_DIR, SYSFACTS.hmarker) if not is_path(distro_folder): os.makedirs(distro_folder) old_name = os.path.join(DIST_DIR, old_name) package_name = os.path.join(RELEASE_DIR, distro_folder, new_name) command('cp %s %s' % (old_name, package_name)) # Package copies for name, folder in copies: if not is_path(folder): os.makedirs(folder) name = os.path.join(RELEASE_DIR, folder, name) command('cp %s %s' % (old_name, name)) if SYSFACTS.is_src: echo_msg('Creating source package') if os.path.isdir(DIST_DIR): shutil.rmtree(DIST_DIR, True) command('cd %s;python3 %s sdist %s' % (PROJECT_DIR, SCRIPT, out)) old_name = bbox.get_package_name(DIST_DIR) marker = '_%s' % bbox.TIMESTAMP if not RELEASE else '' new_name = old_name.replace('.tar.gz', '%s.tar.gz' % marker) old_name = os.path.join(DIST_DIR, old_name) package_name = os.path.join(RELEASE_DIR, new_name) command('cp %s %s' % (old_name, package_name)) # ArchLinux PKGBUILD # if os.path.isdir(PKGBUILD_DIR): # shutil.rmtree(PKGBUILD_DIR, True) # os.mkdir(PKGBUILD_DIR) # os.chdir(PKGBUILD_DIR) # # tarball = os.path.join(PKGBUILD_DIR, new_name) # command('cp %s %s' % (package_name, tarball)) # # dest = 'PKGBUILD' # src = os.path.join(ARCH_DIR, '%s-%s' % (dest, APP_NAME)) # command('cp %s %s' % (src, dest)) # command("sed -i 's/VERSION/%s/g' %s" % (APP_VER, dest)) # command("sed -i 's/TARBALL/%s/g' %s" % (new_name, dest)) # # dest = 'README' # src = os.path.join(ARCH_DIR, '%s-%s' % (dest, APP_NAME)) # command('cp %s %s' % (src, dest)) # # pkg_name = new_name.replace('.tar.gz', '.archlinux.pkgbuild.zip') # arch_folder = os.path.join(RELEASE_DIR, 'ArchLinux') # os.makedirs(arch_folder) # pkg_name = os.path.join(arch_folder, pkg_name) # ziph = ZipFile(pkg_name, 'w', ZIP_DEFLATED) # for item in [new_name, 'PKGBUILD', 'README']: # path = os.path.join(PKGBUILD_DIR, item) # ziph.write(path, item) # ziph.close() # shutil.rmtree(PKGBUILD_DIR, True) clear_folders()
def run_build_local(): run_build(locally=True, stop_on_error=False) command('chmod -R 777 %s' % RELEASE_DIR) command('sudo rm -rf %s' % LOCALES_DIR)
def remove_images(): for image in IMAGES: command('docker rmi %s%s' % (IMAGE_PREFIX, image))
def build_msw_packages(): echo_msg('Creating portable package') distro_folder = os.path.join(RELEASE_DIR, 'MS_Windows') out = ' 1> /dev/null 2> /dev/null' if not DEBUG_MODE else '' clear_folders() if os.path.isdir(DIST_DIR): shutil.rmtree(DIST_DIR, True) command('cd %s;python2 %s build %s' % (PROJECT_DIR, SCRIPT, out)) libdir = os.path.join(BUILD_DIR, 'lib.linux-x86_64-2.7') build.compile_sources(libdir) clear_files(libdir) clear_files(libdir, 'so') for arch in ['win32', 'win64']: portable_name = '%s-%s-%s-portable' % (APP_NAME, APP_VER, arch) if not RELEASE: portable_name = '%s-%s-%s-%s-portable' % \ (APP_NAME, APP_VER, TIMESTAMP, arch) portable_folder = os.path.join(PROJECT_DIR, portable_name) if os.path.exists(portable_folder): shutil.rmtree(portable_folder, True) os.mkdir(portable_folder) portable = os.path.join('/%s-devres' % arch, 'portable.zip') echo_msg('Extracting portable files from %s' % portable) ZipFile(portable, 'r').extractall(portable_folder) build.compile_sources(portable_folder) clear_files(portable_folder) portable_libs = os.path.join(portable_folder, 'libs') for item in PKGS: src = os.path.join(libdir, item) echo_msg('Copying tree %s' % src) shutil.copytree(src, os.path.join(portable_libs, item)) for item in EXTENSIONS: filename = os.path.basename(item) src = os.path.join('/%s-devres' % arch, 'pyd', filename) dst = os.path.join(portable_libs, item) shutil.copy(src, dst) if not is_path(distro_folder): os.makedirs(distro_folder) portable_zip = os.path.join(distro_folder, portable_name + '.zip') ziph = ZipFile(portable_zip, 'w', ZIP_DEFLATED) echo_msg('Compressing into %s' % portable_zip) for root, dirs, files in os.walk(portable_folder): for item in files: path = os.path.join(root, item) local_path = path.split(portable_name)[1][1:] ziph.write(path, os.path.join(portable_name, local_path)) ziph.close() shutil.rmtree(portable_folder, True) # Build clearing ##### shutil.rmtree(BUILD_DIR, True) for item in ['MANIFEST', 'MANIFEST.in', 'src/script/sk1', 'src/script/uniconvertor', 'setup.cfg']: item = os.path.join(PROJECT_DIR, item) if os.path.lexists(item): os.remove(item)
def run_build(): echo_msg('BuildBox started', code=STDOUT_MAGENTA) echo_msg('=' * 30, code=STDOUT_MAGENTA) if VAGRANT_DIR != PROJECT_DIR: if is_path(VAGRANT_DIR): command('rm -f %s' % VAGRANT_DIR) command('ln -s %s %s' % (PROJECT_DIR, VAGRANT_DIR)) if is_path(RELEASE_DIR): command('rm -rf %s' % RELEASE_DIR) for image in IMAGES: os_name = image.capitalize().replace('_', ' ') echo_msg('Build on %s' % os_name, code=STDOUT_YELLOW) output = ' 1> /dev/null' if not DEBUG_MODE else '' if command('docker run --rm -v %s:%s %s%s %s' % (PROJECT_DIR, VAGRANT_DIR, IMAGE_PREFIX, image, output)): echo_msg('=' * 30 + '> FAIL', code=STDOUT_FAIL) else: echo_msg('=' * 30 + '> OK', code=STDOUT_GREEN) command('chmod -R 777 %s' % RELEASE_DIR) if VAGRANT_DIR != PROJECT_DIR: command('rm -f %s' % VAGRANT_DIR)
def pull_images(): for image in IMAGES: echo_msg('Pulling %s%s image' % (IMAGE_PREFIX, image), code=STDOUT_GREEN) command('docker pull %s%s' % (IMAGE_PREFIX, image))