Did I find the right examples for you? yes no

All Samples(102)  |  Call(84)  |  Derive(0)  |  Import(18)
Subprocess wrapper for running commands 

        def run(command, display=True, err_codes=[0], silent=True):
    """ Subprocess wrapper for running commands """
    if display:
        sys.stderr.write("\n\033[1m $ %s\033[0m\n" % command)
    out_stream = subprocess.PIPE
    err_stream = subprocess.PIPE
    
    p = subprocess.Popen(command, shell=True, executable='/bin/bash', stdout=out_stream, stderr=err_stream)
    make_async(p.stdout)
    make_async(p.stderr)
    
    stdout = str()
    stderr = str()
    
    # Async reading of stdout and sterr
    while True:
        # Wait for data to become available 
        select.select([p.stdout, p.stderr], [], [])
        
        # Try reading some data from each
        stdoutPiece = read_async(p.stdout)
        stderrPiece = read_async(p.stderr)
        
        if display and stdoutPiece:
            sys.stdout.write(stdoutPiece)
        if display and stderrPiece:
            sys.stderr.write(stderrPiece)
        
        stdout += stdoutPiece
        stderr += stderrPiece
        returnCode = p.poll()
        
        if returnCode != None:
            break
    
    out = _AttributeString(stdout.strip())
    err = _AttributeString(stderr.strip())
    p.stdout.close()
    p.stderr.close()
    
    out.failed = False
    out.return_code = returnCode
    out.stderr = err
    if p.returncode not in err_codes:
        out.failed = True
        msg = "\nrun() encountered an error (return code %s) while executing '%s'\n" % (p.returncode, command)
        sys.stderr.write("\n\033[1;31mCommandError: %s %s\033[m\n" % (msg, err))
        if not silent:
            raise CommandError("\n%s\n %s\n" % (msg, err))
    
    out.succeeded = not out.failed
    return out
        


src/c/o/confine-controller-0.10.5/controller/management/commands/setuppostgres.py   confine-controller(Download)
 
from controller.utils.paths import get_project_root
from controller.utils.system import run, check_root
 
 
            'db_port': options.get('db_port') }
 
        run('su postgres -c "psql -c \\"CREATE USER %(db_user)s PASSWORD \'%(db_password)s\';\\""' % context, err_codes=[0,1])
        run('su postgres -c "psql -c \\"CREATE DATABASE %(db_name)s OWNER %(db_user)s;\\""' % context, err_codes=[0,1])
 
        context.update({'settings': os.path.join(get_project_root(), 'settings.py')})
 
        if run("grep 'DATABASES' %(settings)s" % context, err_codes=[0,1]).return_code == 0:
            # Update existing settings_file
            run("sed -i \"s/'ENGINE': '\w*',/'ENGINE': 'django.db.backends.postgresql_psycopg2',/\" %(settings)s" % context)
            # Update existing settings_file
            run("sed -i \"s/'ENGINE': '\w*',/'ENGINE': 'django.db.backends.postgresql_psycopg2',/\" %(settings)s" % context)
            run("sed -i \"s/'NAME': '.*',/'NAME': '%(db_name)s',/\" %(settings)s" % context)
            run("sed -i \"s/'USER': '.*',/'USER': '%(db_user)s',/\" %(settings)s" % context)
            run("sed -i \"s/'PASSWORD': '.*',/'PASSWORD': '%(db_password)s',/\" %(settings)s" % context)

src/c/o/confine-controller-0.10.5/controller/management/commands/setupnginx.py   confine-controller(Download)
 
from controller.utils.paths import get_project_root, get_site_root, get_project_name
from controller.utils.system import run, check_root, get_default_celeryd_username
 
from pki import ca
        for extra_context in (nginx, uwsgi):
            context.update(extra_context)
            diff = run("echo '%(conf)s'|diff - %(file)s" % context, err_codes=[0,1,2])
            if diff.return_code == 2:
                # File does not exist
                run("echo '%(conf)s' > %(file)s" % context)
                            return
                        break
                run("cp %(file)s %(file)s.save" % context)
                run("echo '%(conf)s' > %(file)s" % context)
                self.stdout.write("\033[1;31mA new version of %(file)s has been installed.\n "

src/c/o/confine-controller-0.10.5/controller/management/commands/setupapache.py   confine-controller(Download)
 
from controller.utils.paths import get_project_root, get_site_root, get_project_name
from controller.utils.system import run, check_root, get_default_celeryd_username
 
from pki import ca
            'apache_conf_file': '/etc/apache2/conf.d/%(project_name)s.conf' % context})
 
        diff = run("echo '%(apache_conf)s'|diff - %(apache_conf_file)s" % context, err_codes=[0,1,2])
        if diff.return_code == 2:
            # File does not exist
            run("echo '%(apache_conf)s' > %(apache_conf_file)s" % context)
                        return
                    break
            run("cp %(apache_conf_file)s %(apache_conf_file)s.\$save" % context)
            run("echo '%(apache_conf)s' > %(apache_conf_file)s" % context)
            self.stdout.write("\033[1;31mA new version of %(apache_conf_file)s "

src/c/o/confine-controller-0.10.5/controller/management/commands/startservices.py   confine-controller(Download)
 
from controller.settings import START_SERVICES
from controller.utils.system import run, check_root
 
 
        if options.get(service):
            err_codes = [0,1] if optional else [0]
            e = run('service %s %s' % (service, action), err_codes=err_codes)
            if e.return_code == 1:
                return False

src/c/o/confine-controller-0.10.5/controller/utils/options.py   confine-controller(Download)
from controller.core.exceptions import OperationLocked
from controller.utils.paths import get_project_root
from controller.utils.system import run, touch
 
 
                'settings': settings_file,
            }
            if run("grep '^%(name)s *=' %(settings)s" % context, err_codes=[0,1]):
                # Update existing settings_file
                run("sed -i \"s#%(name)s *=.*#%(name)s = %(value)s#\" %(settings)s" % context)
            else:
                run("echo \"%(name)s = %(value)s\" >> %(settings)s" % context)

