Пример #1
0
def trac_admin(env, cmd, sudoer=None):
    """
    Runs trac-admin command on specified environment with permiss
    :param env: Name or path to the environment
    :param cmd: Command to pass to trac-admin
    :param sudoer: Optional sudo user, defaults to Apache user

    Examples::

        fab dist.trac_admin:home,help
        fab dist.trac_admin:"home","mp deploy"
        fab dist.trac_admin:env="home",cmd="mp deploy",sudoer="root"
        fab dist.trac_admin:"/var/www/trac/projects/projectx","upgrade"
        fab dist.trac_admin:"/var/www/trac/projects/projectx","upgrade","www-data"

    """
    trac_root_dir = config['trac_root']
    sudoer = sudoer or config['webserver_user']
    if sudoer == 'root':
        sudoer = None

    # Check if path is given, otherwise consider it project name
    if not exists(env):
        env = os.path.join(trac_root_dir, 'projects', env)
        if not exists(env):
            return abort('Given environment "%s" cannot be found on server' % env)

    with cd(env):
        tracadmin_cmd = 'trac-admin %s %s' % (env, cmd)
        sudo(tracadmin_cmd, user=sudoer)
Пример #2
0
def trac_admin(env, cmd, sudoer=None):
    """
    Runs trac-admin command on specified environment with permiss
    :param env: Name or path to the environment
    :param cmd: Command to pass to trac-admin
    :param sudoer: Optional sudo user, defaults to Apache user

    Examples::

        fab dist.trac_admin:home,help
        fab dist.trac_admin:"home","mp deploy"
        fab dist.trac_admin:env="home",cmd="mp deploy",sudoer="root"
        fab dist.trac_admin:"/var/www/trac/projects/projectx","upgrade"
        fab dist.trac_admin:"/var/www/trac/projects/projectx","upgrade","www-data"

    """
    trac_root_dir = config['trac_root']
    sudoer = sudoer or config['webserver_user']
    if sudoer == 'root':
        sudoer = None

    # Check if path is given, otherwise consider it project name
    if not exists(env):
        env = os.path.join(trac_root_dir, 'projects', env)
        if not exists(env):
            return abort('Given environment "%s" cannot be found on server' %
                         env)

    with cd(env):
        tracadmin_cmd = 'trac-admin %s %s' % (env, cmd)
        sudo(tracadmin_cmd, user=sudoer)
Пример #3
0
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)
Пример #4
0
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)
Пример #5
0
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)
Пример #6
0
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)