예제 #1
0
def share_dir(dir_to_share):
    dir_to_share = os.path.expanduser(dir_to_share)
    dir_to_share = utils.unfuck_path(dir_to_share)
    dir_to_share = os.path.abspath(dir_to_share)

    room_name = os.path.basename(dir_to_share)
    floo_room_dir = os.path.join(G.COLAB_DIR, G.USERNAME, room_name)

    if os.path.isfile(dir_to_share):
        return msg.error('give me a directory please')

    if not os.path.isdir(dir_to_share):
        return msg.error('The directory %s doesn\'t appear to exist' % dir_to_share)

    floo_file = os.path.join(dir_to_share, '.floo')
    # look for the .floo file for hints about previous behavior
    info = {}
    try:
        floo_info = open(floo_file, 'rb').read().decode('utf-8')
        info = json.loads(floo_info)
    except (IOError, OSError):
        pass
    except Exception:
        msg.warn("couldn't read the floo_info file: %s" % floo_file)

    room_url = info.get('url')
    if room_url:
        try:
            result = utils.parse_url(room_url)
        except Exception as e:
            msg.error(str(e))
        else:
            room_name = result['room']
            floo_room_dir = os.path.join(G.COLAB_DIR, result['owner'], result['room'])
            # they have previously joined the room
            if os.path.realpath(floo_room_dir) == os.path.realpath(dir_to_share):
                # it could have been deleted, try to recreate it if possible
                # TODO: org or something here?
                if result['owner'] == G.USERNAME:
                    try:
                        api.create_room(room_name)
                        msg.debug('Created room %s' % room_url)
                    except Exception as e:
                        msg.debug('Tried to create room' + str(e))
                # they wanted to share teh dir, so always share it
                return join_room(room_url, lambda x: agent.protocol.create_buf(dir_to_share))

    # link to what they want to share
    try:
        utils.mkdir(os.path.dirname(floo_room_dir))
        os.symlink(dir_to_share, floo_room_dir)
    except OSError as e:
        if e.errno != 17:
            raise
    except Exception as e:
        return msg.error("Couldn't create symlink from %s to %s: %s" % (dir_to_share, floo_room_dir, str(e)))

    # make & join room
    create_room(room_name, floo_room_dir, dir_to_share)
예제 #2
0
def share_dir(dir_to_share):
    dir_to_share = os.path.expanduser(dir_to_share)
    dir_to_share = utils.unfuck_path(dir_to_share)
    dir_to_share = os.path.abspath(dir_to_share)

    room_name = os.path.basename(dir_to_share)
    floo_room_dir = os.path.join(G.COLAB_DIR, G.USERNAME, room_name)

    if os.path.isfile(dir_to_share):
        return msg.error('give me a directory please')

    if not os.path.isdir(dir_to_share):
        return msg.error('The directory %s doesn\'t appear to exist' % dir_to_share)

    floo_file = os.path.join(dir_to_share, '.floo')
    # look for the .floo file for hints about previous behavior
    info = {}
    try:
        floo_info = open(floo_file, 'rb').read().decode('utf-8')
        info = json.loads(floo_info)
    except (IOError, OSError):
        pass
    except Exception:
        msg.warn("couldn't read the floo_info file: %s" % floo_file)

    room_url = info.get('url')
    if room_url:
        try:
            result = utils.parse_url(room_url)
        except Exception as e:
            msg.error(str(e))
        else:
            room_name = result['room']
            floo_room_dir = os.path.join(G.COLAB_DIR, result['owner'], result['room'])
            # they have previously joined the room
            if os.path.realpath(floo_room_dir) == os.path.realpath(dir_to_share):
                # it could have been deleted, try to recreate it if possible
                # TODO: org or something here?
                if result['owner'] == G.USERNAME:
                    try:
                        api.create_room(room_name)
                        msg.debug('Created room %s' % room_url)
                    except Exception as e:
                        msg.debug('Tried to create room' + str(e))
                # they wanted to share teh dir, so always share it
                return join_room(room_url, lambda x: agent.protocol.create_buf(dir_to_share))

    # link to what they want to share
    try:
        utils.mkdir(os.path.dirname(floo_room_dir))
        os.symlink(dir_to_share, floo_room_dir)
    except OSError as e:
        if e.errno != 17:
            raise
    except Exception as e:
        return msg.error("Couldn't create symlink from %s to %s: %s" % (dir_to_share, floo_room_dir, str(e)))

    # make & join room
    create_room(room_name, floo_room_dir, dir_to_share)
예제 #3
0
def is_modifiable(name_to_check=None):
    if not agent or not agent.protocol:
        return
    vim_buf = vim.current.buffer
    name = vim_buf.name
    if not name:
        return
    if name_to_check and name_to_check != name:
        msg.warn('Can not call readonly on file: %s' % name)
    if not agent.protocol.is_shared(name):
        return
    if 'patch' not in agent.protocol.perms:
        vim.command("call g:FlooSetReadOnly()")
        sublime.set_timeout(is_modifiable, 0, name)
예제 #4
0
def ticker_watcher(ticker):
    global ticker_errors

    if not agent:
        return
    ticker.poll()
    if ticker.returncode is None:
        return
    msg.warn('respawning new ticker')
    ticker_errors += 1
    if ticker_errors > 10:
        return fallback_to_feedkeys('Too much trouble with the floobits external ticker.')
    start_event_loop()
    sublime.set_timeout(ticker_watcher, 2000, ticker)
예제 #5
0
def is_modifiable(name_to_check=None):
    if not agent or not agent.protocol:
        return
    vim_buf = vim.current.buffer
    name = vim_buf.name
    if not name:
        return
    if name_to_check and name_to_check != name:
        msg.warn('Can not call readonly on file: %s' % name)
    if not agent.protocol.is_shared(name):
        return
    if 'patch' not in agent.protocol.perms:
        vim.command("call g:FlooSetReadOnly()")
        sublime.set_timeout(is_modifiable, 0, name)
예제 #6
0
def ticker_watcher(ticker):
    global ticker_errors

    if not agent:
        return
    ticker.poll()
    if ticker.returncode is None:
        return
    msg.warn('respawning new ticker')
    ticker_errors += 1
    if ticker_errors > 10:
        return fallback_to_feedkeys('Too much trouble with the floobits external ticker.')
    start_event_loop()
    sublime.set_timeout(ticker_watcher, 2000, ticker)
예제 #7
0
def fallback_to_feedkeys(warning):
    global using_feedkeys
    using_feedkeys = True
    warning += " Falling back to f//e hack which will break some key commands. You may need to call FlooPause/FlooUnPause before some commands."
    msg.warn(warning)
    enable_floo_feedkeys()
예제 #8
0
def part_room():
    if not agent:
        return msg.warn('Unable to part room: You are not joined to a room.')
    stop_everything()
    msg.log('You left the room.')
예제 #9
0
def fallback_to_feedkeys(warning):
    global using_feedkeys
    using_feedkeys = True
    warning += " Falling back to f//e hack which will break some key commands. You may need to call FlooPause/FlooUnPause before some commands."
    msg.warn(warning)
    enable_floo_feedkeys()
예제 #10
0
def part_room():
    if not agent:
        return msg.warn('Unable to part room: You are not joined to a room.')
    stop_everything()
    msg.log('You left the room.')