Пример #1
0
    def __init__(self, master=None):
        
        if 'MESOS_SLAVE_PID' in os.environ and 'DRUN_SIZE' not in os.environ:
            from executor import run
            run()
            sys.exit(0)
        
        options = parse_options()
        self.master = master or options.master

        if self.master.startswith('local'):
            self.scheduler = LocalScheduler()
            self.isLocal = True
        elif self.master.startswith('process'):
            self.scheduler = MultiProcessScheduler(options.parallel)
            self.isLocal = True
        elif (self.master.startswith('mesos')
              or self.master.startswith('zoo')):
            if '://' not in self.master:
                self.master = os.environ.get('MESOS_MASTER')
                if not self.master:
                    raise Exception("invalid uri of mesos master: %s" % self.master)
            self.scheduler = MesosScheduler(self.master, options) 
            self.isLocal = False
        else:
            raise Exception("invalid master option: %s" % self.master)

        if options.parallel:
            self.defaultParallelism = options.parallel
        else:
            self.defaultParallelism = self.scheduler.defaultParallelism()
        self.defaultMinSplits = max(self.defaultParallelism, 2)
       
        self.started = False
Пример #2
0
    def __init__(self, master=None):

        if 'MESOS_SLAVE_PID' in os.environ and 'DRUN_SIZE' not in os.environ:
            from executor import run
            run()
            sys.exit(0)

        options = parse_options()
        self.master = master or options.master

        if self.master.startswith('local'):
            self.scheduler = LocalScheduler()
            self.isLocal = True
        elif self.master.startswith('process'):
            self.scheduler = MultiProcessScheduler(options.parallel)
            self.isLocal = True
        elif (self.master.startswith('mesos')
              or self.master.startswith('zoo')):
            if '://' not in self.master:
                self.master = os.environ.get('MESOS_MASTER')
                if not self.master:
                    raise Exception("invalid uri of mesos master: %s" %
                                    self.master)
            self.scheduler = MesosScheduler(self.master, options)
            self.isLocal = False
        else:
            raise Exception("invalid master option: %s" % self.master)

        if options.parallel:
            self.defaultParallelism = options.parallel
        else:
            self.defaultParallelism = self.scheduler.defaultParallelism()
        self.defaultMinSplits = max(self.defaultParallelism, 2)

        self.started = False
Пример #3
0
    def __init__(self, master=None):
        
        if 'MESOS_SLAVE_PID' in os.environ and 'DRUN_SIZE' not in os.environ:
            from executor import run
            run()
            sys.exit(0)
        
        options = parse_options()
        self.options = options
        master = master or options.master

        if master == 'local':
            self.scheduler = LocalScheduler()
            self.isLocal = True
        elif master == 'process':
            self.scheduler = MultiProcessScheduler(options.parallel)
            self.isLocal = True
        else:
            if master == 'mesos':
                master = os.environ.get('MESOS_MASTER')
                if not master:
                    raise Exception("invalid uri of mesos master: %s" % master)
            if master.startswith('mesos://'):
                if '@' in master:
                    master = master[master.rfind('@')+1:]
                else:
                    master = master[master.rfind('//')+2:]
            elif master.startswith('zoo://'):
                master = 'zk' + master[3:]

            if ':' not in master:
                master += ':5050'
            self.scheduler = MesosScheduler(master, options) 
            self.isLocal = False
            
        self.master = master

        if options.parallel:
            self.defaultParallelism = options.parallel
        else:
            self.defaultParallelism = self.scheduler.defaultParallelism()
        self.defaultMinSplits = max(self.defaultParallelism, 2)
      
        try:
            from rfoo.utils import rconsole
            rconsole.spawn_server(locals(), 0)
        except ImportError:
            pass

        self.started = False
