示例#1
0
def _main(args):
    root_path = args.root_path or find_app_root()
    appcfg = load_app_config(root_path)

    ret = sync_database(root_path, args.dump_mysql, args.server,remote=True)
    if 'succeeded' not in ret:
        logger.info("Syncdb failed, deploy exit ...")
        sys.exit(1)

    logger.info("Pushing modifications...")
    push_modifications(root_path)

    vcs_url = get_vcs_url(root_path)
    if not vcs_url:
        logger.error("%s is not under version control. abort.", root_path)
        sys.exit(1)
    logger.debug("app url: %s", vcs_url)

    logger.info("Deploying to servers...")
    data = {'app_name': appcfg['application'],
            'app_url': vcs_url}

    if args.fast:
        data['fast'] = '1'

    ret = deploy_to_server(data, args.server)
    if ret == 'Failed':
        logger.warning("It seems that the deploy failed.  Try again later.  "
                       "If the failure persists, contact admin please.")
        sys.exit(1)

    ret = mirror_statics(root_path, args.server)
    if 'succeeded' not in ret:
        logger.info("Mirror failed, deploy exit ...")
        sys.exit(1)
示例#2
0
def remote_main(args):
    logger.warning("CAUTION! CAUTION! CAUTION! ")
    logger.warning("You are connecting to the database in production environment!")
    logger.warning("BE CAREFUL!")

    root_path = args.root_path or find_app_root()
    appcfg = load_app_config(root_path)
    appname = appcfg['application']
    try:
        ws = create_connection("ws://%s.xiaom.co:5000/_sheep/mysql/" % appname)
        read_thread = Thread(target=read_output, args=(ws, ))
        read_thread.start()
    except:
        print 'Can\'t connect remote.'
        return
    try:
        while True:
            if not ws.connected:
                break
            else:
                command = raw_input('')
                if not command.endswith('\n'):
                    command += '\n'
                ws.send(command)
                if command == 'quit\n' or command == '\\q\n':
                    sys.stdout.write('Wait for connection closed.\t\n')
                    read_thread.join()
    except:
        ws.send('quit\n')
        read_thread.join()
    finally:
        ws.close()
示例#3
0
def main(args, argv):
    approot = find_app_root()
    init_app(approot)
    venvdir = get_venvdir(approot)
    pip_path = os.path.join(venvdir, 'bin', 'pip')

    if args.help:
        print "Usage: sheep install ..."
        print
        print "Delegate to `pip install' in the app's virtual environment."
        print "Must run within app directory."
        print
        print "Usage of `pip install' follows."
        print
        return call([pip_path] + argv)

    if not is_pip_compatible(pip_path):
        return "Your app environment needs to upgrade.  Run 'sheep sync' please."

    pip_download_dir = os.path.join(approot, 'pip-download')
    retval = call([pip_path] + argv + ['--save-download', pip_download_dir])
    dump_requirements(approot)
    if os.path.exists(os.path.join(approot, '.svn')):
        call(['svn', 'add', '-q', pip_download_dir] + \
             glob(os.path.join(pip_download_dir, '*')))
    elif os.path.exists(os.path.join(approot, '.hg')):
        call(['hg', 'add', pip_download_dir])
    return retval
示例#4
0
def main(args):
    root_path = args.root_path or find_app_root()
    appcfg = load_app_config(root_path)
    appname = appcfg['application']
    try:
        ws = create_connection("ws://%s.xiaom.co:5000/_sheep/shell/" % appname)
        read_thread = Thread(target=read_output, args=(ws, ))
        read_thread.start()
    except:
        print 'Can\'t connect remote.'
        return
    try:
        while True:
            if not ws.connected:
                break
            else:
                try:
                    command = raw_input('')
                    if not command.endswith('\n'):
                        command += '\n'
                    ws.send(command)
                    if command == 'quit()\n' or command == 'exit()\n':
                        sys.stdout.write('Wait for connection closed.\t\n')
                        read_thread.join()
                except KeyboardInterrupt:
                    print
                    print 'KeyboardInterrupt'
                    ws.send('\n')
    except:
        ws.send('quit()\n')
        read_thread.join()
    finally:
        ws.close()
