Beispiel #1
0
def gather_permissions_labels():
    # FIXME: would probably put in global db?

    cmd = '{cli} shell getprop ro.product.model'
    model = catch_err(run_command(cmd, outf=MAP)).strip().replace(' ', '_')
    cmd = '{cli} shell pm list permissions -g -f > {outf}'
    perms = catch_err(run_command(cmd, outf=model + '.permissions'))
Beispiel #2
0
def binary_exists(filename):
    # Check if binary is callable on our path
    try:
        run_command([filename], True)
        return True
    except OSError:
        return False
Beispiel #3
0
def apply_manifests(kubectl):
    print('Applying manifests...')
    run_command([kubectl, '--context=minikube', 'apply', '-f', MANIFESTS])
    print('Deleting existing pods...')
    kubernetes.config.load_kube_config(context='minikube')
    v1_api = kubernetes.client.CoreV1Api()
    for pod in v1_api.list_namespaced_pod('default').items:
        v1_api.delete_namespaced_pod(body=kubernetes.client.V1DeleteOptions(), name=pod.metadata.name, namespace='default')
Beispiel #4
0
def pip_install(path, names, is_file, has_version = True):
    command = '{} && pip --no-cache-dir install'.format(to_env(path))
    
    proxy = os.environ.get('http_proxy')
    if proxy:
        command = '{} --proxy {} '.format(command, proxy)
    if is_file:
        filename = home_path(names)
        command = '{} -r {}'.format(command, filename)
    else:
        for name in names:
            if isinstance(name, dict):
                if name.get('version', ''):
                    command = '{} {}=={} '.format(command, name['name'], name['version'])
                else:
                    command = '{} {}'.format(command, name['name'])
            else:    
                if has_version and name.version != None and name.version != '':
                    command = '{} {}=={} '.format(command, name.name, name.version)
                elif name.name == 'django':
                    command = '{} {}==1.8.4'.format(command, name.name)
                else:
                    command = '{} {}'.format(command, name.name)
    out = run_command(command)

    return out
Beispiel #5
0
def build_docker_images(minikube):
    print('Building docker images')
    raw_env_settings = run_command([minikube, 'docker-env', '--shell="bash"'],
                                   True)
    matches = re.finditer(r'^export (.+)="(.+)"$', raw_env_settings,
                          re.MULTILINE)
    env = dict([(m.group(1), m.group(2)) for m in matches])

    client = docker.from_env(
        environment=env,
        version='auto',
    )

    dirs = ('aimmo-game', 'aimmo-game-creator', 'aimmo-game-worker')
    for dir in dirs:
        path = os.path.join(BASE_DIR, dir)
        tag = 'ocadotechnology/%s:test' % dir
        print("Building %s..." % tag)
        status = client.build(
            decode=True,
            path=dir,
            tag=tag,
        )
        for line in status:
            if 'stream' in line:
                print(line['stream'], end='')
Beispiel #6
0
    def execute(self):
        self.status = "running"
        self.start_time = datetime.now().isoformat()

        (self.out, self.err, self.rc) = run_command(self.command)

        self.end_time = datetime.now().isoformat()
        self.status = "done"
Beispiel #7
0
def get_ruby_versions():
    command = 'source /usr/local/rvm/scripts/rvm && rvm list'
    output = run_command(command)
    versions = []
    for line in output[1].split('\n'):
        s = re.search('ruby-(.+) \[', line)
        if s:
            versions.append(s.group(1))
    return sorted(versions)
Beispiel #8
0
def pip_install_text(path, name):
    command = '{} && pip --no-cache-dir install'.format(to_env(path))
    
    proxy = os.environ.get('http_proxy')
    if proxy:
        command = '{} --proxy {} '.format(command, proxy)
    command = '{} {} '.format(command, name)
    out = run_command(command)

    return out
Beispiel #9
0
def pip_install_text(path, name):
    command = '{} && pip --no-cache-dir install'.format(to_env(path))
    
    proxy = os.environ.get('http_proxy')
    if proxy:
        command = '{} --proxy {} '.format(command, proxy)
    command = '{} {} '.format(command, name)
    out = run_command(command)

    return out
Beispiel #10
0
def start():
    if platform.machine().lower() not in ('amd64', 'x86_64'):
        raise ValueError('Requires 64-bit')
    create_test_bin()
    kubectl = download_kubectl()
    minikube = download_minikube()
    start_cluster(minikube)
    build_docker_images(minikube)
    render_manifests()
    apply_manifests(kubectl)
    os.environ['MINIKUBE_PROXY_URL'] = run_command([minikube, 'service', 'aimmo-reverse-proxy', '--url'], True).strip()
    print('Cluster ready')
Beispiel #11
0
def client_handler(client_socket):

	if len(config.upload_destination):
		file_buffer = ""

		while True:
			data = client_socket.recv(1024)

			if not data:
				break
			else:
				file_buffer += data

		try:
			file_descriptor = open(config.upload_destination, "wb")
			file_descriptor.write(file_buffer)
			file_descriptor.close()

			client_socket.send("Successfully saved file to \
				%s\r\n" % config.upload_destination)

		except:
			client_socket.send("Failed to save file to %s\r\n" % \
				config.upload_destination)

	if len(config.execute):
		output = run.run_command(config.execute)
		client_socket.send(output)

	if config.command:
		while True:
			client_socket.send("<BHP:#> ")
			cmd_buffer = ""
			while "\n" not in cmd_buffer:
				cmd_buffer += client_socket.recv(1024)

			response = run.run_command(cmd_buffer)
			client_socket.send(response)