Пример #4
0
def _load_lookup_table_vars(executor, dirname, program, pserver_id,
                            table_name):
    """
    The parameter server will load lookup table's local file in 
    selectedrows variable.

    Args:
        executor(Executor): The executor to run for loading persistable variables
        dirname(str): The directory path
        main_program(Program): Find the variable named table_name in main_program
        pserver_id(int): the serial number in pserver_endpoints list
        table_name(str): lookup table name

    Returns:
        None

    Examples:
        .. code-block:: python

            exe = fluid.Executor(fluid.CPUPlace())
            dirname = "./checkpoints/checkpoint_9/"
            prog = fluid.default_main_program()
            pserver_id = 1
            table_name = "share_w"
            _load_lookup_table_vars(executor=exe,
                    dirname=dirname, program=prog, pserver_id=pserver_id,
                    table_name=table_name)
    """

    for var in program.list_vars():
        if var.name == table_name:
            lookup_table_var = var
            break

    assert lookup_table_var is not None

    lookup_table_dir = os.path.join(dirname, LOOKUP_TABLE_DIR)
    table_file = table_name + CHECKPOINT_SEPARATOR + str(pserver_id)

    load_prog = framework.Program()
    load_block = load_prog.global_block()

    load_block.append_op(
        type='load',
        inputs={},
        outputs={'Out': [lookup_table_var]},
        attrs={'file_path': os.path.join(lookup_table_dir, table_file)})

    executor.run(load_prog)
Пример #5
0
def get():
    python3env = os.environ.copy()
    python3dir = os.path.abspath(os.path.join(os.getcwd(),
                                              os.pardir)) + '/letsencrypt/bin:'

    python3env['PATH'] = python3dir + python3env['PATH']

    commands = [
        ["~/dehydrated/dehydrated --register --accept-terms"],
        [
            "~/dehydrated/dehydrated -c -t dns-01 -k '../dehydrated/hooks/cloudflare/hook.py'"
        ],
    ]

    executor.run(commands, env=python3env, shell=True)
Пример #6
0
def blockify_cpu():
  """ Print the CPU load average and temperature """
  
  block = Powerblock("cpu")

  cpuload = executor.run("uptime | awk -F'[a-z]:' '{ print $2}'")[0]
  oneminload = float(cpuload.split(",")[0] + "." + cpuload.split(",")[1])
  cputemp = executor.run("cat /sys/class/thermal/thermal_zone7/temp")[0]
  temp = int(cputemp) / 1000
  
  if oneminload > 3 or temp > 80:
    block.set_urgent()

  block.set_text(str(oneminload) + "/" + str(temp))
  return block
Пример #7
0
def _save_pserver_vars_by_notify(executor, dirname, lookup_table,
                                 ps_endpoint_list):
    """
    This function will send checkpoint notify message from Trainer 0
    to all the pservers.
    The checkpoint notify message contains lookup table name, 
    the absolute path on pserver to save lookup_table.

    Args:
        executor(Executor): The executor to run for send checkpoint notify.
        dirname(str): The folder where to save checkpoints.
        lookup_table(string): the lookup table name, when use distribute
            lookup table, we can get lookup table name by DistributeTranspiler.
            table_name 
        ps_endpoint_list(list): the parameter server ip:port list.  
            when use distribute lookup table, we can get ps_endpoint_list by 
            distribute arguments.
    Return:
        None
    
    Examples:
        .. code-block:: python

            exe = fluid.Executor(fluid.CPUPlace())
            param_path = "./my_paddle_model"
            prog = fluid.default_main_program()
            table_name = "share_w"
            ps_endpoints = ["127.0.0.1:6000","127.0.0.1:6001"]

            _save_pserver_vars_by_notify(executor=exe,
                    dirname=param_path, lookup_table=table_name, 
                    ps_endpoint_list=ps_endpoints)
    """
    cur_dir = _get_lookuptable_dir(dirname)

    checkpoint_notify_program = framework.Program()
    checkpoint_notify_block = checkpoint_notify_program.global_block()

    attrs = {}
    attrs['epmap'] = ps_endpoint_list
    attrs['dir'] = cur_dir
    attrs['lookup_table'] = lookup_table

    checkpoint_notify_block.append_op(type='checkpoint_notify',
                                      inputs={},
                                      outputs={},
                                      attrs=attrs)
    executor.run(checkpoint_notify_program)