示例#5
0
文件: log.py 项目: pigsoldierlu/sheep
def main(args):
    root_path = args.root_path or find_app_root()
    appcfg = load_app_config(root_path)
    appname = appcfg['application']
    try:
        ws = create_connection("ws://%s.xiaom.co:5000/_sheep/log/" % appname)
    except Exception, e:
        print e
        print 'Can\'t connect remote.'
        return
示例#6
0
def main(args, argv):
    approot = find_app_root()
    venvdir = get_venvdir(approot)
    if args.help:
        print "Usage: sheep uninstall ..."
        print
        print "Delegate to `pip uninstall' in the app's virtual environment."
        print "Must run within app directory."
        print
        print "Usage of `pip install' follows."
        print
    os.environ['SHEEP_IGN_SDKPATH'] = 'true'
    retval = call([os.path.join(venvdir, 'bin', 'pip')] + argv)
    dump_requirements(approot)
    return retval
示例#7
0
def main(args):
    approot = find_app_root()
    executable = os.path.join(approot, 'venv', 'bin', args.executable)
    if not os.path.exists(executable):
        logger.error("No such executable: %s", executable)
        return 1

    os.environ['SHEEP_SDK_PATH'] = site.PREFIXES[0]
    if args.executable == 'pip':
        os.environ['SHEEP_IGN_SDKPATH'] = 'true'
    activate_app(approot)

    rc = -1
    try:
        rc = call([executable] + args.arg)
    except KeyboardInterrupt:
        os.system('reset')
    return rc
示例#8
0
def dev_main(args):
    root_path = args.root_path or find_app_root()
    devcfg = load_dev_config(root_path)
    if 'mysql' not in devcfg:
        logger.fatal("No mysql defined in dev.yaml")
        return 1

    cfg = devcfg['mysql']

    cmd = ['mysql']
    if 'host' in cfg:
        cmd += ['-h', cfg['host']]
    if 'port' in cfg:
        cmd += ['-P', str(cfg['port'])]
    if 'user' in cfg:
        cmd += ['-u', cfg['user']]
    if 'passwd' in cfg:
        cmd += ['-p%s' % cfg['passwd']]
    cmd += [cfg['db']]

    return call(cmd)
示例#9
0
def main(args):
    approot = find_app_root()
    devcfg = load_dev_config(approot)
    if not os.path.exists(os.path.join(approot, TEST_YAML)):
        create_test_yaml(approot, devcfg, TEST_YAML)

    if 'mysql' in devcfg:
        sync_database(approot, 'db_dumps.sql', sync_data=False, remote=False)

    if not os.path.exists(os.path.join(approot, 'permdir_test')):
        os.mkdir(os.path.join(approot, 'permdir_test'))

    os.environ['SHEEP_DEV_YAML'] = TEST_YAML

    nosetests = load_entry_point('nose', 'console_scripts', 'nosetests')
    sys.argv = ['sheep test']
    if os.path.exists(os.path.join(approot, 'nose.cfg')):
        sys.argv += ['-c', os.path.join(approot, 'nose.cfg')]
    sys.argv += args.arg
    activate_app(approot)
    return nosetests()
示例#10
0
def main(args):
    root_path = args.root_path or find_app_root()
    sync_database(root_path, args.dump_mysql, server=args.server, \
                  sync_data=args.data, reset=args.reset, \
                  remote=args.remote)
