def supervisorstartup():
    """Start the supervisor daemon"""
    hostout = api.env.hostout
    path = hostout.getRemoteBuildoutPath()
    bin = "%(path)s/bin" % locals()
    supervisor = hostout.options.get('sudosupervisor') or hostout.options.get('supervisor')
    try:
        with asbuildoutuser():
            api.run("%(bin)s/%(supervisor)sctl reload"% dict(bin=bin, supervisor=supervisor))
    except:
        if hostout.options.get('sudosupervisor',None):
            with api.settings(warn_only=True):
                api.sudo("%(bin)s/%(supervisor)sctl shutdown"% dict(bin=bin, supervisor=supervisor))
            api.sudo("%(bin)s/%(supervisor)sd"% dict(bin=bin, supervisor=supervisor))
        else:

            buildout_user = hostout.options.get("buildout-user")
            effective_user = hostout.options.get("effective-user")
            if effective_user == buildout_user:
                with asbuildoutuser():
                    api.run("%(bin)s/%(supervisor)sd"% dict(bin=bin, supervisor=supervisor))
            else:
                api.sudo ("%(bin)s/%(supervisor)sd" % dict(bin=bin, supervisor=supervisor), user=effective_user)

        time.sleep(5) # give it a little chance
    
    api.env.hostout.supervisorctl('status')
def putrsync(dir):
    """ rsync a local buildout folder with the remote buildout """
    with asbuildoutuser():
        parent = '/'.join(dir.split('/')[:-1])
        remote = api.env.path + '/' + parent

        fabric.contrib.project.rsync_project(remote_dir=remote, local_dir = dir)
def bootstrap_python(extra_args=""):
    version = api.env['python-version']

    versionParsed = '.'.join(version.split('.')[:3])
    
    d = dict(version=versionParsed)
    
    prefix = api.env["python-path"]
    if not prefix:
        raise "No path for python set"
    save_path = api.env.path # the pwd may not yet exist
    api.env.path = "/"
    with cd('/'):
        runescalatable('mkdir -p %s' % prefix)
    #api.run("([-O %s])"%prefix)
    
    with asbuildoutuser():
      with cd('/tmp'):
        get_url('http://python.org/ftp/python/%(version)s/Python-%(version)s.tgz'%d)
        api.run('tar -xzf Python-%(version)s.tgz'%d)
        with cd('Python-%(version)s'%d):
#            api.run("sed 's/#readline/readline/' Modules/Setup.dist > TMPFILE && mv TMPFILE Modules/Setup.dist")
#            api.run("sed 's/#_socket/_socket/' Modules/Setup.dist > TMPFILE && mv TMPFILE Modules/Setup.dist")
            
            api.run('./configure --prefix=%(prefix)s  --enable-unicode=ucs4 --with-threads --with-readline --with-dbm --with-zlib --with-ssl --with-bz2 %(extra_args)s' % locals())
            api.run('make')
            runescalatable('make altinstall')
        api.run("rm -rf /tmp/Python-%(version)s"%d)
    api.env["system-python-use-not"] = True
    api.env.path = save_path
Beispiel #4
0
def fsrestore(filestorage="Data.fs", filestorage_dir="var/filestorage"):
    hostout = api.env.hostout
    hostout.supervisorctl("stop all")
    with api.cd(api.env.path):
        with asbuildoutuser():
            api.run('bin/repozo --recover -o %(filestorage_dir)s/%(filestorage)s -r var/backups/%(filestorage)s' % locals())
    hostout.supervisorctl("start all")
Beispiel #5
0
def fsbackup(filestorage="Data.fs", filestorage_dir="var/filestorage"):
    hostout = api.env.hostout
    db = filestorage
    with api.cd(api.env.path):
        with asbuildoutuser():
            api.run('mkdir -p var/backups/%(db)s' % locals())
            api.run('bin/repozo --backup -f %(filestorage_dir)s/%(db)s --gzip -r var/backups/%(db)s' % locals())
