Exemplo n.º 1
0
def create_room(room_name, ln_path=None, share_path=None):
    try:
        api.create_room(room_name)
        room_url = 'https://%s/r/%s/%s' % (G.DEFAULT_HOST, G.USERNAME,
                                           room_name)
        msg.debug('Created room %s' % room_url)
    except urllib2.HTTPError as e:
        if e.code != 409:
            raise
        if ln_path:
            while True:
                room_name = vim_input(
                    'Room %s already exists. Choose another name: ' %
                    room_name, room_name + "1")
                new_path = os.path.join(os.path.dirname(ln_path), room_name)
                try:
                    os.rename(ln_path, new_path)
                except OSError:
                    continue
                msg.debug('renamed ln %s to %s' % (ln_path, new_path))
                ln_path = new_path
                break

        return create_room(room_name, ln_path, share_path)
    except Exception as e:
        sublime.error_message('Unable to create room: %s' % str(e))
        return

    try:
        webbrowser.open(room_url + '/settings', new=2, autoraise=True)
    except Exception:
        msg.debug("Couldn't open a browser. Thats OK!")
    join_room(room_url, lambda x: agent.protocol.create_buf(share_path))
Exemplo n.º 2
0
def create_room(room_name, ln_path=None, share_path=None):
    try:
        api.create_room(room_name)
        room_url = 'https://%s/r/%s/%s' % (G.DEFAULT_HOST, G.USERNAME, room_name)
        msg.debug('Created room %s' % room_url)
    except urllib2.HTTPError as e:
        if e.code != 409:
            raise
        if ln_path:
            while True:
                room_name = vim_input('Room %s already exists. Choose another name: ' % room_name, room_name + "1")
                new_path = os.path.join(os.path.dirname(ln_path), room_name)
                try:
                    os.rename(ln_path, new_path)
                except OSError:
                    continue
                msg.debug('renamed ln %s to %s' % (ln_path, new_path))
                ln_path = new_path
                break

        return create_room(room_name, ln_path, share_path)
    except Exception as e:
        sublime.error_message('Unable to create room: %s' % str(e))
        return

    try:
        webbrowser.open(room_url + '/settings', new=2, autoraise=True)
    except Exception:
        msg.debug("Couldn't open a browser. Thats OK!")
    join_room(room_url, lambda x: agent.protocol.create_buf(share_path))
Exemplo n.º 3
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)
Exemplo n.º 4
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)
Exemplo n.º 5
0
    def on_input(self, room_name):
        try:
            api.create_room(room_name)
            room_url = 'https://%s/r/%s/%s' % (G.DEFAULT_HOST, G.USERNAME,
                                               room_name)
            print('Created room %s' % room_url)
        except HTTPError as e:
            if e.code != 409:
                raise
            args = {
                'room_name':
                room_name,
                'prompt':
                'Room %s already exists. Choose another name:' % room_name
            }

            if self.ln_path:
                while True:
                    room_name = room_name + '1'
                    new_path = os.path.join(os.path.dirname(self.ln_path),
                                            room_name)
                    try:
                        os.rename(self.ln_path, new_path)
                    except OSError:
                        continue
                    args = {
                        'ln_path':
                        new_path,
                        'room_name':
                        room_name,
                        'prompt':
                        'Room %s already exists. Choose another name:' %
                        room_name
                    }
                    break

            return self.window.run_command('floobits_create_room', args)
        except Exception as e:
            sublime.error_message('Unable to create room: %s' % str(e))
            return

        if not disconnect_dialog():
            return

        webbrowser.open(room_url + '/settings', new=2, autoraise=True)

        self.window.run_command('floobits_join_room', {
            'room_url': room_url,
        })
Exemplo n.º 6
0
    def on_input(self, room_name):
        try:
            api.create_room(room_name)
            room_url = 'https://%s/r/%s/%s' % (G.DEFAULT_HOST, G.USERNAME, room_name)
            print('Created room %s' % room_url)
        except HTTPError as e:
            if e.code != 409:
                raise
            args = {
                'room_name': room_name,
                'prompt': 'Room %s already exists. Choose another name:' % room_name
            }

            if self.ln_path:
                while True:
                    room_name = room_name + '1'
                    new_path = os.path.join(os.path.dirname(self.ln_path), room_name)
                    try:
                        os.rename(self.ln_path, new_path)
                    except OSError:
                        continue
                    args = {
                        'ln_path': new_path,
                        'room_name': room_name,
                        'prompt': 'Room %s already exists. Choose another name:' % room_name
                    }
                    break

            return self.window.run_command('floobits_create_room', args)
        except Exception as e:
            sublime.error_message('Unable to create room: %s' % str(e))
            return

        if not disconnect_dialog():
            return

        webbrowser.open(room_url + '/settings', new=2, autoraise=True)

        self.window.run_command('floobits_join_room', {
            'room_url': room_url,
        })
