Esempio n. 1
0
def cli(ctx, images, hosts, exclude):
    """pull images on docker machine env

    for example:

    \b
        #default pull on all hosts
        niuker machine-pull ubuntu alpine
    \b
        #pull on specific hosts
        niuker machine-pull ubuntu alpine -h xxxx -h yyyyy
    \b
        #pull exclude some hosts
        niuker machine-pull ubuntu alpine -e xxxx -e yyyyy
    """
    if not images:
        return
    if hosts and exclude:
        ctx.log('never use hosts and exclude together')
        return
    docker_hosts = get_machine_hosts(hosts, exclude)
    ctx.log('Hosts:\n%s' % '\n'.join(docker_hosts))
    ctx.log('sleep 10s waiting for you')
    sleep(10)
    pull_images(ctx, docker_hosts, images)
Esempio n. 2
0
def cli(ctx, images, hosts, exclude):
    """pull images on docker machine env

    for example:

    \b
        #default pull on all hosts
        niuker machine-pull ubuntu alpine
    \b
        #pull on specific hosts
        niuker machine-pull ubuntu alpine -h xxxx -h yyyyy
    \b
        #pull exclude some hosts
        niuker machine-pull ubuntu alpine -e xxxx -e yyyyy
    """
    if not images:
        return
    if hosts and exclude:
        ctx.log('never use hosts and exclude together')
        return
    docker_hosts = get_machine_hosts(hosts, exclude)
    ctx.log('Hosts:\n%s' % '\n'.join(docker_hosts))
    ctx.log('sleep 10s waiting for you')
    sleep(10)
    pull_images(ctx, docker_hosts, images)
Esempio n. 3
0
def cli(ctx, image_files, hosts, exclude):
    """sync images to docker machine hosts

    for example:

    \b
        #sync all hosts
        niuker machine-sync ubuntu.tar alpine.tar
    \b
        #sync to specific hosts
        niuker machine-sync ubuntu.tar alpine.tar -h xxxx -h yyyyy
    \b
        #sync exclude some hosts
        niuker machine-sync ubuntu.tar alpine.tar -e xxxx -e yyyyy
    """
    if not image_files:
        return
    if hosts and exclude:
        ctx.log('never use hosts and exclude together')
        return
    docker_hosts = get_machine_hosts(hosts, exclude)
    ctx.log('Hosts:\n%s' % '\n'.join(docker_hosts))
    ctx.log('sleep 10s waiting for you')
    sleep(10)
    sync_images(ctx, docker_hosts, image_files)
Esempio n. 4
0
def avi_cmd(path):
  fifo = '/tmp/omxplayer_fifo'

  sh.rm('-f', fifo)
  sh.mkfifo(fifo)
  omx_fifo_cmd = "/usr/bin/omxplayer -r -o hdmi " + path + " < " + fifo + " &"
  call(omx_fifo_cmd, shell=True)
  sh.sleep(0.2)
  call("echo . > " + fifo + " &", shell=True)
Esempio n. 5
0
def checkConn(ip):
    logging.debug("Checking ip...")
    for i in range(5):
        try:
            ping('-c', '1', ip, _fg=True)
            return True
        except:
            sleep('5')
    return False
Esempio n. 6
0
def master_clear():
    printer = StatusPrinter(indent=0)
    printer("Clearing Device")
    with Indent(printer):
        with Indent(printer):
            d = get_connected_device(printer=printer)
        cmd = ['shell', 'am', 'broadcast', '-a', 'android.intent.action.MASTER_CLEAR', '-n', 'android/com.android.server.MasterClearReceiver']
        printer('\'' + ' '.join(cmd) + '\'')
        adb(cmd)
    sleep(d.get_shutdown_delay())