Beispiel #6
0
def bootstrap():
    """ Install packages and users needed to get buildout running """
    hostos = api.env.get('hostos','').lower()
    version = api.env['python-version']
    major = '.'.join(version.split('.')[:2])
    majorshort = major.replace('.','')
    d = dict(major=major)

    if not hostos:
        hostos = api.env.hostout.detecthostos().lower()
        
    cmd = getattr(api.env.hostout, 'bootstrap_users_%s'%hostos, api.env.hostout.bootstrap_users)
    cmd()

    python = 'python%(major)s' % d
    #if api.env.get("python-path"):
    pythonpath = os.path.join (api.env.get("python-path"),'bin')
    python = "PATH=\$PATH:\"%s\"; %s" % (pythonpath, python)

    try:
        with asbuildoutuser():
            #with cd(api.env["python-prefix"]+'/bin'):
                api.run(python + " -V")
    except:
        if api.env.get('force-python-compile'):
            api.env.hostout.bootstrap_python()
        else:
            cmd = getattr(api.env.hostout, 'bootstrap_python_%s'%hostos, api.env.hostout.bootstrap_python)
            cmd()

    cmd = getattr(api.env.hostout, 'bootstrap_buildout_%s'%hostos, api.env.hostout.bootstrap_buildout)
    cmd()
Beispiel #7
0
def runescalatable(*cmd):
    try:
        with asbuildoutuser():
            api.env.hostout.run(' '.join(cmd))
    except:
        try:
            api.env.hostout.run(' '.join(cmd))
        except:
            api.env.hostout.sudo(' '.join(cmd))
Beispiel #8
0
def fsrestore(filestorage="Data.fs", filestorage_dir="var/filestorage"):
    hostout = api.env.hostout
    hostout.supervisorctl("stop all")
    with api.cd(api.env.path):
        with asbuildoutuser():
            api.run(
                'bin/repozo --recover -o %(filestorage_dir)s/%(filestorage)s -r var/backups/%(filestorage)s'
                % locals())
    hostout.supervisorctl("start all")
Beispiel #9
0
def fsbackup(filestorage="Data.fs", filestorage_dir="var/filestorage"):
    hostout = api.env.hostout
    db = filestorage
    with api.cd(api.env.path):
        with asbuildoutuser():
            api.run('mkdir -p var/backups/%(db)s' % locals())
            api.run(
                'bin/repozo --backup -f %(filestorage_dir)s/%(db)s --gzip -r var/backups/%(db)s'
                % locals())
Beispiel #10
0
def runescalatable(*cmd):
    try:
        with asbuildoutuser():
            return _run(' '.join(cmd))
    except:
        try:
            return _run(' '.join(cmd))
        except:
            return _run(' '.join(cmd), run_cmd=api.sudo)
Beispiel #11
0
def fsget(filestorage="Data.fs", filestorage_dir="var/filestorage"):
    """ download a database from teh remote server and overwrite the local """
    api.env.hostout.fsbackup(filestorage, filestorage_dir)
    db = filestorage
    with api.cd(api.env.path):
        with asbuildoutuser():
            api.local("mkdir -p backups")
            api.get('var/backups/%(db)s'%locals(), 'var/backups/%(db)s'%locals())
            api.local('bin/repozo --recover -o %(filestorage_dir)s/%(db)s -r var/backups/%(filestorage)s' % locals())
Beispiel #12
0
def fsget(filestorage="Data.fs", filestorage_dir="var/filestorage"):
    """ download a database from teh remote server and overwrite the local """
    api.env.hostout.fsbackup(filestorage, filestorage_dir)
    db = filestorage
    with api.cd(api.env.path):
        with asbuildoutuser():
            api.local("mkdir -p backups")
            api.get('var/backups/%(db)s' % locals(),
                    'var/backups/%(db)s' % locals())
            api.local(
                'bin/repozo --recover -o %(filestorage_dir)s/%(db)s -r var/backups/%(filestorage)s'
                % locals())
Beispiel #13
0
def bootstrap_buildout():
    """ Create an initialised buildout directory """
    # bootstrap assumes that correct python is already installed


    # First ensure all needed directories are created and have right permissions
    path = api.env.path
    buildout = api.env['buildout-user']
    buildoutgroup = api.env['buildout-group']
    # create buildout dir
    api.sudo('mkdir -p -m ug+x %(path)s && chown %(buildout)s:%(buildoutgroup)s %(path)s' % dict(
        path=path,
        buildout=buildout,
        buildoutgroup=buildoutgroup,
    ))
    # ensure buildout user and group and cd in (ug+x)
    parts = path.split('/')
    for i in range(2, len(parts)):
        api.sudo('chmod ug+x %s' % '/'.join(parts[:i]) )



    buildoutcache = api.env['buildout-cache']
    api.sudo('mkdir -p %s/eggs' % buildoutcache)
    api.sudo('mkdir -p %s/downloads/dist' % buildoutcache)
    api.sudo('mkdir -p %s/extends' % buildoutcache)
    api.sudo('chown -R %s:%s %s' % (buildout, buildoutgroup, buildoutcache))
    api.env.hostout.setowners()