Пример #8
0
def main():
    euler_q = _choose_question()

    print(format_cli_display(euler_q.question_text, euler_q.title))
    if euler_q.is_solved:
        print(
            format_cli_display(
                f"Solution: {euler_q.solved_value}\nMinimum Solution Time: {euler_q.min_solution_time}"
            ))
    elif input_yes_no("\nDo you want to attempt to run a solution? "):
        solution, t = executor.run(euler_q.question_id)

        if solution == euler_q.solved_value:
            if t < euler_q.min_solution_time:
                euler_q.add_vals(min_solution_time=t)
        else:
            print(
                format_cli_display(
                    f"Saved solution does not match calculated solution."
                    f"\nCurrent Value: {euler_q.solved_value}\nNew Value: {solution}",
                    title='**WARNING**'))
            if print(input_yes_no('Do you want to overwrite the old data?')):
                euler_q.add_vals(solved_value=solution,
                                 min_solution_time=t,
                                 is_solved=True)
                print(format_cli_display('Values updated'))
Пример #9
0
def blockify_battery():
  """ Print the current battery level. """

  block = StatusUnit('battery')
  block.set_icon('')

  acpi = executor.run('acpi -b')[0]
  battery = re.search('\d*%', acpi).group(0)
  battery_int = int(battery[:-1])
  is_charging = bool(re.search('Charging|Unknown', acpi))

  if is_charging:
    block.set_icon('')
  elif battery_int > 90:
    block.set_icon('')
  elif battery_int > 60:
    block.set_icon('')
  elif battery_int > 30:
    block.set_icon('')
  elif battery_int > 10:
    block.set_icon('')
  else:
    block.set_icon('')

  if is_charging:
    block.set_text('')
  else:
    block.set_text(battery)
    block.set_background(colors['red'])
    block.set_color(colors['white'], colors['white'])

  return block
Пример #10
0
def blockify_cpu():
  """ Print the CPU load average and temperature """
  
  block = StatusUnit("cpu")
  block.set_icon("C")

  cpuload = executor.run("uptime | awk -F'[a-z]:' '{ print $2}'")[0]
  oneminload = float(cpuload.split(",")[0] + "." + cpuload.split(",")[1])
  cputemp = executor.run("cat /sys/class/thermal/thermal_zone7/temp")[0]
  temp = int(cputemp) / 1000
  
  if oneminload > 3 or temp > 80:
    block.set_urgent()
  elif oneminload > 1 or temp > 60:
    block.set_border(colors["urgent"], 0, TOP_BORDER_WIDTH, 0, 0)

  block.set_text(str(oneminload) + "/" + str(temp))
  block.status_block.set_min_width(40, "right")
  return block.to_json()
