Example #1
0
def test_virtualenv():
    from metrique.utils import virtualenv_activate, virtualenv_deactivate
    from metrique.utils import active_virtualenv
    av = active_virtualenv
    orig_venv = av()
    if not orig_venv:
        # this test will only work if we START in a virtenv
        # otherwise, we don't know of a virtenv we can test against
        return
    assert av() == os.environ['VIRTUAL_ENV']
    assert virtualenv_deactivate() is True
    assert virtualenv_deactivate() is None
    assert av() == ''
    assert '' == os.environ['VIRTUAL_ENV']
    virtualenv_activate(orig_venv)
    assert av() == os.environ['VIRTUAL_ENV']
    assert av() == orig_venv

    assert virtualenv_activate() is None
    assert virtualenv_activate(orig_venv) is None

    try:
        virtualenv_activate('virtenv_that_doesnt_exist')
    except OSError:
        pass
    else:
        assert False, "Activated non-existing virtenv"
Example #2
0
def test_virtualenv():
    from metrique.utils import virtualenv_activate, virtualenv_deactivate
    from metrique.utils import active_virtualenv
    av = active_virtualenv
    orig_venv = av()
    if not orig_venv:
        # this test will only work if we START in a virtenv
        # otherwise, we don't know of a virtenv we can test against
        return
    assert av() == os.environ['VIRTUAL_ENV']
    assert virtualenv_deactivate() is True
    assert virtualenv_deactivate() is None
    assert av() == ''
    assert '' == os.environ['VIRTUAL_ENV']
    virtualenv_activate(orig_venv)
    assert av() == os.environ['VIRTUAL_ENV']
    assert av() == orig_venv

    assert virtualenv_activate() is None
    assert virtualenv_activate(orig_venv) is None

    try:
        virtualenv_activate('virtenv_that_doesnt_exist')
    except OSError:
        pass
    else:
        assert False, "Activated non-existing virtenv"
Example #3
0
def _deploy_virtenv_init(args):
    _virtenv = utils.active_virtualenv()
    virtenv = getattr(args, 'virtenv') or _virtenv
    # skip if we're already in the targeted virtenv...
    if virtenv and virtenv != _virtenv:
        # we can't alrady be in a virtenv when running virtualenv.main()
        utils.virtualenv_deactivate()

        # scratch the existing virtenv directory, if requested
        if args.trash:
            utils.remove_file(virtenv, force=True)
            if args.trash_home:
                trash()

        # virtualenv.main; pass in only the virtenv path
        sys.argv = sys.argv[0:1] + [virtenv]
        # run the virtualenv script to install the virtenv
        virtualenv.main()

        # activate the newly installed virtenv
        utils.virtualenv_activate(args.virtenv)
    return virtenv
Example #4
0
def _deploy_virtenv_init(args):
    _virtenv = utils.active_virtualenv()
    virtenv = getattr(args, 'virtenv') or _virtenv
    # skip if we're already in the targeted virtenv...
    if virtenv and virtenv != _virtenv:
        # we can't alrady be in a virtenv when running virtualenv.main()
        utils.virtualenv_deactivate()

        # scratch the existing virtenv directory, if requested
        if args.trash:
            utils.remove_file(virtenv, force=True)
            if args.trash_home:
                trash()

        # virtualenv.main; pass in only the virtenv path
        sys.argv = sys.argv[0:1] + [virtenv]
        # run the virtualenv script to install the virtenv
        virtualenv.main()

        # activate the newly installed virtenv
        utils.virtualenv_activate(args.virtenv)
    return virtenv