#    api.run('mkdir -p %s/eggs' % buildoutcache)
#    api.run('mkdir -p %s/downloads/dist' % buildoutcache)
#    api.run('mkdir -p %s/extends' % buildoutcache)
    #api.run('chown -R %s:%s %s' % (buildout, buildoutgroup, buildoutcache))

    with asbuildoutuser():
        bootstrap = resource_filename(__name__, 'bootstrap.py')
        with cd(path):
            api.put(bootstrap, '%s/bootstrap.py' % path)

            # put in simplest buildout to get bootstrap to run
            api.run('echo "[buildout]" > buildout.cfg')

            python = api.env.get('python')
            if not python or python == 'buildout':

                version = api.env['python-version']
                major = '.'.join(version.split('.')[:2])
                python = "python%s" % major

            api.run('%s bootstrap.py --distribute' % python)
Beispiel #14
0
def setowners():
    """ Ensure ownership and permissions are correct on buildout and cache """
    hostout = api.env.get('hostout')
    buildout = api.env['buildout-user']
    effective = api.env['effective-user']
    buildoutgroup = api.env['buildout-group']
    owner = buildout


    path = api.env.path
    bc = hostout.buildout_cache
    dl = hostout.getDownloadCache()
    dist = os.path.join(dl, 'dist')
    ec = hostout.getEggCache()
    var = os.path.join(path, 'var')
    
    # What we want is for - login user to own the buildout and the cache.  -
    # effective user to be own the var dir + able to read buildout and cache.
    
    api.env.hostout.runescalatable ("find %(path)s  -maxdepth 1 -mindepth 1 ! -name var -exec chown -R %(buildout)s:%(buildoutgroup)s '{}' \; " \
             " -exec chmod -R u+rw,g+r-w,o-rw '{}' \;" % locals())

    # command to set any +x file to also be +x for the group too. runzope and zopectl are examples
    if effective == buildout:
        with asbuildoutuser():
            api.run("find %(path)s -perm -u+x ! -path %(var)s -exec chmod g+x '{}' \;" % dict(path=path,var=var))
    else:
        api.sudo("find %(path)s -perm -u+x ! -path %(var)s -exec chmod g+x '{}' \;" % dict(path=path,var=var))


    api.env.hostout.runescalatable ('mkdir -p %(var)s' % locals())
#    api.run('mkdir -p %(var)s' % dict(var=var))

    if effective != buildout:
        try:
            api.sudo (\
                    '[ `stat -c %%U:%%G %(var)s` = "%(effective)s:%(buildoutgroup)s" ] || ' \
                    'chown -R %(effective)s:%(buildoutgroup)s %(var)s ' % locals())
            api.sudo ( '[ `stat -c %%A %(var)s` = "drwxrws--x" ] || chmod -R u+rw,g+wrs,o-rw %(var)s ' % locals())
        except:
            pass
            #raise Exception ("Was not able to set owner and permissions on "\
            #            "%(var)s to %(effective)s:%(buildoutgroup)s with u+rw,g+wrs,o-rw" % locals() )
        

#    api.sudo("chmod g+x `find %(path)s -perm -g-x` || find %(path)s -perm -g-x -exec chmod g+x '{}' \;" % locals()) #so effective can execute code
#    api.sudo("chmod g+s `find %(path)s -type d` || find %(path)s -type d -exec chmod g+s '{}' \;" % locals()) # so new files will keep same group
#    api.sudo("chmod g+s `find %(path)s -type d` || find %(path)s -type d -exec chmod g+s '{}' \;" % locals()) # so new files will keep same group
    
    api.env.hostout.runescalatable('mkdir -p %s %s/dist %s' % (bc, dl, ec))