Пример #11
0
def download(target_dir, urls, filenames=None,\
    parallelism=10, creds=None, tries=3, extract=False):
    """ downloads large files either locally or on a remote machine
    @target_dir: where to download to
    @urls: a list of urls or a single url
    @filenames: list of filenames. If used, the the urls will be downloaded to
        those file names
    @parallelism(default=10): number of parallel processes to use
    @creds: dictionary with credentials
        if None, it will download locally
        if not None, then wget command will be run on a remote host
    @extract: boolean - whether to extract tar or zip files after download
    """
    if isinstance(urls, str):
        urls = [urls]

    if not isinstance(urls, list):
        raise Exception('Expected a list of urls. Received %s' % urls)

    if not os.path.exists(target_dir):
        os.makedirs(target_dir)

    cmds = []
    if filenames is None:
        filenames = [__url_to_filename(_url) for _url in urls]

    if isinstance(filenames, str):
        filenames = [filenames]

    if len(filenames) != len(urls):
        raise Exception('You have specified filenames but the number of filenames '\
            'does not match the number of urls')

    for ind, _url in enumerate(urls):
        filename = filenames[ind]
        file_path = os.path.join(target_dir, filename)
        cmd = 'wget -O "{}" -t {} -T {} -q "{}"'.format(file_path, tries, TIMEOUT, _url)
        if extract:
            ext = compression.get_unzip_cmd(file_path)
            if ext is not None:
                cmd = '{};cd "{}";{} "{}"'.format(cmd, target_dir, ext, filename)
        cmds.append(cmd)
    executor.run(cmds, parallelism=parallelism, curr_dir=target_dir, creds=creds)
Пример #12
0
async def wait_and_execute(websocket, path):
    while True:
        data = await websocket.recv()
        request = json.loads(data)
        print(f'< {request["code"]}')

        result = run(request['code'], request['language'])

        await websocket.send(str(result))
        print(f"> {result}")
Пример #13
0
def blockify_topprocess():
  """ Print the top CPU consuming process """
  
  block = StatusUnit("topcpu")
  block.set_icon("T")

  topprocess = executor.run("ps aux | sort -rk 3,3 | head -n 2 | tail -n 1 | rev | sed -e 's/^[[:space:]]*//' | cut -d' ' -f 1 | rev")[0]
  block.set_text(str(topprocess))
  block.status_block.set_min_width(40, "right")
  return block.to_json()
Пример #14
0
def download(target_dir, urls, filenames=None,\
    parallelism=10, creds=None, tries=3, extract=False):
    """ downloads large files either locally or on a remote machine
    @target_dir: where to download to
    @urls: a list of urls or a single url
    @filenames: list of filenames. If used, the the urls will be downloaded to
        those file names
    @parallelism(default=10): number of parallel processes to use
    @creds: dictionary with credentials
        if None, it will download locally
        if not None, then wget command will be run on a remote host
    @extract: boolean - whether to extract tar or zip files after download
    """
    if isinstance(urls, str):
        urls = [urls]

    if not isinstance(urls, list):
        raise Exception('Expected a list of urls. Received %s' % urls)

    if not os.path.exists(target_dir):
        os.makedirs(target_dir)

    cmds = []
    if filenames is None:
        filenames = [__url_to_filename(_url) for _url in urls]

    if isinstance(filenames, str):
        filenames = [filenames]

    if len(filenames) != len(urls):
        raise Exception('You have specified filenames but the number of filenames '\
            'does not match the number of urls')

    for ind, _url in enumerate(urls):
        filename = filenames[ind]
        file_path = os.path.join(target_dir, filename)
        cmd = 'wget -O "{}" -t {} -T {} -q "{}"'.format(file_path, tries, TIMEOUT, _url)
        if extract:
            ext = compression.get_unzip_cmd(file_path)
            if ext is not None:
                cmd = "{};cd {};{} {}".format(cmd, target_dir, ext, filename)
        cmds.append(cmd)
    executor.run(cmds, parallelism=parallelism, curr_dir=target_dir, creds=creds)
Пример #15
0
def blockify_active_window():
  """ Print the currently active window (or 'none'). """

  active_window, return_code = executor.run('xdotool getactivewindow getwindowname')
  if return_code != 0:
    return None
  if len(active_window) > 100:
    active_window = active_window[:80] + '...' + active_window[-20:]

  block = Powerblock('active-window')
  block.set_text(active_window)

  return block
Пример #16
0
def blockify_active_window():
  """ Print the currently active window (or 'none'). """

  active_window, return_code = executor.run('xdotool getactivewindow getwindowname')
  if return_code != 0:
    return None
  if len(active_window) > 100:
    active_window = active_window[:80] + '...' + active_window[-20:]

  block = StatusUnit('active-window')
  block.set_icon('')
  block.set_text(' ' + active_window)

  return block.to_json()
