Beispiel #1
0
def pull(connection, site=None):
    """
    Checkout the site(s) repository.
        fab git_pull:dev
        fab git_pull:dev,sitename
        fab appnode git_pull:prod
        fab appnode git_pull:prod,sitename
    """
    if site is None:
        sites = [site["name"] for site in settings.SITES]
    else:
        sites = [site]
    for site in sites:
        if connection == "dev":
            venv_local(git_pull_rebase(), site)
        elif connection == "prod":
            venv("git pull", site)
        else:
            print("Bad connection type. Use ``dev`` or ``prod``.")
Beispiel #2
0
def pip_requirements(connection, site=None):
    """
    Run the pip requirements file for a project, or all projects.
    Usage:
        fab appnode pip_requirements:prod,sitename
    """
    if site is None:
        sites = [site["name"] for site in settings.SITES]
    else:
        sites = [site]
    for site in sites:
        print(green("started pip install for {0}".format(site)))
        if connection == "dev":
            venv_local("pip install --upgrade pip", site)
            venv_local("pip install --quiet --requirement=requirements.txt", site)
        elif connection == "prod":
            venv("pip install --upgrade pip", site)
            venv("pip install --quiet --requirement=requirements.txt", site)
        else:
            print(red("Bad connection type. Use ``dev`` or ``prod``."))
        print(green("finished pip install for {0}".format(site)))
Beispiel #3
0
def pip_uninstall(connection, package, site=None):
    """
    Uninstall one package for a project, or all projects.
    Usage:
        fab pip_uninstall:dev,PIL,rizumu
        fab appnode pip_uninstall:prod,PIL,rizumu
    """
    if site is None:
        sites = [site["name"] for site in settings.SITES]
    else:
        sites = [site]
    for site in sites:
        try:
            if connection == "dev":
                venv_local("pip uninstall --yes {0}".format(package), site)
            elif connection == "prod":
                venv("pip uninstall --yes {0}".format(package), site)
            else:
                print(red("Bad connection type. Use ``dev`` or ``prod``."))
        except:
            print(red('Cannot uninstall requirement {0} on site {1}, not installed'.format(package, site)))
Beispiel #4
0
def staticfiles(site=None, wipe=False):
    """
    Collect, compress, and sync the static media files to rackspace.
    Usage:
        fab staticfiles:sitename
    """
    if site is None:
        sites = [site["name"] for site in settings.SITES]
    else:
        sites = [site]

    if wipe:
        wipe = "--wipe"

    for site in sites:
        if not contains("{0}{1}".format(settings.SITES_ROOT, "static.log"), site):
            print(yellow(time.ctime()))
            venv("python manage.py collectstatic --noinput --verbosity=0", site)
            venv("python manage.py compress --verbosity=0", site)
            local("fab cachenode redis_flushdb:0")
            try:
                venv("python manage.py syncstatic {0}".format(wipe), site)
            except (SSLError, CannotSendRequest):
                print(red("syncstatic failed 1 time for {0}".format(site)))
                sleep(30)
                try:
                    venv("python manage.py syncstatic {0}".format(wipe), site)
                except (SSLError, CannotSendRequest):
                    print(red("syncstatic failed 2 times for {0}".format(site)))
                    sleep(30)
                    venv("python manage.py syncstatic {0}".format(wipe), site)
            append("{0}{1}".format(settings.SITES_ROOT, "static.log"), site)
            print(green("sucessfully collected/compressed/synced staticfiles for {0}".format(site)))
            print(green(time.ctime()))
    run("rm {0}{1}".format(settings.SITES_ROOT, "static.log"))
    if len(sites) > 1:
        print(green("sucessfully collected/compressed/synced staticfiles for all sites!".format(site)))
Beispiel #5
0
def pip_install(connection, repo, package, path=None, version=None, site=None, nodeps=False):
    """
    Install one package for a project, or all projects.
    Usage:
        fab pip_install:dev,git,django-oauth-access,git://github.com/eldarion,site=rizumu
        fab appnode pip_install:prod,pypi,Django,version=1.2.3,site=rizumu
    """
    if repo in ["git", "hg", "github"]:
        if repo == "github":
            path = "git://github.com/{0}".format(path)
            repo = "git"
        fmt_egg = "{0}+{1}/{2}".format(repo, path, package)
        if version:
            fmt_egg += "@{0}".format(version)
        fmt_egg += "#egg={0}".format(package)
    elif repo == "pypi":
        fmt_egg = package
        if version:
            fmt_egg += "=={0}".format(version)
    else:
        print(red("Repo type does not exist, use git, hg, or pypi"))
        raise(NotImplementedError)
    if site is None:
        sites = [site["name"] for site in settings.SITES]
    else:
        sites = [site]
    for site in sites:
        args = ""
        if nodeps:
            args += "--no-dependencies"
        if connection == "dev":
            venv_local("pip install --ignore-installed {0} {1}".format(args, fmt_egg), site)
        elif connection == "prod":
            venv("pip install --ignore-installed {0} {1}".format(args, fmt_egg), site)
        else:
            print(red("Bad connection type. Use ``dev`` or ``prod``."))
Beispiel #6
0
def syncdb(site):
    "Call syncdb for the given site."
    venv("python manage.py syncdb --noinput".format(site), site)
Beispiel #7
0
def log(site=None):
    "show last 3 commits"
    venv("git log -3", "rizumu")