Beispiel #15
0
def blobcopy(tgt, blobstorage="blobstorage"):
    "Copy blobstorage to tgt buildout (must be on the same machine)"
    target = api.env.hostout.hostouts[tgt]
    towner = target.options['buildout-user']
    e = dict(blobstorage=blobstorage, towner=towner)

    # Assumes we're on the same machine for this to work
    assert target.options['host'] == api.env.hostout.options['host']

    with api.cd(api.env.path):
        with asbuildoutuser():
            api.run("cp -R var/%(blobstorage)s /tmp" % e)
            api.run("chown -R %(towner)s /tmp/%(blobstorage)s" % e)

    target.supervisorctl("stop all")
    target.run("cp -fR /tmp/%(blobstorage)s var/" % e )
    target.run("rm -Rf /tmp/%(blobstorage)s " % e )
    target.supervisorctl("start all")
Beispiel #16
0
def blobcopy(tgt, blobstorage="blobstorage"):
    "Copy blobstorage to tgt buildout (must be on the same machine)"
    target = api.env.hostout.hostouts[tgt]
    towner = target.options['buildout-user']
    e = dict(blobstorage=blobstorage, towner=towner)

    # Assumes we're on the same machine for this to work
    assert target.options['host'] == api.env.hostout.options['host']

    with api.cd(api.env.path):
        with asbuildoutuser():
            api.run("cp -R var/%(blobstorage)s /tmp" % e)
            api.run("chown -R %(towner)s /tmp/%(blobstorage)s" % e)

    target.supervisorctl("stop all")
    target.run("cp -fR /tmp/%(blobstorage)s var/" % e)
    target.run("rm -Rf /tmp/%(blobstorage)s " % e)
    target.supervisorctl("start all")
Beispiel #17
0
def fscopy(tgt, filestorage="Data.fs", filestorage_dir="var/filestorage"):
    "Move the Data.fs to tgt (must be on the same machine)"
    target = api.env.hostout.hostouts[tgt]
    towner = target.options['buildout-user']
    e = dict(filestorage=filestorage, towner=towner)

    # Assumes we're on the same machine for this to work
    assert target.options['host'] == api.env.hostout.options['host']

    api.env.hostout.fsbackup(filestorage, filestorage_dir)
    with api.cd(api.env.path):
        with asbuildoutuser():
            backup = "var/backups/%(filestorage)s" % e
            api.run("cp -R %(backup)s /tmp" % dict(backup=backup))
            api.run("chown -R %(towner)s /tmp/%(filestorage)s" % e)

    target.run("cp -fR /tmp/%(filestorage)s var/backups/%(filestorage)s" % e )
    target.run("rm -Rf /tmp/%(filestorage)s " % e )
    target.fsrestore(filestorage, filestorage_dir)
Beispiel #18
0
def fscopy(tgt, filestorage="Data.fs", filestorage_dir="var/filestorage"):
    "Move the Data.fs to tgt (must be on the same machine)"
    target = api.env.hostout.hostouts[tgt]
    towner = target.options['buildout-user']
    e = dict(filestorage=filestorage, towner=towner)

    # Assumes we're on the same machine for this to work
    assert target.options['host'] == api.env.hostout.options['host']

    api.env.hostout.fsbackup(filestorage, filestorage_dir)
    with api.cd(api.env.path):
        with asbuildoutuser():
            backup = "var/backups/%(filestorage)s" % e
            api.run("cp -R %(backup)s /tmp" % dict(backup=backup))
            api.run("chown -R %(towner)s /tmp/%(filestorage)s" % e)

    target.run("cp -fR /tmp/%(filestorage)s var/backups/%(filestorage)s" % e)
    target.run("rm -Rf /tmp/%(filestorage)s " % e)
    target.fsrestore(filestorage, filestorage_dir)
Beispiel #19
0
def put(file, target=None):
    """Recursively upload specified files into the remote buildout folder"""
    if os.path.isdir(file):
        uploads = os.walk(file)
    else:
        uploads = None, None, [file]
    with asbuildoutuser():
        for root, dirs, files in uploads:
            for dir in dirs:
                with cd(api.env.path):
                    api.run('mkdir -p %s'% root +'/'+ dir)
            for file in files:
                file = root + '/' + file
                print file
                if not target:
                    target = file
                if target[0] != '/':
                    target = api.env.path + '/' + target
                api.put(file, target)