Example #5
0
def main():
    import argparse

    cli = argparse.ArgumentParser(description='Metrique Manage CLI')
    cli.add_argument('-V', '--virtenv')
    cli.add_argument('-v', '--verbose')

    _sub = cli.add_subparsers(description='action', dest='action')

    # Automated metrique deployment
    _deploy = _sub.add_parser('deploy')
    _deploy.add_argument('--no-pre',
                         action='store_true',
                         help='ignore pre-release versions')
    _deploy.add_argument('--develop',
                         action='store_true',
                         help='install in "develop mode"')
    _deploy.add_argument('--test',
                         action='store_true',
                         help='run tests after deployment')
    _deploy.add_argument('--all',
                         action='store_true',
                         help='install all "extra" dependencies')
    _deploy.add_argument('--ipython',
                         action='store_true',
                         help='install ipython')
    _deploy.add_argument('--sqlalchemy',
                         action='store_true',
                         help='install sqlalchemy')
    _deploy.add_argument('--pytest',
                         action='store_true',
                         help='install pytest')
    _deploy.add_argument('--docs',
                         action='store_true',
                         help='install doc utils')
    _deploy.add_argument('--supervisord',
                         action='store_true',
                         help='install supervisord')
    _deploy.add_argument('--joblib',
                         action='store_true',
                         help='install joblib')
    _deploy.add_argument('--postgres',
                         action='store_true',
                         help='install postgres')
    _deploy.add_argument('--celery',
                         action='store_true',
                         help='install celery')
    _deploy.add_argument('--pymongo',
                         action='store_true',
                         help='install pymongo, pql')
    _deploy.add_argument('--pandas',
                         action='store_true',
                         help='install pandas')
    _deploy.add_argument('--matplotlib',
                         action='store_true',
                         help='install matplotlib')
    _deploy.add_argument('--dulwich',
                         action='store_true',
                         help='install dulwich')
    _deploy.add_argument('--paramiko',
                         action='store_true',
                         help='install paramiko')
    _deploy.add_argument('--cython',
                         action='store_true',
                         help='install cython')
    _deploy.add_argument('--trash',
                         action='store_true',
                         help='fresh install (rm old virtenv)')
    _deploy.add_argument('--trash-home',
                         action='store_true',
                         help='fresh install (rm old virtenv)')
    _deploy.set_defaults(func=deploy)

    # PIP standard build
    _build = _sub.add_parser('build')
    _build.set_defaults(func=build)

    # PIP sdist build
    _sdist = _sub.add_parser('sdist')
    _sdist.add_argument('-u', '--upload', action='store_true')
    _sdist.add_argument('-b', '--bump-r', action='store_true')
    _sdist.set_defaults(func=sdist)

    # PIP `develop` deployment
    _develop = _sub.add_parser('develop')
    _develop.set_defaults(func=develop)

    # PIP pkg register
    _register = _sub.add_parser('register')
    _register.set_defaults(func=register)

    # Trash existing metrique installation
    _trash = _sub.add_parser('trash')
    _trash.add_argument('named', nargs='*')
    _trash.set_defaults(func=trash)

    # Firstboot routines
    _firstboot = _sub.add_parser('firstboot')
    _firstboot.add_argument(
        'command',
        nargs='+',
        choices=['metrique', 'postgresql', 'supervisord', 'nginx'])
    _firstboot.add_argument('-f', '--force', action='store_true')
    #_firstboot.add_argument('-A', '--no-auth', action='store_true')
    _firstboot.set_defaults(func=firstboot)

    # Cython commands
    _cython = _sub.add_parser('cython')
    _cython.add_argument('command', choices=['compile', 'clean'])
    _cython.set_defaults(func=cython)

    # rsync
    _rsync = _sub.add_parser('rsync')
    _rsync.add_argument('targets', nargs='*')
    _rsync.add_argument('-Z', '--nocompress', action='store_true')
    _rsync.add_argument('-H', '--ssh-host')
    _rsync.add_argument('-u', '--ssh-user', default='backup')
    _rsync.set_defaults(func=rsync)

    # nginx Server
    _nginx = _sub.add_parser('nginx')
    _nginx.add_argument('command',
                        choices=['start', 'stop', 'reload', 'restart', 'test'])
    _nginx.add_argument('-F', '--nofork', action='store_true')
    _nginx.set_defaults(func=nginx)

    # celeryd task run
    _celeryd_task = _sub.add_parser('celeryd_task')
    _celeryd_task.add_argument('task')
    _celeryd_task.add_argument('--tasks-mod', default='dataservices.tasks')
    _celeryd_task.set_defaults(func=celeryd_task)

    # celeryd server
    _celeryd = _sub.add_parser('celeryd')
    _celeryd.add_argument('command', choices=['start', 'stop', 'clean'])
    _celeryd.add_argument('--tasks-mod', default='dataservices.tasks')
    _celeryd.add_argument('-F', '--nofork', action='store_true')
    _celeryd.set_defaults(func=celeryd)

    # celerybeat server
    _celerybeat = _sub.add_parser('celerybeat')
    _celerybeat.add_argument('command', choices=['start', 'stop', 'clean'])
    _celerybeat.add_argument('--tasks-mod', default='dataservices.tasks')
    _celerybeat.add_argument('-F', '--nofork', action='store_true')
    _celerybeat.set_defaults(func=celerybeat)

    # supervisord server
    _supervisord = _sub.add_parser('supervisord')
    _supervisord.add_argument('command',
                              choices=['start', 'stop', 'clean', 'reload'])
    _supervisord.set_defaults(func=supervisord)

    # postgresql server
    _postgresql = _sub.add_parser('postgresql')
    _postgresql.add_argument(
        'command', choices=['start', 'stop', 'trash', 'clean', 'reload'])
    _postgresql.add_argument('-F', '--nofork', action='store_true')
    _postgresql.set_defaults(func=postgresql)

    # SSL creation
    _ssl = _sub.add_parser('ssl')
    _ssl.set_defaults(func=ssl)

    # parse argv
    args = cli.parse_args()

    if args.verbose:
        logger.setLevel(logging.DEBUG)

    logger.debug('-' * 30)
    logger.debug('Started at  : %s' % NOW)
    logger.debug('Current User: %s' % USER)
    logger.debug('Virtual Env : %s' % VIRTUAL_ENV)
    logger.debug('Hostname    : %s' % HOSTNAME)
    logger.debug('Local IP    : %s' % LOCAL_IP)
    logger.debug('This file   : %s' % __file__)
    logger.debug('Home Path   : %s' % HOME_DIR)
    logger.debug('User Path   : %s' % PREFIX_DIR)
    logger.debug('-' * 30)

    # Activate the virtual environment in this python session if
    # parent env has one set
    # unless we are deploying
    if args.action != 'deploy':
        utils.virtualenv_activate()

    # run command
    args.func(args)