Esempio n. 7
0
def main(base_dir, cmd_name, id_range):
    all_dirs = sorted(glob(join(base_dir, "*")))
    id_min, id_max = map(int, id_range.split(","))
    used_dirs = all_dirs[id_min:id_max]
    for each_dir in used_dirs:
        sbatch_dir = join(each_dir, "sbatch")
        sh.cd(sbatch_dir)
        sh.sleep(0.5)
        sh.sbatch(cmd_name)
        print(f"submitted {cmd_name} in {basename(each_dir)}")
Esempio n. 8
0
def test_background_processes():
    from sh import sleep
    # blocks
    sleep(3)
    print '...3 seconds later'

    # doesn't block
    p = sleep(3, _bg=True)
    print 'print immediately!'
    p.wait()
    print '...and 3 seconds later'
Esempio n. 9
0
def wait_ready(printer=StatusPrinter()):
    if not ready():
        printer('waiting for device ', end='')
        spinner = itertools.cycle(['-', '\\', '|', '/'])
        while not ready():
            sys.stdout.write(next(spinner))
            sys.stdout.flush()
            sleep(1)
            sys.stdout.write('\b')
            sys.stdout.flush()
        sleep(1)
        printer(' ... ready')
Esempio n. 10
0
    def set_target(self, target, url, printer=StatusPrinter()):
        self.wait_ready()

        if re.match('http://.*', url):
            url = url[7:]

        printer("Targeting device to: " + url)
        with Indent(printer):

            cmd = ['su', '1000', 'content', 'call', '--uri', 'content://com.clover.service.provider',
                '--method', 'changeTarget', '--extra', 'target:s:{}:{}'.format(target, url)]

            printer('\'' + ' '.join(cmd) + '\'')
            adb.shell(cmd)

        # the above call causes a reset
        # wait until the adb connection is lost
        printer("Waiting {} seconds for device to begin reboot..."
                .format(self.get_shutdown_delay()))
        sleep(self.get_shutdown_delay())
Esempio n. 11
0
File: test.py Progetto: ahhentz/sh
 def test_timeout(self):
     from sh import sleep
     from time import time
     
     # check that a normal sleep is more or less how long the whole process
     # takes
     sleep_for = 3
     started = time()
     sh.sleep(sleep_for).wait()
     elapsed = time() - started
     
     self.assertTrue(abs(elapsed - sleep_for) < 0.1)
     
     # now make sure that killing early makes the process take less time
     sleep_for = 3
     timeout = 1
     started = time()
     sh.sleep(sleep_for, _timeout=timeout).wait()
     elapsed = time() - started
     self.assertTrue(abs(elapsed - timeout) < 0.1)
Esempio n. 12
0
    def test_timeout(self):
        from sh import sleep
        from time import time

        # check that a normal sleep is more or less how long the whole process
        # takes
        sleep_for = 3
        started = time()
        sh.sleep(sleep_for).wait()
        elapsed = time() - started

        self.assertTrue(abs(elapsed - sleep_for) < 0.1)

        # now make sure that killing early makes the process take less time
        sleep_for = 3
        timeout = 1
        started = time()
        sh.sleep(sleep_for, _timeout=timeout).wait()
        elapsed = time() - started
        self.assertTrue(abs(elapsed - timeout) < 0.1)