src/c/o/confine-controller-0.10.5/controller/apps/mgmtnetworks/tinc/management/commands/setuptincd.py   confine-controller(Download)
from controller import settings
from controller.utils import update_settings
from controller.utils.system import check_root, run, get_default_celeryd_username
from nodes.models import Server
 
 
        r = functools.partial(run, silent=False)
        boots = run("grep %(net_name)s %(tincd_root)s/nets.boot" % context, err_codes=[0,1])
        if boots.return_code == 1:
            r("echo %(net_name)s >> %(tincd_root)s/nets.boot" % context)
                "%(user)s\s\s*ALL=NOPASSWD:\s\s*%(tincd_bin)s\s\s*-kHUP\s\s*-n %(net_name)s"
            ) % context
            sudoers_exists = run('grep "%s" /etc/sudoers' % sudoers_hup, err_codes=[0,1,2])
            if sudoers_exists.return_code == 1:
                cmd = "%(user)s ALL=NOPASSWD: %(tincd_bin)s -kHUP -n %(net_name)s" % context

src/c/o/confine-controller-0.10.5/controller/management/commands/postupgradecontroller.py   confine-controller(Download)
 
from controller.utils.apps import is_installed
from controller.utils.system import run, check_root
 
 
def deprecate_periodic_tasks(names):
    from djcelery.models import PeriodicTask
    for name in names:
        PeriodicTask.objects.filter(name=name).delete()
    run('rabbitmqctl stop_app')
        PeriodicTask.objects.filter(name=name).delete()
    run('rabbitmqctl stop_app')
    run('rabbitmqctl reset')
    run('rabbitmqctl start_app')
    run('service celeryd restart')

src/c/o/confine-controller-0.10.5/controller/apps/mgmtnetworks/tinc/tasks.py   confine-controller(Download)
 
from controller.utils import LockFile
from controller.utils.system import run, touch
 
from .settings import TINC_NET_NAME, TINC_TINCD_ROOT, TINC_TINCD_BIN, TINC_TINCD_SEND_HUP
 
        # delete all tinc hosts
        run('rm -f -- %s{host_,node_}*' % hosts_path)
 
        # create all tinc hosts
        for script in scripts:
            run(script)
        }
        tinc_hup = "sudo %(tincd_bin)s -kHUP -n %(net_name)s" % context
        run(tinc_hup)
 

src/c/o/confine-controller-0.10.5/controller/apps/firmware/management/commands/setupfirmware.py   confine-controller(Download)
from optparse import make_option
 
from django.core.management.base import BaseCommand, CommandError
 
from controller.utils.system import run, check_root, get_default_celeryd_username
 
        if run('grep "^fuse:" /etc/group', err_codes=[0,1]).return_code == 1:
            run('addgroup fuse')
        if run('groups %s|grep fuse' % username, err_codes=[0,1]).return_code == 1: 
            run('adduser %s fuse' % username)

src/c/o/confine-controller-0.10.5/controller/management/commands/upgradecontroller.py   confine-controller(Download)
from controller import get_version
from controller.utils import get_existing_pip_installation
from controller.utils.system import run, check_root
 
 
            rand_name = ''.join(random.sample(char_set, 6))
            backup = os.path.join(base_path, 'controller.' + rand_name)
            run("mv %s %s" % (current_path, backup))
 
            # collect existing eggs previous to the installation
            eggs_regex = os.path.join(base_path, 'confine_controller-*.egg-info')
            eggs = run('ls -d %s' % eggs_regex)
            except CommandError:
                # Restore backup
                run('rm -rf %s' % current_path)
                run('mv %s %s' % (backup, current_path))
                raise CommandError("Problem runing pip upgrade, aborting...")

  1 | 2  Next