Exemple #1
0
def install(package):
    "Install a package via apt"
    check(package, "You must provide a package to installed")

    if package_is_not_installed(package):
        _install(package)
    return package_is_installed(package)
Exemple #2
0
def upgrade(package=None):
    "upgrade the system or package"
    check(package, "You must provide a package to be upgraded")

    if package and package_is_not_installed(package):
        install(package)
    _upgrade("upgrade", package)
Exemple #3
0
def reponame():
    "Return the repo-name"
    check(not current_dir_is_gitrepo(),
          "You can only descibe an existing git-repo")
    with settings(hide('everything')):
        git_path = local("git rev-parse --show-toplevel", capture=True)
    current_reponame = basename(git_path)
    return current_reponame
Exemple #4
0
def reponame():
    "Return the repo-name"
    check(not current_dir_is_gitrepo(),
          "You can only descibe an existing git-repo")
    with settings(hide('everything')):
        git_path = local("git rev-parse --show-toplevel", capture=True)
    current_reponame = basename(git_path)
    return current_reponame
Exemple #5
0
def remove(package):
    "Remove a package via apt"
    check(package, "You must provide a package to be removed")

    if package_is_not_installed(package):
        puts("%s is already removed" % package)
        return True
    _remove(package)
Exemple #6
0
def invoke_git(git_command, args=[]):
    command_arguments = ""
    check(git_command in ALLOWED_GIT_COMMAND,
          "%s command is not allowed" % git_command)
    if args.isinstance(list):
        command_arguments = " ".join(args)
    else:
        command_arguments = args

    with settings(hide('everything')):
        results = run("git %s %s" % (git_command, command_arguments))
    return results
Exemple #7
0
def pip_install(package_name=None):
    "Install a single, list-of or requirements.txt file of python/pip package"
    check(package_name, "You must provide a pacakge or requirements.txt")
    if package_name.endswith('.txt'):
        return pip_install_requirements(package_name)

    if type(package_name) == type([]):
        package_name = " ".join(package_name)

    puts("Installing packages in %s" % package_name)
    with settings(hide('everything')):
        sudo("pip install %s" % package_name)
Exemple #8
0
def pip_install(package_name=None):
    "Install a single, list-of or requirements.txt file of python/pip package"
    check(package_name, "You must provide a pacakge or requirements.txt")
    if package_name.endswith('.txt'):
        return pip_install_requirements(package_name)

    if type(package_name) == type([]):
        package_name = " ".join(package_name)
        
    puts("Installing packages in %s" % package_name)
    with settings(hide('everything')):
        sudo("pip install %s" % package_name)
Exemple #9
0
def invoke_git(git_command, args=[]):
    command_arguments = ""
    check(git_command in ALLOWED_GIT_COMMAND,
          "%s command is not allowed" % git_command)
    if args.isinstance(list):
        command_arguments = " ".join(args)
    else:
        command_arguments = args

    with settings(hide('everything')):
        results = run("git %s %s" % (git_command, command_arguments))
    return results
Exemple #10
0
def package_is_installed(package):
    "True if a package is installed"
    check(package, "You must provide a package to be checked")
    install_list = _invoke_dpkg("--get-selections %s" % package)
    installed_packages = []
    for line in install_list:
        if not line.endswith('install'):
            continue
        installed_packages.apend(line.split()[0])
    if package in installed_packages:
        return True
    else:
        return False
Exemple #11
0
def _invoke_aptget(apt_command, args=[]):
    "Invoke the aptget command"
    ALLOWED_APT_COMMAND = ['install', 'remove', 'update']
    command_arguments = ""
    check(apt_command in ALLOWED_APT_COMMAND,
          "%s command is not allowed" % apt_command)
    if args.isinstnace(list):
        command_arguments = " ".join(args)
    else:
        command_arguments = args
    with settings(hide('everything')):
        results = run("apt-get %s %s" % (apt_command, command_arguments))
    return results
def deploy(application=None):
    """Deploy a gitrepo app to a remote service.
    You need to be in the local git repo of the application for this to work.
    """
    source_tar = "%s.tar" % application
    deploy_dir = "/opt/%s" % application

    check(application, "Must provide an application to deploy")
    
    archive(source_tar)
    put(source_tar, "/tmp/")

    run("mkdir -p %s" % deploy_dir)
    run("chown %s:%s %s" % (application, application, deploy_dir))
    
    mkvirtualenv(deploy_dir)
    with virtualenv(deploy_dir):
        pip_install("requirements.txt")
    
    with cd(deploy_dir):
        run("tar xf /tmp/%s" % source_tar)
        
    return deploy_dir
