def floobits_join_workspace(workspace_url, d='', upload_path=None):
    editor.line_endings = _get_line_endings()
    msg.debug('workspace url is %s' % workspace_url)
    try:
        result = utils.parse_url(workspace_url)
    except Exception as e:
        return msg.error(str(e))

    if d:
        utils.mkdir(d)
    else:
        try:
            d = utils.get_persistent_data()['workspaces'][result['owner']][result['workspace']]['path']
        except Exception:
            d = os.path.realpath(os.path.join(G.COLAB_DIR, result['owner'], result['workspace']))

    prompt = 'Save workspace files to: '
    if not os.path.isdir(d):
        while True:
            d = vim_input(prompt, d, 'dir')
            if d == '':
                continue
            d = os.path.realpath(os.path.expanduser(d))
            if os.path.isfile(d):
                prompt = '%s is not a directory. Enter an existing path or a path I can create: ' % d
                continue
            if not os.path.isdir(d):
                try:
                    utils.mkdir(d)
                except Exception as e:
                    prompt = 'Couldn\'t make dir %s: %s ' % (d, str(e))
                    continue
            break
    d = os.path.realpath(os.path.abspath(d) + os.sep)
    try:
        utils.add_workspace_to_persistent_json(result['owner'], result['workspace'], workspace_url, d)
    except Exception as e:
        return msg.error('Error adding workspace to persistent.json: %s' % str(e))

    G.PROJECT_PATH = d
    vim.command('cd %s' % G.PROJECT_PATH)
    msg.debug('Joining workspace %s' % workspace_url)

    floobits_stop_everything()
    try:
        conn = VimHandler(result['owner'], result['workspace'])
        if upload_path:
            conn.once('room_info', lambda: G.AGENT.upload(upload_path))
        reactor.connect(conn, result['host'], result['port'], result['secure'])
    except Exception as e:
        msg.error(str(e))
        tb = traceback.format_exc()
        msg.debug(tb)
    if not G.TIMERS:
        start_event_loop()
 def run_agent(owner, workspace, host, port, secure):
     global on_room_info_waterfall
     if G.AGENT:
         msg.debug('Stopping agent.')
         reactor.stop()
         G.AGENT = None
     on_room_info_waterfall.add(update_recent_workspaces, {'url': workspace_url})
     try:
         conn = SublimeConnection(owner, workspace, agent_conn_kwargs.get('get_bufs', True))
         reactor.connect(conn, host, port, secure)
         conn.once('room_info', on_room_info_waterfall.call)
         on_room_info_waterfall = utils.Waterfall()
     except Exception as e:
         print(e)
         tb = traceback.format_exc()
         print(tb)
 def run_agent(owner, workspace, host, port, secure, upload):
     if G.AGENT:
         msg.debug('Stopping agent.')
         reactor.stop()
         G.AGENT = None
     try:
         auth = G.AUTH.get(host)
         if not auth:
             success = yield link_account, host
             if not success:
                 return
             auth = G.AUTH.get(host)
         conn = SublimeConnection(owner, workspace, auth, upload)
         reactor.connect(conn, host, port, secure)
     except Exception as e:
         msg.error(str_e(e))
Exemple #4
0
 def run_agent(owner, workspace, host, port, secure, upload):
     if G.AGENT:
         msg.debug('Stopping agent.')
         reactor.stop()
         G.AGENT = None
     try:
         auth = G.AUTH.get(host)
         if not auth:
             success = yield link_account, host
             if not success:
                 return
             auth = G.AUTH.get(host)
         conn = SublimeConnection(owner, workspace, auth, upload)
         reactor.connect(conn, host, port, secure)
     except Exception as e:
         msg.error(str_e(e))
 def cb(index):
     if index == 0:
         token = binascii.b2a_hex(uuid.uuid4().bytes).decode('utf-8')
         agent = RequestCredentialsHandler(token)
     elif index == 1:
         agent = CreateAccountHandler()
     else:
         d = utils.get_persistent_data()
         if d.get('disable_account_creation'):
             return
         d['disable_account_creation'] = True
         utils.update_persistent_data(d)
         sublime.message_dialog('''You can set up a Floobits account at any time under\n\nTools -> Floobits -> Setup''')
     try:
         reactor.connect(agent, G.DEFAULT_HOST, G.DEFAULT_PORT, True)
     except Exception as e:
         print(str_e(e))
def link_account(host, cb):
    account = sublime.ok_cancel_dialog('No credentials found in ~/.floorc.json for %s.\n\n'
                                       'Click "Link Account" to open a web browser and add credentials.' % host,
                                       'Link Account')
    if not account:
        return
    token = binascii.b2a_hex(uuid.uuid4().bytes).decode('utf-8')
    agent = RequestCredentialsHandler(token)
    if not agent:
        sublime.error_message('''A configuration error occured earlier. Please go to %s and sign up to use this plugin.\n
We're really sorry. This should never happen.''' % host)
        return

    agent.once('end', cb)

    try:
        reactor.connect(agent, host, G.DEFAULT_PORT, True)
    except Exception as e:
        print(str_e(e))
Exemple #7
0
 def cb(index):
     if index == 0:
         token = binascii.b2a_hex(uuid.uuid4().bytes).decode('utf-8')
         agent = RequestCredentialsHandler(token)
     elif index == 1:
         agent = CreateAccountHandler()
     else:
         d = utils.get_persistent_data()
         if d.get('disable_account_creation'):
             return
         d['disable_account_creation'] = True
         utils.update_persistent_data(d)
         sublime.message_dialog(
             '''You can set up a Floobits account at any time under\n\nTools -> Floobits -> Setup'''
         )
     try:
         reactor.connect(agent, G.DEFAULT_HOST, G.DEFAULT_PORT, True)
     except Exception as e:
         print(str_e(e))