def put(file, target=None):
    """Recursively upload specified files into the remote buildout folder"""
    if os.path.isdir(file):
        uploads = os.walk(file)
    else:
        path = file.split("/")
        uploads = [("/".join(path[:-1]), [], [path[-1]])]
    with asbuildoutuser():
        for root, dirs, files in uploads:
            for dir in dirs:
                with cd(api.env.path):
                    api.run("mkdir -p %s" % root + "/" + dir)
            for file in files:
                file = root + "/" + file
                print file
                if not target:
                    target = file
                if target[0] != "/":
                    target = api.env.path + "/" + target
                api.put(file, target)
Beispiel #21
0
def put(path, target=None):
    """Recursively upload specified files into the remote buildout folder"""
    if os.path.isdir(path):
        uploads = os.walk(path)
    else:
        path = path.split('/')
        uploads = [('/'.join(path[:-1]), [], [path[-1]])]
    with asbuildoutuser():
        for root, dirs, files in uploads:
            for dir_name in dirs:
                with cd(api.env.path):
                    api.run('mkdir -p %s' % root + '/' + dir_name)
            for file_name in files:
                file_path = root + '/' + file_name
                print file_path
                if not target:
                    target = file_path
                if target[0] != '/':
                    target = api.env.path + '/' + target
                api.put(file_path, target)
Beispiel #22
0
def predeploy():
    """Perform any initial plugin tasks. Call bootstrap if needed"""

    hasBuildoutUser = True
    hasBuildout = True
    if not (api.env.get("buildout-password") or os.path.exists(api.env.get('identity-file'))):
        hasBuildoutUser = False
    else:
        with asbuildoutuser():
            try:
                api.run("[ -e %s/bin/buildout ]"%api.env.path, pty=True)
            except:
                hasBuildout = False
    
    if not hasBuildoutUser or not hasBuildout:
        raise Exception ("Target deployment does not seem to have been bootstraped.")

    api.env.hostout.precommands()

    return api.env.superfun()
Beispiel #23
0
def predeploy():
    """Perform any initial plugin tasks. Call bootstrap if needed"""

    hasBuildoutUser = True
    hasBuildout = True
    if not os.path.exists(api.env.get('identity-file')):
        hasBuildoutUser = False
    else:
        with asbuildoutuser():
            try:
                api.run("[ -e %s/bin/buildout ]"%api.env.path, pty=True)
            except:
                hasBuildout = False
    
    if not hasBuildoutUser or not hasBuildout:
        api.env.hostout.bootstrap()
        api.env.hostout.setowners()

    api.env.hostout.precommands()

    return api.env.superfun()
Beispiel #24
0
def hotfix(url,products_dir='products'):
    """ Takes a url and will deploy that to your products directory. Don't forget to restart after """
    with api.cd('%s/%s'%(api.env.path,products_dir)):
        with asbuildoutuser():
            #api.run("curl %s /tmp/hotfix.zip"%url)
            #api.run("python -c \"import urllib; f=open('/tmp/hotfix.zip','w'); f.write(urllib.urlopen('%s').read()); f.close()\""%url)
            filename = os.path.basename(url)
            tmp = '/tmp/%s'%filename
            if not os.path.exists(tmp):
                f=open(tmp,'w')
                f.write(urllib.urlopen(url).read())
                f.close()
            api.put(tmp, tmp)
            try:
                api.run("unzip -o %s"%tmp)
            except:
                api.run("""python -c "import zipfile;import urllib;import StringIO; zipfile.ZipFile(StringIO.StringIO(urllib.urlopen('%s').read())).extractall()" """%url)

            group = api.env['buildout-group']
            api.run("chgrp -R %s ."%(group))
            api.run('rm %s'%tmp)