Beispiel #12
0
def client_handler(client_socket):

    if len(config.upload_destination):
        file_buffer = ""

        while True:
            data = client_socket.recv(1024)

            if not data:
                break
            else:
                file_buffer += data

        try:
            file_descriptor = open(config.upload_destination, "wb")
            file_descriptor.write(file_buffer)
            file_descriptor.close()

            client_socket.send("Successfully saved file to \
				%s\r\n" % config.upload_destination)

        except:
            client_socket.send("Failed to save file to %s\r\n" % \
             config.upload_destination)

    if len(config.execute):
        output = run.run_command(config.execute)
        client_socket.send(output)

    if config.command:
        while True:
            client_socket.send("<BHP:#> ")
            cmd_buffer = ""
            while "\n" not in cmd_buffer:
                cmd_buffer += client_socket.recv(1024)

            response = run.run_command(cmd_buffer)
            client_socket.send(response)
Beispiel #13
0
def pip_install(path, names, is_file, has_version = True):
    command = '{} && pip --no-cache-dir install'.format(to_env(path))
    
    proxy = os.environ.get('http_proxy')
    if proxy:
        command = '{} --proxy {} '.format(command, proxy)
    if is_file:
        filename = home_path(names)
        command = '{} -r {}'.format(command, filename)
    else:
        for name in names:
            if has_version and name.version != None and name.version != '':
                command = '{} {}=={} '.format(command, name.name, name.version)
            elif name.name == 'django':
                command = '{} {}==1.8.4'.format(command, name.name)
            else:
                command = '{} {}'.format(command, name.name)
    out = run_command(command)

    return out
Beispiel #14
0
def build_docker_images(minikube):
    print('Building docker images')
    raw_env_settings = run_command([minikube, 'docker-env', '--shell="bash"'], True)
    matches = re.finditer(r'^export (.+)="(.+)"$', raw_env_settings, re.MULTILINE)
    env = dict([(m.group(1), m.group(2)) for m in matches])

    client = docker.from_env(
        environment=env,
        version='auto',
    )

    dirs = ('aimmo-game', 'aimmo-game-creator', 'aimmo-game-worker', 'aimmo-reverse-proxy')
    for dir in dirs:
        path = os.path.join(BASE_DIR, dir)
        tag = 'ocadotechnology/%s:test' % dir
        print("Building %s..." % tag)
        status = client.build(
            decode=True,
            path=dir,
            tag=tag,
        )
        for line in status:
            if 'stream' in line:
                print(line['stream'], end='')
Beispiel #15
0
def install_ruby_version(version):
    command = 'sudo su && source /usr/local/rvm/scripts/rvm && rvm install {} && gem install bundle && gem install bundler'.format(version)
    return run_command(command)
Beispiel #16
0
def configure_env(path):
    command = 'virtualenv {}'.format(path)
    return run_command(command)
Beispiel #17
0
def block_network():
    return run_command('ufw enable')
Beispiel #18
0
def pip_freeze(path):
    out = run_command('{} && pip freeze'.format(to_env(path)))
    out = out[1].strip().splitlines()
    out = [line for line in out if not ' ' in line and '==' in line]
    return out
Beispiel #19
0
def start_cluster(minikube):
    status = run_command([minikube, 'status'], True)
    if 'Running' in status:
        print('Cluster already running')
    else:
        run_command([minikube, 'start', '--memory=2048', '--cpus=2'])
Beispiel #20
0
def configure_env(path):
    command = 'virtualenv --no-site-packages {}'.format(path)
    return run_command(command)
Beispiel #21
0
def rename_file(old_file, new_file):
    return run_command('mv {} {}'.format(
        old_file,
        new_file))
Beispiel #22
0
def pip_freeze(path):
    out = run_command('{} && pip freeze'.format(to_env(path)))
    out = out[1].strip().splitlines()
    out = [line for line in out if not ' ' in line and '==' in line]
    return out
Beispiel #23
0
def kill_port(port):
    return run_command('fuser -n tcp -k {}'.format(port))
Beispiel #24
0
import lexer
import run
import sys
import var
import getpass
COMMAND = 'command'
UNKNOWN = 'unknown'
print('PySh')
try:
    while True:
        try:
            code = input(getpass.getuser() + '@' + var.CD_NAME + ' $ ')
            if code == 'exit':
                break
            lexed = lexer.lex(code)
            code_type = lexer.code_type(lexed)
            if code_type == COMMAND:
                run.run_command(lexed)
            elif code_type == UNKNOWN:
                print('bash: error: unknown command "{}"'.format(lexed[0]),
                      file=sys.stderr)
        except:
            print('bash: error')
except KeyboardInterrupt:
    pass
print('exit')
Beispiel #25
0
def unzip(zip_name, dir_name):
    command = 'unzip -o -qq ' + zip_name + ' -d ' + dir_name
    out = run_command(command)
Beispiel #26
0
def rename_file(old_file, new_file):
    return run_command('mv {} {}'.format(
        old_file,
        new_file))
Beispiel #27
0
def render_manifests():
    run_command([RENDER_MANIFESTS, BASE_DIR, 'test', 'http://%s:8000/players/api/games/' % get_ip()])
Beispiel #28
0
def unblock_network():
    return run_command('ufw disable')
Beispiel #29
0
def unzip(zip_name, dir_name):
    command = 'unzip -o -qq ' + zip_name + ' -d ' + dir_name
    out = run_command(command)
Beispiel #30
0
def configure_env(path):
    command = 'virtualenv {}'.format(path)
    return run_command(command)