def deploy_targz(packagename, opts): """ Run the deploy activities for source/custom tar.gz package. The script can deploy following kind of tar.gz packages: - Python source package: if setup.py is found from root folder, it is run with python setup.py install - Custom source package (created with build task): runs scripts/deploy.sh found from the package :param str packagename: Name of the package to deploy. Example 'mypackage-1.1.0.tar.gz' :param str opts: Optional parameters to pass to deploying app (easy_install, rpm, dpkg, deploy.sh) """ root_dir = config['trac_root'] webserver_user = config['webserver_user'] webserver_group = config['webserver_group'] releasename, releaseversion, releaseextension = split_package_name( packagename) # Get the subdirectory (where all the files are place) of the archive, if any out = run('tar ztf %s' % packagename) subdir = os.path.commonprefix(out.stdout.splitlines()) run('tar zxf %s' % packagename) with cd('~/%s' % subdir): # Run the setup.py if is found if exists('setup.py'): logger.info( 'Installing python module from source, using: %s/setup.py' % releasename) sudo('python setup.py install %s' % opts) # Custom package, expect to find scripts/deploy.sh else: logger.info( 'Running deploy script ./scripts/deploy.sh at directory: %s' % subdir) with settings(show('stdout')): sudo('./scripts/deploy.sh %s' % opts) # Fix file permissions logger.info('Setting the permissions to deployment folder') sudo('chown -L -R %s:%s %s' % (webserver_user, webserver_group, join(root_dir, 'dist', 'current'))) # Cleanup - needs to be done with sudo because of sudo is being used at running deploy.sh (at the moment) with cd('~'): logger.info('Cleaning up...') if subdir: sudo('rm -rf ./%s' % subdir) sudo('rm -rf ./%s' % releasename)
def whoami(): """ Show whoami both with and without sudo Testing purpose. """ logger.info('Running whoami with sudo: %s' % sudo('whoami')) logger.info('Running whoami with user: %s' % run('whoami'))
def deploy_targz(packagename, opts): """ Run the deploy activities for source/custom tar.gz package. The script can deploy following kind of tar.gz packages: - Python source package: if setup.py is found from root folder, it is run with python setup.py install - Custom source package (created with build task): runs scripts/deploy.sh found from the package :param str packagename: Name of the package to deploy. Example 'mypackage-1.1.0.tar.gz' :param str opts: Optional parameters to pass to deploying app (easy_install, rpm, dpkg, deploy.sh) """ root_dir = config['trac_root'] webserver_user = config['webserver_user'] webserver_group = config['webserver_group'] releasename, releaseversion, releaseextension = split_package_name(packagename) # Get the subdirectory (where all the files are place) of the archive, if any out = run('tar ztf %s' % packagename) subdir = os.path.commonprefix(out.stdout.splitlines()) run('tar zxf %s' % packagename) with cd('~/%s' % subdir): # Run the setup.py if is found if exists('setup.py'): logger.info('Installing python module from source, using: %s/setup.py' % releasename) sudo('python setup.py install %s' % opts) # Custom package, expect to find scripts/deploy.sh else: logger.info('Running deploy script ./scripts/deploy.sh at directory: %s' % subdir) with settings(show('stdout')): sudo('./scripts/deploy.sh %s' % opts) # Fix file permissions logger.info('Setting the permissions to deployment folder') sudo('chown -L -R %s:%s %s' % (webserver_user, webserver_group, join(root_dir, 'dist', 'current'))) # Cleanup - needs to be done with sudo because of sudo is being used at running deploy.sh (at the moment) with cd('~'): logger.info('Cleaning up...') if subdir: sudo('rm -rf ./%s' % subdir) sudo('rm -rf ./%s' % releasename)
def show_status(): """ Show short status info about the host """ # Testing envvars = ['ROOT', 'PATH', 'LD_LIBRARY_PATH'] for evar in envvars: value = run('echo $%s' % evar) print '%s: %s' % (evar, value)
def upload(package, rdir=''): """ Uploads the given package to remote host :param str package: Path to package, absolute or relative :param str rdir: Remote directory where to upload the package. Defaults to users home directory Examples:: fab dist.upload:package.tar.gz,/tmp fab dist.upload:package=../../package.tar.gz fab dist.upload:package=../../packa*.tar.gz fab dist.upload:package=../../package.tar.gz,rdir=/tmp .. NOTE:: Special paths, containing environment variables or tilde characters are not supported. """ # Use glob to find package from local filesystem (glob supports wildcards) pmatches = glob(os.path.expandvars(os.path.expanduser(package))) if not pmatches: return abort('No package can be found with name: %s' % package) # Upload package(s) to remote host and determine the name of release folder for pmatch in pmatches: package = os.path.normpath(pmatch) # Get the release name from package: drop the extension and version packagename = os.path.basename(package) target_path = join(rdir, packagename) if rdir else packagename target_dir = os.path.dirname(target_path) # Upload package to specified directory, with the same name as the orig logger.info('Uploading the package: %s -> %s' % (package, target_path)) if not exists(target_dir): run(target_dir) put(package, target_path)
def show_summary(): """ Shows summary about the setup """ logger.info(run('echo ROOT=$ROOT'))