示例#1
0
def enable_dist_api():
    """Enable distant API.

    .. deprecated:: 0.8.0
          ``enable_dist_api`` will be removed in reapy 1.0.0.
          Use :func:`reapy.config.configure_reaper` that works
          even from outside REAPER.

    Create a Web interface and add the ReaScript
    ``reapy.reascripts.activate_reapy_server`` to the Actions list.
    """
    msg = ("Function enable_dist_api is deprecated since 0.8.0. "
           "Use reapy.config.configure_reaper instead.")
    warnings.warn(FutureWarning(msg))
    if not reapy.is_inside_reaper():
        raise OutsideREAPERError
    create_new_web_interface(WEB_INTERFACE_PORT)
    reascript_path = get_activate_reapy_server_path()
    action_id = reapy.add_reascript(reascript_path)
    command_name = json.dumps(reapy.get_command_name(action_id))
    section, key, value = "reapy", "activate_reapy_server", command_name
    reapy.set_ext_state(section, key, value, persist=True)
    message = (
        "reapy successfully enabled!\n\nPlease restart REAPER.\n\nYou will "
        "then be able to import reapy from the outside.")
    reapy.show_message_box(message)
示例#2
0
def cnoose_ip() -> ty.Optional[str]:
    """Ask user to choose IP for slave server."""
    hard = ty.cast(ty.List[str], nip.interfaces())  # type:ignore
    log(hard)
    log([nip.ifaddresses(iface) for iface in hard])  # type:ignore
    addresses = ty.cast(
        ty.List[str],
        [
            nip.ifaddresses(iface)[nip.AF_INET][0]['addr']  # type:ignore
            for iface in hard
        ])
    log(*addresses)
    rpr.delete_ext_state(EXT_SECTION, ADDRESS_KEY_SLAVE, persist=True)
    for addr in addresses:
        response = rpr.show_message_box(
            text=f"""slave server can listen of dollowing ips:
            {addresses}
            Do you want to use {addr}?
            (other will be prompted if you refuse)""",
            title="choose slave IP",
            type="yes-no")
        if response == 'yes':
            rpr.set_ext_state(EXT_SECTION, ADDRESS_KEY_SLAVE, addr)
            return rpr.get_ext_state(EXT_SECTION, ADDRESS_KEY_SLAVE)

    rpr.show_message_box(text='no IP set', title='status', type="ok")
    return None
示例#3
0
 def _ping(self) -> None:
     # log('ping')
     response = ''
     active = self._slaves_active.copy()
     for host in active:
         try:
             response = send_data('ping',
                                  'ping',
                                  host,
                                  self._slaves_port,
                                  timeout=0.03)
         except ConnectionRefusedError as e:
             log(f'slave {host} is dead: {e}')
             del self._slaves_active[host]
             rpr.defer(self._send_slaves_to_gui)
             return
         except st.timeout as e:
             log(f'timeout on host: {host}')
             rpr.show_message_box(
                 'slave server on this machine started before master.\n' +
                 'please, restart both scripts in the proper order.',
                 'connection timeout')
             raise e
         if response:
             log(f'slave {host} is alive')
示例#4
0
def disable_dist_api():
    """
    Disable distant API.

    Delete ``reapy`` Web interface, and remove the ReaScript
    ``reapy.reascripts.activate_reapy_server`` from the
    Actions list.
    """
    if not reapy.is_inside_reaper():
        raise OutsideREAPERError
    delete_web_interface(reapy.get_resource_path(), WEB_INTERFACE_PORT)
    reascript_path = get_activate_reapy_server_path()
    reapy.remove_reascript(reascript_path)
    message = ("reapy will be disabled as soon as you restart REAPER.")
    reapy.show_message_box(message)
示例#5
0
def enable_dist_api():
    """
    Enable distant API.

    Create a Web interface and add the ReaScript
    ``reapy.reascripts.activate_reapy_server`` to the Actions list.
    """
    if not reapy.is_inside_reaper():
        raise OutsideREAPERError
    create_new_web_interface(WEB_INTERFACE_PORT)
    reascript_path = get_activate_reapy_server_path()
    action_id = reapy.add_reascript(reascript_path)
    command_name = json.dumps(reapy.get_command_name(action_id))
    section, key, value = "reapy", "activate_reapy_server", command_name
    reapy.set_ext_state(section, key, value, persist=True)
    message = (
        "reapy successfully enabled!\n\nPlease restart REAPER.\n\nYou will "
        "then be able to import reapy from the outside.")
    reapy.show_message_box(message)
示例#6
0
from common import log
from common import is_stopped
import set_slave_ip

from config import EXT_SECTION, ADDRESS_KEY_SLAVE

# log.enable_print()
# log.enable_console()
HOST: str
PORT: int
HOST, PORT = DEF_HOST, DEF_PORT

if not rpr.has_ext_state(EXT_SECTION, ADDRESS_KEY_SLAVE):
    host = set_slave_ip.cnoose_ip()
    if host is None:
        rpr.show_message_box(text='cannot run slave', title='error', type="ok")
        raise RuntimeError('cannot run slave')
    HOST = host
else:
    HOST = rpr.get_ext_state(EXT_SECTION, ADDRESS_KEY_SLAVE)

handlers = [PrintHandler, PingHandler]
server = ReaperServer(HOST, PORT, handlers)

announce = Announce(HOST, PORT)


def main_loop() -> None:
    if is_stopped():
        server.run()
        announce.run()