Example #1
0
def push_modifications(root_path):
    scm = get_vcs(root_path)
    if scm == 'hg':
        push_hg_modifications(root_path)
    elif scm == 'svn':
        push_svn_modifications(root_path)
    elif scm == 'git':
        push_git_modifications(root_path)
Example #2
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...')