Esempio n. 13
0
def run_trial(fs, trial_num, run_type):
    print "%s: trial %d, %s" % (fs, trial_num, run_type)
    trace_filename = fs + '.' + run_type + '.' + str(trial_num)

    if run_type == 'write':
        while True:
            try:
                sh.sudo('hadoop fs -rmr -skipTrash /benchmarks'.split())
                break
            except sh.ErrorReturnCode_255:
                print "failed to delete benchmark data; retrying in 5 seconds..."
                sh.sleep(5)

    for server in servers:
        server.start_blktrace(server.hostname + '.' + trace_filename)
        #server.start_blktrace('data/blktrace/%s/%s.%d' % (fs, server.hostname, trial_num))

    sh.sleep(1)    

    try:
        """
        sh.time(
                'sudo hadoop jar /usr/share/hadoop/hadoop-examples-1.0.4.jar teragen -Dmapred.map.tasks=10 1000000000 /tera'.split(), 
                _err = 'data/%s.gen.%d' % (fs, trial_num)
        )
        sh.time(
                'sudo hadoop jar /usr/share/hadoop/hadoop-examples-1.0.4.jar terasort -Dmapred.map.tasks=10 -Dmapred.reduce.tasks=10 /tera /sorted'.split(), 
                _err = 'data/%s.sort.%d' % (fs, trial_num)
        )
        """
        sh.time(
                ('sudo hadoop jar /usr/share/hadoop/hadoop-test-1.0.4.jar TestDFSIO -%s -fileSize 100 -nrFiles 100' % run_type).split(),
                _err = 'data/%s/%s.%d' % (run_type, fs, trial_num)
        )
    except sh.ErrorReturnCode_255:
        print "WARNING: test failed"
    
    for server in servers:
        server.end_blktrace()
        sh.scp(('root@%s:%s.* %s' % (server.hostname, server.hostname + '.' + trace_filename, 'data/blktrace/%s/' % fs)).split())
Esempio n. 14
0
def wait():
    """not yet implemented"""

    try:
        instances = fgrep(nova('list'), prefix)
        total = _count(instances)
        exit
        bar = Bar('Processing', max=total)
        old = total
        while True:

            # _status()

            current = _count(instances)
            if old != current:
                bar.next()
            if current == 0:
                bar.finish()
                break
            sleep(2)
            instances = fgrep(nova('list'), prefix)
    except:
        print 'done'
Esempio n. 15
0
    def test_background(self):
        from sh import sleep
        import time

        start = time.time()
        sleep_time = .5
        p = sleep(sleep_time, _bg=True)

        now = time.time()
        self.assertTrue(now - start < sleep_time)

        p.wait()
        now = time.time()
        self.assertTrue(now - start > sleep_time)
def wait():
    """not yet implemented"""

    try:
        instances = fgrep(nova('list'), prefix)
        total = _count(instances)
        exit
        bar = Bar('Processing', max=total)
        old = total
        while True:

            # _status()

            current = _count(instances)
            if old != current:
                bar.next()
            if current == 0:
                bar.finish()
                break
            sleep(2)
            instances = fgrep(nova('list'), prefix)
    except:
        print 'done'
Esempio n. 17
0
File: test.py Progetto: ahhentz/sh
    def test_background(self):
        from sh import sleep
        import time

        start = time.time()
        sleep_time = .5
        p = sleep(sleep_time, _bg=True)

        now = time.time()
        self.assertTrue(now - start < sleep_time)

        p.wait()
        now = time.time()
        self.assertTrue(now - start > sleep_time)
Esempio n. 18
0
    def process(self):
        cmd = self.opt("cmd")
        script = cmd if cmd else self.opt("script")
        timeout = self.opt("timeout")
        concurrent = self.opt("concurrent")
        assets = self.opt("assets")
        wait_for_success = self.opt("wait-for-success")
        back_off = self.opt("back-off")
        retries = self.opt("retries")

        timeout_delta = None
        if timeout:
            start_time = datetime.datetime.now()
            timeout_delta = start_time + datetime.timedelta(seconds=timeout)

        if not concurrent:
            concurrent = False

        if not retries:
            retries = 0
        retries_count = 0

        app.log.info(f"Running: {script}")
        if assets:
            app.log.info(f"\tbuilding assets")
            for asset in assets:
                is_executable = asset.get("is-executable", False)
                if "source-blob" in asset:
                    self._handle_source_blob(asset["source-blob"],
                                             asset["destination"],
                                             is_executable)
                elif "source-file" in asset:
                    self._handle_source_file(asset["source-file"],
                                             asset["destination"],
                                             is_executable)

        def _do_run():
            self._run_script(script, timeout, concurrent=concurrent)

        try:
            _do_run()
        except sh.TimeoutException:
            raise SpecProcessException(f"Timeout exceeded")
        except sh.ErrorReturnCode as error:
            if wait_for_success:
                app.log.debug(f"\twait for success initiated.")
                while wait_for_success and retries <= retries_count:
                    app.log.debug(f"\tretrying command.")
                    if timeout_delta:
                        current_time = datetime.datetime.now()
                        time_left = timeout_delta - current_time
                        app.log.debug(
                            f"\twill timeout in {time_left.seconds} seconds.")
                        if timeout_delta < current_time:
                            raise SpecProcessException(
                                f"Failed: timeout exceeded.")
                    if back_off:
                        app.log.info(
                            f"\tsleeping for {back_off} seconds, retrying.")
                        sh.sleep(back_off)
                    try:
                        _do_run()
                    except sh.ErrorReturnCode as error:
                        app.log.info(f"\tfailure detected, initiating retry.")
                    retries_count += 1

            raise