示例#11
0
def main(args):
    approot = os.path.abspath(args.root_path or find_app_root())
    appcfg = load_app_config(approot)
    appname = appcfg['application']
    venvdir = get_venvdir(approot)

    vcs = get_vcs(approot)
    if vcs == 'hg':
        check_call(['hg', '-R', approot,  'pull', '-u'])
    elif vcs == 'svn':
        check_call(['svn', 'up', approot])
    elif vcs == 'git':
        try:
            check_call(['git', '--git-dir', os.path.join(approot, '.git'),
                        '--work-tree', approot, 'pull'])
        except:
            call(['git', '--git-dir', os.path.join(approot, '.git'), 'pull'])
    else:
        logger.error("%s is not under version control", approot)
        return 1

    if not os.path.exists(os.path.join(approot, 'permdir')):
        os.mkdir(os.path.join(approot, 'permdir'))

    if not os.path.exists(venvdir):
        pkgdir = os.path.join(os.path.dirname(os.path.dirname(here)),
                              '3rdparty')
        logger.info('Creating virtualenv at %s...', venvdir)
        check_call(['python', os.path.join(pkgdir, 'virtualenv.py'),
                    '--no-site-packages',
                    '--distribute',
                    '--extra-search-dir', pkgdir,
                    '--never-download',
                    '--prompt', '(%s)' % appname,
                    venvdir])

    sitecustomize_path = os.path.join(venvdir, 'lib',
                        'python'+sys.version[:3], 'sitecustomize.py')
    if not os.path.exists(sitecustomize_path):
        logger.info("Create sitecustomize.py...")
        with open(sitecustomize_path, 'w') as f:
            f.write("""\
import os, sys, site
sdk_path = os.environ.get('SHEEP_SDK_PATH')
ignore_sdk_path = os.environ.get('SHEEP_IGN_SDKPATH')
if sdk_path and not ignore_sdk_path:
    sdk_site_dir = os.path.join(sdk_path, 'venv', 'lib', 'python'+sys.version[:3],
                    'site-packages')
    site.addsitedir(sdk_site_dir)

    approot = os.environ['SHEEP_APPROOT']
    from sheep.env import activate_app
    activate_app(approot, chdir=False)
""")

    os.environ['SHEEP_APPROOT'] = approot
    os.environ['SHEEP_IGN_SDKPATH'] = 'True'

    if not is_pip_compatible(os.path.join(venvdir, 'bin', 'pip')):
        logger.info('Installing patched pip...')
        check_call([os.path.join(venvdir, 'bin', 'pip'), 'install', '-U',
                    'hg+https://bitbucket.org/CMGS/pip'])

    if os.path.exists(os.path.join(approot, 'pip-req.txt')):
        logger.info('Installing requirements...')
        check_call([os.path.join(venvdir, 'bin', 'pip'), 'install',
                    '-r', os.path.join(approot, 'pip-req.txt'),
                    '--save-download', os.path.join(approot, 'pip-download'),
                    '--no-index',
                    '--find-links', 'file://%s/pip-download/' % approot,
                    '--fallback-index-url', 'http://pypi.python.org/simple/',
                   ])

    clear_redundant_pkgs(venvdir)

    if os.path.exists(os.path.join(approot, 'setup.py')):
        logger.info("Running python setup.py develop")
        check_call([os.path.join(venvdir, 'bin', 'python'),
                    os.path.join(approot, 'setup.py'),
                    'develop'])

    logger.info('Sync success...')
示例#12
0
def main(args):
    root_path = args.root_path or find_app_root()
    mirror_statics(root_path, server=args.server)
示例#13
0
def main(args):
    approot = os.path.abspath(args.approot or find_app_root())
    init_app(approot)
    return run_server(approot, args.port, args.pidfile, args.daemon)
示例#14
0
def main(args):
    approot = find_app_root()
    dump_requirements(approot)
示例#15
0
#!/usr/bin/python
# encoding: UTF-8

"""
static_files url replace
"""
__all__ = ['static_files', 'public_files', 'upload_files']

import os
from sheep.util import load_app_config, find_app_root

approot = os.environ.get('SHEEP_APPROOT') or find_app_root(raises=False) or ''
appconf = load_app_config(approot)

appname = appconf['application']
upload_prefix = appconf.get('upload_prefix', '')
public_prefix = appconf.get('public_prefix', '')

static_files = lambda path: path
upload_files = lambda path: os.path.join(upload_prefix, appname) + path
public_files = lambda path: public_prefix + path