Exemplo n.º 7
0
    def on_input(self, dir_to_share):
        global ON_CONNECT
        dir_to_share = os.path.expanduser(dir_to_share)
        dir_to_share = utils.unfuck_path(dir_to_share)
        room_name = os.path.basename(dir_to_share)
        floo_room_dir = os.path.join(G.COLAB_DIR, G.USERNAME, room_name)
        print(G.COLAB_DIR, G.USERNAME, room_name, floo_room_dir)

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

        try:
            utils.mkdir(dir_to_share)
        except Exception:
            return sublime.error_message("The directory %s doesn't exist and I can't make it." % dir_to_share)

        floo_file = os.path.join(dir_to_share, '.floo')

        info = {}
        try:
            floo_info = open(floo_file, 'rb').read().decode('utf-8')
            info = json.loads(floo_info)
        except (IOError, OSError):
            pass
        except Exception:
            print("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:
                sublime.error_message(str(e))
            else:
                room_name = result['room']
                floo_room_dir = os.path.join(G.COLAB_DIR, result['owner'], result['room'])
                if os.path.realpath(floo_room_dir) == os.path.realpath(dir_to_share):
                    if result['owner'] == G.USERNAME:
                        try:
                            api.create_room(room_name)
                            print('Created room %s' % room_url)
                        except Exception as e:
                            print('Tried to create room' + str(e))
                    # they wanted to share teh dir, so always share it
                    return self.window.run_command('floobits_join_room', {'room_url': room_url})
        # go make sym link
        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 sublime.error_message("Couldn't create symlink from %s to %s: %s" % (dir_to_share, floo_room_dir, str(e)))

        # make & join room
        ON_CONNECT = lambda x: Listener.create_buf(dir_to_share)
        self.window.run_command('floobits_create_room', {
            'room_name': room_name,
            'ln_path': floo_room_dir,
        })
Exemplo n.º 8
0
    def on_input(self, dir_to_share):
        global ON_CONNECT
        dir_to_share = os.path.expanduser(dir_to_share)
        dir_to_share = utils.unfuck_path(dir_to_share)
        room_name = os.path.basename(dir_to_share)
        floo_room_dir = os.path.join(G.COLAB_DIR, G.USERNAME, room_name)
        print(G.COLAB_DIR, G.USERNAME, room_name, floo_room_dir)

        if os.path.isfile(dir_to_share):
            return sublime.error_message('Give me a directory please')

        try:
            utils.mkdir(dir_to_share)
        except Exception:
            return sublime.error_message(
                "The directory %s doesn't exist and I can't make it." %
                dir_to_share)

        floo_file = os.path.join(dir_to_share, '.floo')

        info = {}
        try:
            floo_info = open(floo_file, 'rb').read().decode('utf-8')
            info = json.loads(floo_info)
        except (IOError, OSError):
            pass
        except Exception:
            print("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:
                sublime.error_message(str(e))
            else:
                room_name = result['room']
                floo_room_dir = os.path.join(G.COLAB_DIR, result['owner'],
                                             result['room'])
                if os.path.realpath(floo_room_dir) == os.path.realpath(
                        dir_to_share):
                    if result['owner'] == G.USERNAME:
                        try:
                            api.create_room(room_name)
                            print('Created room %s' % room_url)
                        except Exception as e:
                            print('Tried to create room' + str(e))
                    # they wanted to share teh dir, so always share it
                    return self.window.run_command('floobits_join_room',
                                                   {'room_url': room_url})
        # go make sym link
        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 sublime.error_message(
                "Couldn't create symlink from %s to %s: %s" %
                (dir_to_share, floo_room_dir, str(e)))

        # make & join room
        ON_CONNECT = lambda x: Listener.create_buf(dir_to_share)
        self.window.run_command('floobits_create_room', {
            'room_name': room_name,
            'ln_path': floo_room_dir,
        })