Пример #17
0
def blockify_internet():
  """ Prints primary IP and ping time to 8.8.8.8.
      Alerts when ping is high or IP not found.
  """
  block = Powerblock("internet")

  pingtime = executor.run("fping -C 1 -t 200 8.8.8.8")[0]
  ip = executor.run("ip a | grep -Eo 'inet (addr:)?([0-9]*\.){3}[0-9]*' | grep -Eo '([0-9]*\.){3}[0-9]*' | grep -v '127.0.0.1'")[0]
  if len(ip) < 4:
    block.set_urgent()
    block.set_text("NO IP")
  else:
    if len(pingtime) < 4:
      block.set_text(ip + " >200 ms")
      block.set_hl()
    else:
      pingtime = float(pingtime.split(" ")[5])
      if pingtime > 500:
        block.set_hl()
      elif pingtime > 1000:
        block.set_urgent()
      block.set_text(ip + " " + str(pingtime) + " ms")
  
  return block
Пример #18
0
def blockify_battery():
  """ Print the current battery level. """

  block = Powerblock('battery')

  acpi = executor.run('acpi -b')[0]
  battery = re.search('\d*%', acpi).group(0)
  battery_int = int(battery[:-1])
  is_charging = bool(re.search('Charging|Unknown', acpi))

  block.set_text(battery)
  if battery_int < 40 and not is_charging:
    block.set_hl()
  elif battery_int < 20 and not is_charging:
    block.set_urgent()


  return block
Пример #19
0
def blockify_battery():
  """ Print the current battery level. """

  block = StatusUnit('battery')
  block.set_icon('')

  acpi = executor.run('acpi -b')[0]
  battery = re.search('\d*%', acpi).group(0)
  battery_int = int(battery[:-1])
  is_charging = bool(re.search('Charging|Unknown', acpi))

  if is_charging:
    block.set_icon('')
  elif battery_int > 90:
    block.set_icon('')
  elif battery_int > 50:
    block.set_icon('')
  elif battery_int > 20:
    block.set_icon('')
  else:
    block.set_icon('')

  block.set_text(battery)

  if battery_int > 10 or is_charging:
    color = get_color_gradient(battery_int, [ 
      { 'threshold': 0,   'color': colors['urgent'] },
      { 'threshold': 20,  'color': colors['urgent'] },
      { 'threshold': 80,  'color': colors['lime'] },
      { 'threshold': 100, 'color': colors['lime'] } ])
    #block.set_border(colors["blue"], 0, 1, 0, 1)
  else:
    #block.set_urgent()
    pass

  block.status_block.set_min_width(40, 'right')
  return block.to_json()
Пример #20
0
def blockify_battery():
  """ Print the current battery level. """

  block = StatusUnit('battery')
  block.set_icon('')

  acpi = executor.run('acpi -b')[0]
  battery = re.search('\d*%', acpi).group(0)
  battery_int = int(battery[:-1])
  is_charging = bool(re.search('Charging|Unknown', acpi))

  if is_charging:
    block.set_icon('')
  elif battery_int > 90:
    block.set_icon('')
  elif battery_int > 50:
    block.set_icon('')
  elif battery_int > 20:
    block.set_icon('')
  else:
    block.set_icon('')

  block.set_text(battery)

  if battery_int > 10 or is_charging:
    color = get_color_gradient(battery_int, [ 
      { 'threshold': 0,   'color': colors['urgent'] },
      { 'threshold': 20,  'color': colors['urgent'] },
      { 'threshold': 80,  'color': colors['blue'] },
      { 'threshold': 100, 'color': colors['blue'] } ])
    block.set_border(color, 0, TOP_BORDER_WIDTH, 0, 0)
  else:
    block.set_urgent()

  block.status_block.set_min_width(40, 'right')
  return block.to_json()