def bootstrap():
    """ Install packages and users needed to get buildout running """
    hostos = api.env.get("hostos", "").lower()
    version = api.env["python-version"]
    major = ".".join(version.split(".")[:2])
    majorshort = major.replace(".", "")
    d = dict(major=major)

    if not hostos:
        hostos = api.env.hostout.detecthostos().lower()

    cmd = getattr(api.env.hostout, "bootstrap_users_%s" % hostos, api.env.hostout.bootstrap_users)
    cmd()

    python = "python%(major)s" % d
    # if api.env.get("python-path"):
    pythonpath = os.path.join(api.env.get("python-path"), "bin")
    python = 'PATH=\$PATH:"%s"; %s' % (pythonpath, python)

    try:
        with asbuildoutuser():
            # with cd(api.env["python-prefix"]+'/bin'):
            api.run(python + " -V")
    except:
        if api.env.get("force-python-compile"):
            api.env.hostout.bootstrap_python_buildout()
        else:
            try:
                cmd = getattr(api.env.hostout, "bootstrap_python_%s" % hostos, api.env.hostout.bootstrap_python)
            except:
                cmd = api.env.hostout.bootstrap_python_buildout

            cmd()

    if api.env.get("force-python-compile"):
        api.env.hostout.bootstrap_buildout()
    else:
        cmd = getattr(api.env.hostout, "bootstrap_buildout_%s" % hostos, api.env.hostout.bootstrap_buildout)
        cmd()
Beispiel #26
0
def hotfix(url, products_dir='products'):
    """ Takes a url and will deploy that to your products directory. Don't forget to restart after """
    with api.cd('%s/%s' % (api.env.path, products_dir)):
        with asbuildoutuser():
            #api.run("curl %s /tmp/hotfix.zip"%url)
            #api.run("python -c \"import urllib; f=open('/tmp/hotfix.zip','w'); f.write(urllib.urlopen('%s').read()); f.close()\""%url)
            filename = os.path.basename(url)
            tmp = '/tmp/%s' % filename
            if not os.path.exists(tmp):
                f = open(tmp, 'w')
                f.write(urllib.urlopen(url).read())
                f.close()
            api.put(tmp, tmp)
            try:
                api.run("unzip -o %s" % tmp)
            except:
                api.run(
                    """python -c "import zipfile;import urllib;import StringIO; zipfile.ZipFile(StringIO.StringIO(urllib.urlopen('%s').read())).extractall()" """
                    % url)

            group = api.env['buildout-group']
            api.run("chgrp -R %s ." % (group))
            api.run('rm %s' % tmp)
Beispiel #27
0
def bootstrap_python_buildout():
    "Install python from source via buildout"
    
    #TODO: need a better way to install from source that doesn't need svn or python
    
    path = api.env.path

    BUILDOUT = """
[buildout]
extends =
      src/base.cfg
      src/readline.cfg
      src/libjpeg.cfg
      src/python%(majorshort)s.cfg
      src/links.cfg

parts =
      ${buildout:base-parts}
      ${buildout:readline-parts}
      ${buildout:libjpeg-parts}
      ${buildout:python%(majorshort)s-parts}
      ${buildout:links-parts}

# ucs4 is needed as lots of eggs like lxml are also compiled with ucs4 since most linux distros compile with this      
[python-%(major)s-build:default]
extra_options +=
    --enable-unicode=ucs4
    --with-threads
    --with-readline
    --with-dbm
    --with-zlib
    --with-ssl
    --with-bz2
patch = %(patch_file)s

[install-links]
prefix = ${buildout:directory}

[versions]
zc.buildout = 1.4.3

"""

    patch = r"""
--- Modules/Setup.dist	2005-12-28 04:37:16.000000000 +1100
+++ Modules/Setup.dist	2012-05-23 23:31:22.000000000 +1000
@@ -198,14 +198,14 @@
 #_csv _csv.c

 # Socket module helper for socket(2)
-#_socket socketmodule.c
+_socket socketmodule.c

 # Socket module helper for SSL support; you must comment out the other
 # socket line above, and possibly edit the SSL variable:
-#SSL=/usr/local/ssl
-#_ssl _ssl.c \\
-#	-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \\
-#	-L$(SSL)/lib -lssl -lcrypto
+SSL=/usr/lib/ssl
+_ssl _ssl.c \\
+	-DUSE_SSL -I/usr/include/openssl \\
+	-L/usr/lib/ssl -lssl -lcrypto

 # The crypt module is now disabled by default because it breaks builds
 # on many systems (where -lcrypt is needed), e.g. Linux (I believe).
"""

    hostout = api.env.hostout
    hostout = api.env.get('hostout')
    sudouser = api.env.get('user')
    buildout = api.env['buildout-user']
    effective = api.env['effective-user']
    buildoutgroup = api.env['buildout-group']

    #hostout.setupusers()