Esempio n. 19
0
 def after_rm():
     from sh import sleep
     print("We are testing the auto-discard " +
           "functionality of the fs")
     sleep("10")
Esempio n. 20
0
    logging.debug("Master IP != cur IP...")
    return False, masterIp


while True:
    try:
        check, masterIp = compareIp()
        if check:
            logging.debug("Starting server...")
            with sudo:
                sed('-i', f's/#advertise_addr = "127.0.0.1"/advertise_addr = "{masterIp}"/', '/etc/consul.d/consul.hcl')
                consul('agent', "-config-file", "/etc/consul.d/consul.hcl", "-log-file", "/home/max/", _bg=True)
                #changing consul ip in nomad cfg
                sed('-i', f's/127.0.0.1/{masterIp}/', '/etc/nomad.d/nomad.hcl')
                server(_out=sys.stdout)
                sleep(10)
        else:
            check = checkConn(masterIp)
            if check:
                with sudo:
                    logging.debug("Starting client...")
                    #changing consul ip
                    sed('-i', f's/127.0.0.1/{masterIp}/', '/etc/nomad.d/nomad.hcl')
                    client('-servers', masterIp, _out=sys.stdout)
                    sleep(10)
            else:
                logging.debug("Something wrong...")
                print('Something wrong...')
                print('Try to start manualy...')
                print('Press alt+f2 to start inreractive prompt...')
                print('Here soe envs for you:')
Esempio n. 21
0
 def after_rm():
     from sh import sleep
     print("We are testing the auto-discard " +
           "functionality of the fs")
     sleep("10")
Esempio n. 22
0
def _i3_get_current_windows():
    def find(element, results=[]):
        if 'focused' in element and element['focused']:
            results.append(element)
        if 'nodes' in element:
            for node in element['nodes']:
                find(node, results)
        return results

    tree = json.loads(sh.i3_msg('-t', 'get_tree').stdout)
    return find(tree)


if __name__ == '__main__':
    # Sleep some time to provide time to release all pressed keys
    sh.sleep(1)

    try:
        with open(config_file_path) as f:
            window = json.load(f)
            print(f"Using '{config_file_path}' config: {window}")
            print("Delete config file if you need to change windows:")
            print(f"  rm {config_file_path}")
            try:
                current_window_id = _i3_get_current_windows()[0]['window']
                sh.xdotool('windowactivate', window['id'])
                sh.xdotool('key', window['key'])
                sh.xdotool('windowactivate', current_window_id)
            except sh.ErrorReturnCode:
                print("Some command fails")
Esempio n. 23
0
#coding=utf8
from sh import sleep
#非阻塞执行

# blocks
sleep(3)
print("...3 seconds later")



# doesn't block
p = sleep(3, _bg=True)
print("prints immediately!")
p.wait()
print("...and 3 seconds later")