Пример #21
0
def launch():
    code = request.form['code']
    input_ = request.form['stdin']
    execution_result = run(code, input_, timeout)
    return json.dumps(execution_result)
Пример #22
0
def emit_signal():
    executor.run('pkill -RTMIN+1 i3blocks')
Пример #23
0
def get_volume():
  return executor.run('pulseaudio-ctl current | grep -o "[0-9]*" | head -n1')[0]
Пример #24
0
def get_active_sink():
  return executor.run('pacmd list-sinks | grep "* index" | awk \'{print $3}\'')[0]
Пример #25
0
def toggle_volume():
  executor.run('amixer -D pulse set Master Playback Switch toggle')
Пример #26
0
def is_muted():
    return not executor.run(
        'amixer -D pulse get Master | grep -o "\[on\]" | head -n1')[0]
Пример #27
0
def set_volume(percentage):
    executor.run('pactl set-sink-volume ' + get_active_sink() + ' ' +
                 str(percentage) + '%')
    emit_signal()
Пример #28
0
 def _runExecutor(self):
     return executor.run(os.path.dirname(__file__)+"/executor.cfg")
Пример #29
0
 def _runExecutor(self):
     return executor.run(os.path.dirname(__file__) + "/executor.cfg")
Пример #30
0
def get_volume():
    return executor.run(
        'amixer -D pulse get Master | grep -o "\[.*%\]" | grep -o "[0-9]*" | head -n1'
    )[0]
Пример #31
0
def get_active_sink():
    return executor.run(
        'pacmd list-sinks | grep "* index" | awk \'{print $3}\'')[0]
Пример #32
0
def toggle_volume():
    executor.run('amixer -D pulse set Master Playback Switch toggle')
    emit_signal()
Пример #33
0
#!/usr/bin/env pypy
import sys
from os.path import dirname
sys.path.insert(1, dirname(dirname(__file__)))

from executor import run

if __name__ == '__main__':
    run()
Пример #34
0
def emit_signal():
    executor.run('pkill -RTMIN+1 i3blocks')
Пример #35
0
def is_headphones():
    return executor.run(
        'pacmd list-sinks | grep -Eo "active port: .*?headphones"')[0]
Пример #36
0
def set_volume(percentage):
  executor.run('pactl set-sink-volume ' + get_active_sink() + ' ' + str(percentage) + '%')
Пример #37
0
def status():
  if int(get_volume()) == 0 or is_muted():
    return 'muted'
  else:
    return 'on'

def emit_signal():
  executor.run('pkill -RTMIN+1 i3blocks')

if __name__ == '__main__':
  command = sys.argv[1]

  if command == 'set':
    set_volume(trim_to_range(sys.argv[2]))
  elif command == 'up':
      executor.run('pulseaudio-ctl up')
      emit_signal()
  elif command == 'down':
      executor.run('pulseaudio-ctl down')
      emit_signal()
  elif command == 'toggle':
    toggle_volume()
  elif command == 'read':
    write(get_volume())
  elif command == 'status':
    write(status())
  elif command == 'i3blocks':
    output = 'VOL ' + get_volume()
    if is_muted():
      output = '<s>' + output + '</s>'
      output += '\n\n#bb7473'
Пример #38
0
def is_muted():
  return not executor.run('amixer -D pulse get Master | grep -o "\[on\]" | head -n1')[0]
Пример #39
0
def set_volume(percentage):
  executor.run('pulseaudio-ctl set ' + str(percentage))
  emit_signal()
Пример #40
0
def get_volume():
  return executor.run('amixer -D pulse get Master | grep -o "\[.*%\]" | grep -o "[0-9]*" | head -n1')[0]
Пример #41
0
def toggle_volume():
  executor.run('pulseaudio-ctl mute')
  emit_signal()