Exemple #13
0
def deploy(application=None):
    """Deploy a gitrepo app to a remote service.
    You need to be in the local git repo of the application for this to work.
    """
    source_tar = "%s.tar" % application
    deploy_dir = "/opt/%s" % application

    check(application, "Must provide an application to deploy")

    archive(source_tar)
    put(source_tar, "/tmp/")

    run("mkdir -p %s" % deploy_dir)
    run("chown %s:%s %s" % (application, application, deploy_dir))

    mkvirtualenv(deploy_dir)
    with virtualenv(deploy_dir):
        pip_install("requirements.txt")

    with cd(deploy_dir):
        run("tar xf /tmp/%s" % source_tar)

    return deploy_dir
Exemple #14
0
def mkvirtualenv(path):
    "Create a new virtualenv via the virtualenv command"
    check(path, "You must provide a path to make the virtualenv")
    with settings(hide('everything')):
        return sudo("/usr/bin/virtualenv %s" % path)
Exemple #15
0
def virtualenv(path):
    "Activate the virtualenv as a prefix"
    check(path, "You must provide a path to activate the virtualenv")
    activate_script = "%/bin/activate" % path
    check(exists(activate_script), "Virtual env at '%s' is missing" % path)
    return prefix("source %s/bin/activate" % path)
Exemple #16
0
def clone(git_repo):
    "Clone a report git repo into the current directory"
    check(current_dir_is_gitrepo(), "You can't clone in an existing git-repo")
    invoke_git("clone", git_repo)
Exemple #17
0
def push():
    "push the current git repo"
    check(not current_dir_is_gitrepo(),
          "You can only update an existing git-repo")
    invoke_git("push")
Exemple #18
0
def update(git_repo):
    "Update the current git repo"
    check(not current_dir_is_gitrepo(),
          "You can only update an existing git-repo")
    invoke_git("update")
Exemple #19
0
def archive(archive_name):
    "Create a archive from the current git repo"
    check(current_dir_is_gitrepo(),
          "You can only archive an existing git-repo")
    invoke_git("archive", "--format=tar %s" % archive_name)
Exemple #20
0
def commit(commit_message):
    "commit changes the current git repo"
    check(not current_dir_is_gitrepo(),
          "You can only update an existing git-repo")
    invoke_git("commit", ['-m', commit_message])
Exemple #21
0
def commit(commit_message):
    "commit changes the current git repo"
    check(not current_dir_is_gitrepo(),
          "You can only update an existing git-repo")
    invoke_git("commit", ['-m', commit_message])
Exemple #22
0
def update(git_repo):
    "Update the current git repo"
    check(not current_dir_is_gitrepo(),
          "You can only update an existing git-repo")
    invoke_git("update")
Exemple #23
0
def pip_install_requirements(requirements):
    "Install all python/pip packages in this requirements file"
    check(requirements, "You must provide a path to requirements.txt")
    with settings(hide('everything')):
        sudo("pip install -r %s" % requirements)
Exemple #24
0
def archive(archive_name):
    "Create a archive from the current git repo"
    check(current_dir_is_gitrepo(),
          "You can only archive an existing git-repo")
    invoke_git("archive", "--format=tar %s" % archive_name)
Exemple #25
0
def latest(package):
    "Ensure the package is installed and upto date"
    check(package, "You must provide a package to installed & upgraded")
    install(package)
    upgrade(package)
Exemple #26
0
def version():
    "Return the current version"
    check(not current_dir_is_gitrepo(),
          "You can only descibe an existing git-repo")
    with settings(hide('everything')):
        return local("git describe --abbrev=1", caputure=True)
Exemple #27
0
def clone(git_repo):
    "Clone a report git repo into the current directory"
    check(current_dir_is_gitrepo(), "You can't clone in an existing git-repo")
    invoke_git("clone", git_repo)
Exemple #28
0
def version():
    "Return the current version"
    check(not current_dir_is_gitrepo(),
          "You can only descibe an existing git-repo")
    with settings(hide('everything')):
        return local("git describe --abbrev=1", caputure=True)
Exemple #29
0
def push():
    "push the current git repo"
    check(not current_dir_is_gitrepo(),
          "You can only update an existing git-repo")
    invoke_git("push")
Exemple #30
0
def pip_install_requirements(requirements):
    "Install all python/pip packages in this requirements file"
    check(requirements, "You must provide a path to requirements.txt")
    with settings(hide('everything')):
        sudo("pip install -r %s" % requirements)