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 create_workspace(workspace_name, ln_path, share_path=None):
    try:
        api.create_workspace({'name': workspace_name})
        workspace_url = 'https://%s/r/%s/%s' % (G.DEFAULT_HOST, G.USERNAME,
                                                workspace_name)
        msg.debug('Created workspace %s' % workspace_url)
    except urllib2.HTTPError as e:
        err_body = e.read()
        msg.error('Unable to create workspace: %s %s' % (unicode(e), err_body))
        if e.code not in [400, 402, 409]:
            return sublime.error_message('Unable to create workspace: %s %s' %
                                         (unicode(e), err_body))

        if e.code == 400:
            while True:
                workspace_name = re.sub('[^A-Za-z0-9_\-]', '-', workspace_name)
                workspace_name = vim_input(
                    'Invalid name. Workspace names must match the regex [A-Za-z0-9_\-]. Choose another name:'
                    % workspace_name, workspace_name)
                new_path = os.path.join(os.path.dirname(ln_path),
                                        workspace_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
        elif e.code == 402:
            # TODO: better behavior. ask to create a public workspace instead
            return sublime.error_message('Unable to create workspace: %s %s' %
                                         (unicode(e), err_body))
        elif e.code == 409:
            while True:
                workspace_name = vim_input(
                    'Workspace %s already exists. Choose another name: ' %
                    workspace_name, workspace_name + "1")
                new_path = os.path.join(os.path.dirname(ln_path),
                                        workspace_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_workspace(workspace_name, ln_path, share_path)
    except Exception as e:
        sublime.error_message('Unable to create workspace: %s' % str(e))
        return

    try:
        webbrowser.open(workspace_url + '/settings', new=2, autoraise=True)
    except Exception:
        msg.debug("Couldn't open a browser. Thats OK!")
    join_workspace(workspace_url,
                   lambda x: agent.protocol.create_buf(share_path, force=True))
Exemplo n.º 4
0
    def create_workspace(self, data, workspace_name, dir_to_share, owner=None, perms=None):
        owner = owner or G.USERNAME
        workspace_name = data.get('response', workspace_name)
        prompt = 'workspace %s already exists. Choose another name: ' % workspace_name
        try:
            api_args = {
                'name': workspace_name,
                'owner': owner,
            }
            if perms:
                api_args['perms'] = perms
            api.create_workspace(api_args)
            workspace_url = utils.to_workspace_url({'secure': True, 'owner': owner, 'workspace': workspace_name})
            msg.debug('Created workspace %s' % workspace_url)
        except HTTPError as e:
            err_body = e.read()
            msg.error('Unable to create workspace: %s %s' % (unicode(e), err_body))
            if e.code not in [400, 402, 409]:
                return msg.error('Unable to create workspace: %s' % str(e))
            if e.code == 400:
                workspace_name = re.sub('[^A-Za-z0-9_\-]', '-', workspace_name)
                prompt = 'Invalid name. Workspace names must match the regex [A-Za-z0-9_\-]. Choose another name:'
            elif e.code == 402:
                try:
                    err_body = json.loads(err_body)
                    err_body = err_body['detail']
                except Exception:
                    pass
                return sublime.error_message('%s' % err_body)
            else:
                prompt = 'Workspace %s/%s already exists. Choose another name:' % (owner, workspace_name)

            return self.get_input(prompt, workspace_name, self.create_workspace, workspace_name, dir_to_share, owner, perms)
        except Exception as e:
            return msg.error('Unable to create workspace: %s' % str(e))

        G.PROJECT_PATH = dir_to_share
        self.remote_connect(workspace_url, lambda this: this.protocol.create_buf(dir_to_share))