Example #6
0
def main():
    import argparse

    cli = argparse.ArgumentParser(description='Metrique Manage CLI')
    cli.add_argument('-V', '--virtenv')
    cli.add_argument('-v', '--verbose')

    _sub = cli.add_subparsers(description='action', dest='action')

    # Automated metrique deployment
    _deploy = _sub.add_parser('deploy')
    _deploy.add_argument(
        '--no-pre', action='store_true',
        help='ignore pre-release versions')
    _deploy.add_argument(
        '--develop', action='store_true', help='install in "develop mode"')
    _deploy.add_argument(
        '--test', action='store_true', help='run tests after deployment')
    _deploy.add_argument(
        '--all', action='store_true', help='install all "extra" dependencies')
    _deploy.add_argument(
        '--ipython', action='store_true', help='install ipython')
    _deploy.add_argument(
        '--sqlalchemy', action='store_true', help='install sqlalchemy')
    _deploy.add_argument(
        '--pytest', action='store_true', help='install pytest')
    _deploy.add_argument(
        '--docs', action='store_true', help='install doc utils')
    _deploy.add_argument(
        '--supervisord', action='store_true', help='install supervisord')
    _deploy.add_argument(
        '--joblib', action='store_true', help='install joblib')
    _deploy.add_argument(
        '--postgres', action='store_true', help='install postgres')
    _deploy.add_argument(
        '--celery', action='store_true', help='install celery')
    _deploy.add_argument(
        '--pymongo', action='store_true', help='install pymongo, pql')
    _deploy.add_argument(
        '--pandas', action='store_true', help='install pandas')
    _deploy.add_argument(
        '--matplotlib', action='store_true', help='install matplotlib')
    _deploy.add_argument(
        '--dulwich', action='store_true', help='install dulwich')
    _deploy.add_argument(
        '--paramiko', action='store_true', help='install paramiko')
    _deploy.add_argument(
        '--cython', action='store_true', help='install cython')
    _deploy.add_argument(
        '--trash', action='store_true', help='fresh install (rm old virtenv)')
    _deploy.add_argument(
        '--trash-home', action='store_true',
        help='fresh install (rm old virtenv)')
    _deploy.set_defaults(func=deploy)

    # PIP standard build
    _build = _sub.add_parser('build')
    _build.set_defaults(func=build)

    # PIP sdist build
    _sdist = _sub.add_parser('sdist')
    _sdist.add_argument('-u', '--upload', action='store_true')
    _sdist.add_argument('-b', '--bump-r', action='store_true')
    _sdist.set_defaults(func=sdist)

    # PIP `develop` deployment
    _develop = _sub.add_parser('develop')
    _develop.set_defaults(func=develop)

    # PIP pkg register
    _register = _sub.add_parser('register')
    _register.set_defaults(func=register)

    # Trash existing metrique installation
    _trash = _sub.add_parser('trash')
    _trash.add_argument('named', nargs='*')
    _trash.set_defaults(func=trash)

    # Firstboot routines
    _firstboot = _sub.add_parser('firstboot')
    _firstboot.add_argument('command',
                            nargs='+',
                            choices=['metrique', 'postgresql',
                                     'supervisord', 'nginx'])
    _firstboot.add_argument('-f', '--force', action='store_true')
    #_firstboot.add_argument('-A', '--no-auth', action='store_true')
    _firstboot.set_defaults(func=firstboot)

    # Cython commands
    _cython = _sub.add_parser('cython')
    _cython.add_argument('command',
                         choices=['compile', 'clean'])
    _cython.set_defaults(func=cython)

    # rsync
    _rsync = _sub.add_parser('rsync')
    _rsync.add_argument('targets', nargs='*')
    _rsync.add_argument('-Z', '--nocompress', action='store_true')
    _rsync.add_argument('-H', '--ssh-host')
    _rsync.add_argument('-u', '--ssh-user', default='backup')
    _rsync.set_defaults(func=rsync)

    # nginx Server
    _nginx = _sub.add_parser('nginx')
    _nginx.add_argument('command',
                        choices=['start', 'stop', 'reload',
                                 'restart', 'test'])
    _nginx.add_argument('-F', '--nofork', action='store_true')
    _nginx.set_defaults(func=nginx)

    # celeryd task run
    _celeryd_task = _sub.add_parser('celeryd_task')
    _celeryd_task.add_argument('task')
    _celeryd_task.add_argument('--tasks-mod', default='dataservices.tasks')
    _celeryd_task.set_defaults(func=celeryd_task)

    # celeryd server
    _celeryd = _sub.add_parser('celeryd')
    _celeryd.add_argument('command', choices=['start', 'stop', 'clean'])
    _celeryd.add_argument('--tasks-mod', default='dataservices.tasks')
    _celeryd.add_argument('-F', '--nofork', action='store_true')
    _celeryd.set_defaults(func=celeryd)

    # celerybeat server
    _celerybeat = _sub.add_parser('celerybeat')
    _celerybeat.add_argument('command', choices=['start', 'stop', 'clean'])
    _celerybeat.add_argument('--tasks-mod', default='dataservices.tasks')
    _celerybeat.add_argument('-F', '--nofork', action='store_true')
    _celerybeat.set_defaults(func=celerybeat)

    # supervisord server
    _supervisord = _sub.add_parser('supervisord')
    _supervisord.add_argument('command', choices=['start', 'stop',
                                                  'clean', 'reload'])
    _supervisord.set_defaults(func=supervisord)

    # postgresql server
    _postgresql = _sub.add_parser('postgresql')
    _postgresql.add_argument('command', choices=['start', 'stop',
                                                 'trash', 'clean', 'reload'])
    _postgresql.add_argument('-F', '--nofork', action='store_true')
    _postgresql.set_defaults(func=postgresql)

    # SSL creation
    _ssl = _sub.add_parser('ssl')
    _ssl.set_defaults(func=ssl)

    # parse argv
    args = cli.parse_args()

    if args.verbose:
        logger.setLevel(logging.DEBUG)

    logger.debug('-' * 30)
    logger.debug('Started at  : %s' % NOW)
    logger.debug('Current User: %s' % USER)
    logger.debug('Virtual Env : %s' % VIRTUAL_ENV)
    logger.debug('Hostname    : %s' % HOSTNAME)
    logger.debug('Local IP    : %s' % LOCAL_IP)
    logger.debug('This file   : %s' % __file__)
    logger.debug('Home Path   : %s' % HOME_DIR)
    logger.debug('User Path   : %s' % PREFIX_DIR)
    logger.debug('-' * 30)

    # Activate the virtual environment in this python session if
    # parent env has one set
    # unless we are deploying
    if args.action != 'deploy':
        utils.virtualenv_activate()

    # run command
    args.func(args)