#    api.sudo('mkdir -p %(path)s' % locals())
#    hostout.setowners()

    version = api.env['python-version']
    major = '.'.join(version.split('.')[:2])
    majorshort = major.replace('.','')

    prefix = api.env["python-path"]
    if not prefix:
        raise "No path for python set"
    save_path = api.env.path # the pwd may not yet exist
    api.env.path = "/"
    with cd('/'):
        if buildout != sudouser:
            sudo('mkdir -p %s' % prefix)
            sudo('chown %s:%s %s'%(buildout,buildoutgroup,prefix))
        else:
            run('mkdir -p %s' % prefix)
            run('chown %s:%s %s'%(buildout,buildoutgroup,prefix))



    with asbuildoutuser():
      #TODO: bug in fabric. seems like we need to run this command first before cd will work
      hostos = api.env.hostout.detecthostos().lower()
      with cd(prefix):
        api.run('test -f collective-buildout.python.tar.gz || wget http://github.com/collective/buildout.python/tarball/master -O collective-buildout.python.tar.gz --no-check-certificate')
        api.run('tar --strip-components=1 -zxvf collective-buildout.python.tar.gz')

        #api.sudo('svn co http://svn.plone.org/svn/collective/buildout/python/')
        #get_url('http://python-distribute.org/distribute_setup.py',  api.sudo)
        #api.run('%s python distribute_setup.py'% proxy_cmd())
        # -v due to https://github.com/collective/buildout.python/issues/11
        api.run('%s python bootstrap.py --distribute -v 1.4.3' % proxy_cmd())

        if hostos == 'ubuntu' and major=='2.4':
            patch_file = '${buildout:directory}/ubuntussl.patch'
            api.run('rm -f ubuntussl.patch')
            fabric.contrib.files.append('ubuntussl.patch', patch, use_sudo=False,escape=True)
        else:
            patch_file = ''

        fabric.contrib.files.append('buildout.cfg', BUILDOUT%locals(), use_sudo=False)
        api.run('%s bin/buildout -N'%proxy_cmd())
        #api.env['python'] = "source /var/buildout-python/python/python-%(major)s/bin/activate; python "
        #api.run('%s bin/install-links'%proxy_cmd())
        api.run("bin/virtualenv-%(major)s ."%dict(major=major))
        #api.env['python-path'] = "/var/buildout-python/python-%(major)s" %dict(major=major)
        api.env["system-python-use-not"] = True
Beispiel #28
0
def bootstrap_buildout():
    """ Create an initialised buildout directory """
    # bootstrap assumes that correct python is already installed


    # First ensure all needed directories are created and have right permissions
    path = api.env.path
    buildout = api.env['buildout-user']
    buildoutgroup = api.env['buildout-group']
    # create buildout dir

    if path[0] == "/":
        save_path = api.env.path # the pwd may not yet exist
        api.env.path = "/"

    api.env.hostout.runescalatable ('mkdir -p -m ug+x %(path)s' % dict(
        path=path,
        buildout=buildout,
        buildoutgroup=buildoutgroup,
    ))

    if path[0] == "/":
        api.env.path = save_path # restore the pwd

    api.env.hostout.requireOwnership (path, user=buildout, group=buildoutgroup, recursive=True)

    # ensure buildout user and group and cd in (ug+x)
    parts = path.split('/')
    for i in range(2, len(parts)):
        try:
            api.env.hostout.runescalatable('test -x %(p)s || chmod ug+x %(p)s' % dict(p='/'.join(parts[:i])) )
        except:
            print sys.stderr, "Warning: Not able to chmod ug+x on dir " + os.path.join(*parts[:i])


    buildoutcache = api.env['buildout-cache']
    api.env.hostout.runescalatable ('mkdir -p %s' % os.path.join(buildoutcache, "eggs"))
    api.env.hostout.runescalatable ('mkdir -p %s' % os.path.join(buildoutcache, "download/dist"))
    api.env.hostout.runescalatable ('mkdir -p %s' % os.path.join(buildoutcache, "extends"))

    api.env.hostout.requireOwnership (buildoutcache, user=buildout, recursive=True)


    api.env.hostout.setowners()