def floobits_setup_credentials():
    prompt = 'You need a Floobits account! Do you have one? If no we will create one for you [y/n]. '
    d = vim_input(prompt, '')
    if d and (d != 'y' and d != 'n'):
        return floobits_setup_credentials()
    agent = None
    if d == 'y':
        msg.debug('You have an account.')
        token = binascii.b2a_hex(uuid.uuid4().bytes).decode('utf-8')
        agent = RequestCredentialsHandler(token)
    elif not utils.get_persistent_data().get('disable_account_creation'):
        agent = CreateAccountHandler()
    if not agent:
        msg.error('A configuration error occured earlier. Please go to floobits.com and sign up to use this plugin.\n\n'
                  'We\'re really sorry. This should never happen.')
        return
    try:
        reactor.connect(agent, G.DEFAULT_HOST, G.DEFAULT_PORT, True)
    except Exception as e:
        msg.error(str(e))
        msg.debug(traceback.format_exc())
Exemple #9
0
def link_account(host, cb):
    account = sublime.ok_cancel_dialog(
        'No credentials found in ~/.floorc.json for %s.\n\n'
        'Click "Link Account" to open a web browser and add credentials.' %
        host, 'Link Account')
    if not account:
        return
    token = binascii.b2a_hex(uuid.uuid4().bytes).decode('utf-8')
    agent = RequestCredentialsHandler(token)
    if not agent:
        sublime.error_message(
            '''A configuration error occured earlier. Please go to %s and sign up to use this plugin.\n
We're really sorry. This should never happen.''' % host)
        return

    agent.once('end', cb)

    try:
        reactor.connect(agent, host, G.DEFAULT_PORT, True)
    except Exception as e:
        print(str_e(e))
def create_or_link_account():
    agent = None
    account = sublime.ok_cancel_dialog('You need a Floobits account!\n\n'
                                       'Click "Open browser" if you have one or click "cancel" and we\'ll make it for you.',
                                       'Open browser')
    if account:
        token = binascii.b2a_hex(uuid.uuid4().bytes).decode('utf-8')
        agent = RequestCredentialsHandler(token)
    elif not utils.get_persistent_data().get('disable_account_creation'):
        agent = CreateAccountHandler()

    if not agent:
        sublime.error_message('A configuration error occured earlier. Please go to floobits.com and sign up to use this plugin.\n\nWe\'re really sorry. This should never happen.')
        return

    try:
        reactor.connect(agent, G.DEFAULT_HOST, G.DEFAULT_PORT, True)
    except Exception as e:
        print(e)
        tb = traceback.format_exc()
        print(tb)
Exemple #11
0
def floobits_setup_credentials():
    prompt = 'You need a Floobits account! Do you have one? If no we will create one for you [y/n]. '
    d = vim_input(prompt, '')
    if d and (d != 'y' and d != 'n'):
        return floobits_setup_credentials()
    agent = None
    if d == 'y':
        msg.debug('You have an account.')
        token = binascii.b2a_hex(uuid.uuid4().bytes).decode('utf-8')
        agent = RequestCredentialsHandler(token)
    elif not utils.get_persistent_data().get('disable_account_creation'):
        agent = CreateAccountHandler()
    if not agent:
        msg.error(
            'A configuration error occured earlier. Please go to floobits.com and sign up to use this plugin.\n\n'
            'We\'re really sorry. This should never happen.')
        return
    try:
        reactor.connect(agent, G.DEFAULT_HOST, G.DEFAULT_PORT, True)
    except Exception as e:
        msg.error(str(e))
        msg.debug(traceback.format_exc())
Exemple #12
0
def floobits_join_workspace(workspace_url, d='', upload_path=None):
    editor.line_endings = _get_line_endings()
    msg.debug('workspace url is %s' % workspace_url)
    try:
        result = utils.parse_url(workspace_url)
    except Exception as e:
        return msg.error(str(e))

    if d:
        utils.mkdir(d)
    else:
        try:
            d = utils.get_persistent_data()['workspaces'][result['owner']][
                result['workspace']]['path']
        except Exception:
            d = os.path.realpath(
                os.path.join(G.COLAB_DIR, result['owner'],
                             result['workspace']))

    prompt = 'Save workspace files to: '
    if not os.path.isdir(d):
        while True:
            d = vim_input(prompt, d, 'dir')
            if d == '':
                continue
            d = os.path.realpath(os.path.expanduser(d))
            if os.path.isfile(d):
                prompt = '%s is not a directory. Enter an existing path or a path I can create: ' % d
                continue
            if not os.path.isdir(d):
                try:
                    utils.mkdir(d)
                except Exception as e:
                    prompt = 'Couldn\'t make dir %s: %s ' % (d, str(e))
                    continue
            break
    d = os.path.realpath(os.path.abspath(d) + os.sep)
    try:
        utils.add_workspace_to_persistent_json(result['owner'],
                                               result['workspace'],
                                               workspace_url, d)
    except Exception as e:
        return msg.error('Error adding workspace to persistent.json: %s' %
                         str(e))

    G.PROJECT_PATH = d
    vim.command('cd %s' % G.PROJECT_PATH)
    msg.debug('Joining workspace %s' % workspace_url)

    floobits_stop_everything()
    try:
        conn = VimHandler(result['owner'], result['workspace'])
        if upload_path:
            conn.once('room_info', lambda: G.AGENT.upload(upload_path))
        reactor.connect(conn, result['host'], result['port'], result['secure'])
    except Exception as e:
        msg.error(str(e))
        tb = traceback.format_exc()
        msg.debug(tb)
    if not G.TIMERS:
        start_event_loop()