#    api.run('mkdir -p %s/eggs' % buildoutcache)
#    api.run('mkdir -p %s/downloads/dist' % buildoutcache)
#    api.run('mkdir -p %s/extends' % buildoutcache)
    #api.run('chown -R %s:%s %s' % (buildout, buildoutgroup, buildoutcache))

    with asbuildoutuser():
        bootstrap = resource_filename(__name__, 'bootstrap.py')
        with cd(path):
            api.put(bootstrap, '%s/bootstrap.py' % path)

            # put in simplest buildout to get bootstrap to run
            api.run('echo "[buildout]" > buildout.cfg')

            # Get python
            version = api.env['python-version']
            major = '.'.join(version.split('.')[:2])
            python = 'python%s' % major
            #if api.env.get("python-path"):
            pythonpath = os.path.join (api.env.get("python-path"),'bin')
            # try to activate virtualenv if it exists
            #api.run("%(pythonpath)s/virtualenv-%(major)s %(path)s"%dict(pythonpath=pythonpath,major=major,path=path))
            #python += "source /var/buildout-python/python/python-%(major)s/bin/activate; python "

            #python = "PATH=\$PATH:\"%s\"; %s" % (pythonpath, python)
            versions = api.env.hostout.getVersions()
            buildout_version = versions.get('zc.buildout','1.4.3')

            # Bootstrap baby!
            #try:
            with fabric.context_managers.path(pythonpath,behavior='prepend'):
                api.run('%s %s bootstrap.py --distribute -v %s' % (proxy_cmd(), python, buildout_version) )
Beispiel #29
0
def bootstrap_buildout():
    """ Create an initialised buildout directory """
    # bootstrap assumes that correct python is already installed


    # First ensure all needed directories are created and have right permissions
    path = api.env.path
    buildout = api.env['buildout-user']
    buildoutgroup = api.env['buildout-group']
    # create buildout dir
    api.env.hostout.runescalatable ('mkdir -p -m ug+x %(path)s && chown %(buildout)s:%(buildoutgroup)s %(path)s' % dict(
        path=path,
        buildout=buildout,
        buildoutgroup=buildoutgroup,
    ))
    # ensure buildout user and group and cd in (ug+x)
    parts = path.split('/')
    for i in range(2, len(parts)):
        try:
            api.env.hostout.runescalatable('chmod ug+x %s' % '/'.join(parts[:i]) )
        except:
            print sys.stderr, "Warning: Not able to chmod ug+x on dir " + os.path.join(*parts[:i])




    buildoutcache = api.env['buildout-cache']
    api.env.hostout.runescalatable ('mkdir -p %s/eggs' % buildoutcache)
    api.env.hostout.runescalatable ('mkdir -p %s/downloads/dist' % buildoutcache)
    api.env.hostout.runescalatable ('mkdir -p %s/extends' % buildoutcache)

    try:
        api.env.hostout.runescalatable ('chown -R %s:%s %s' % (buildout, buildoutgroup, buildoutcache))
    except:
        print sys.stderr, "Warning: Not able to chown on the buildout cache dir"

    api.env.hostout.setowners()

#    api.run('mkdir -p %s/eggs' % buildoutcache)
#    api.run('mkdir -p %s/downloads/dist' % buildoutcache)
#    api.run('mkdir -p %s/extends' % buildoutcache)
    #api.run('chown -R %s:%s %s' % (buildout, buildoutgroup, buildoutcache))

    with asbuildoutuser():
        bootstrap = resource_filename(__name__, 'bootstrap.py')
        with cd(path):
            api.put(bootstrap, '%s/bootstrap.py' % path)

            # put in simplest buildout to get bootstrap to run
            api.run('echo "[buildout]" > buildout.cfg')

            # Get python
            version = api.env['python-version']
            major = '.'.join(version.split('.')[:2])
            python = 'python%s' % major

            # Bootstrap baby!
            try:
                api.run('%s %s bootstrap.py --distribute' % (proxy_cmd(), python) )
            except:
                python = os.path.join (api.env["python-prefix"], "bin/", python)
                api.run('%s %s bootstrap.py --distribute' % (proxy_cmd(), python) )
Beispiel #30
0
def run(*cmd):
    """Execute cmd on remote as login user """

    with asbuildoutuser():
        return _run(' '.join(cmd), run_cmd=api.run)