def on_input(self, workspace_name, dir_to_share=None): if dir_to_share: self.dir_to_share = dir_to_share if workspace_name == '': return self.run(dir_to_share=self.dir_to_share) try: self.api_args['name'] = workspace_name self.api_args['owner'] = self.owner msg.debug(str(self.api_args)) api.create_workspace(self.api_args) workspace_url = 'https://%s/r/%s/%s' % (G.DEFAULT_HOST, self.owner, workspace_name) print('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 sublime.error_message('Unable to create workspace: %s %s' % (unicode(e), err_body)) kwargs = { 'dir_to_share': self.dir_to_share, 'workspace_name': workspace_name, 'api_args': self.api_args, 'owner': self.owner, } if e.code == 400: kwargs['workspace_name'] = re.sub('[^A-Za-z0-9_\-]', '-', workspace_name) kwargs['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: kwargs['prompt'] = 'Workspace %s/%s already exists. Choose another name:' % (self.owner, workspace_name) return self.window.run_command('floobits_create_workspace', kwargs) except Exception as e: return sublime.error_message('Unable to create workspace: %s' % unicode(e)) add_workspace_to_persistent_json(self.owner, workspace_name, workspace_url, self.dir_to_share) on_room_info_waterfall.add(on_room_info_msg) self.window.run_command('floobits_join_workspace', { 'workspace_url': workspace_url, 'agent_conn_kwargs': { 'get_bufs': False } })
def create_workspace(workspace_name, share_path, owner, perms=None, upload_path=None): workspace_url = 'https://%s/%s/%s' % (G.DEFAULT_HOST, G.USERNAME, workspace_name) try: api_args = { 'name': workspace_name, 'owner': owner, } if perms: api_args['perms'] = perms r = api.create_workspace(api_args) except Exception as e: return editor.error_message('Unable to create workspace %s: %s' % (workspace_url, unicode(e))) if r.code < 400: msg.debug('Created workspace %s' % workspace_url) return floobits_join_workspace(workspace_url, share_path, upload_path=upload_path) if r.code == 402: # TODO: Better behavior. Ask to create a public workspace instead? detail = r.body.get('detail') err_msg = 'Unable to create workspace because you have reached your maximum number of workspaces' if detail: err_msg += detail return editor.error_message(err_msg) if r.code == 400: workspace_name = re.sub('[^A-Za-z0-9_\-]', '-', workspace_name) workspace_name = vim_input( '%s is an invalid name. Workspace names must match the regex [A-Za-z0-9_\-]. Choose another name:' % workspace_name, workspace_name) elif r.code == 409: workspace_name = vim_input('Workspace %s already exists. Choose another name: ' % workspace_name, workspace_name + '1', 'file') else: return editor.error_message('Unable to create workspace: %s %s' % (workspace_url, unicode(e))) return create_workspace(workspace_name, share_path, perms, upload_path=upload_path)
def create_workspace(self, context, host, owner, name, api_args, dir_to_share): prompt = 'Workspace name: ' api_args['name'] = name api_args['owner'] = owner while True: new_name = yield self.user_charfield, context, prompt, name name = new_name or name try: api_args['name'] = name r = api.create_workspace(host, api_args) except Exception as e: msg.error('Unable to create workspace ', str_e(e)) editor.error_message('Unable to create workspace: %s' % str_e(e)) return if r.code < 400: workspace_url = 'https://%s/%s/%s' % (host, owner, name) msg.log('Created workspace ', workspace_url) self.remote_connect(context, host, owner, name, dir_to_share, utils.JOIN_ACTION.UPLOAD) return msg.error('Unable to create workspace: ', r.body) if r.code not in (400, 402, 409): try: r.body = r.body['detail'] except Exception: pass editor.error_message('Unable to create workspace: %s' % r.body) return if r.code == 402: try: r.body = r.body['detail'] except Exception: pass yes = yield self.user_y_or_n, context, '%s Open billing settings?' % r.body, "Yes" if yes: webbrowser.open('https://%s/%s/settings#billing' % (host, owner)) return if r.code == 400: # TODO: strip leading dots/dashes/etc name = re.sub('[^A-Za-z0-9_\-\.]', '_', name) prompt = 'Workspace names may only contain [A-Za-z0-9_\-\.]. Choose another name: ' continue yes = yield self.user_y_or_n, context, 'Workspace %s/%s already exists. Overwrite?' % (owner, name), 'Yes' if yes: # TODO: this doesn't set permissions on the workspace correctly self.remote_connect(context, host, owner, name, dir_to_share, utils.JOIN_ACTION.PROMPT) return prompt = 'Workspace %s/%s already exists. Choose new name: ' % (owner, name)
def on_input(self, workspace_name, dir_to_share=None): if dir_to_share: self.dir_to_share = dir_to_share if workspace_name == '': return self.run(dir_to_share=self.dir_to_share) try: self.api_args['name'] = workspace_name self.api_args['owner'] = self.owner msg.debug(str(self.api_args)) r = api.create_workspace(self.host, self.api_args) except Exception as e: msg.error('Unable to create workspace: %s' % str_e(e)) return sublime.error_message('Unable to create workspace: %s' % str_e(e)) workspace_url = 'https://%s/%s/%s' % (self.host, self.owner, workspace_name) msg.log('Created workspace %s' % workspace_url) if r.code < 400: utils.add_workspace_to_persistent_json(self.owner, workspace_name, workspace_url, self.dir_to_share) return self.window.run_command('floobits_join_workspace', { 'workspace_url': workspace_url, 'upload': dir_to_share }) msg.error('Unable to create workspace: %s' % r.body) if r.code not in [400, 402, 409]: try: r.body = r.body['detail'] except Exception: pass return sublime.error_message('Unable to create workspace: %s' % r.body) kwargs = { 'dir_to_share': self.dir_to_share, 'workspace_name': workspace_name, 'api_args': self.api_args, 'owner': self.owner, 'upload': self.upload, 'host': self.host, } if r.code == 400: kwargs['workspace_name'] = re.sub('[^A-Za-z0-9_\-\.]', '-', workspace_name) kwargs['prompt'] = 'Invalid name. Workspace names must match the regex [A-Za-z0-9_\-\.]. Choose another name:' elif r.code == 402: try: r.body = r.body['detail'] except Exception: pass if sublime.ok_cancel_dialog('%s' % r.body, 'Open billing settings'): webbrowser.open('https://%s/%s/settings#billing' % (self.host, self.owner)) return else: kwargs['prompt'] = 'Workspace %s/%s already exists. Choose another name:' % (self.owner, workspace_name) return self.window.run_command('floobits_create_workspace', kwargs)
def on_input(self, workspace_name, dir_to_share=None): if dir_to_share: self.dir_to_share = dir_to_share if workspace_name == '': return self.run(dir_to_share=self.dir_to_share) try: self.api_args['name'] = workspace_name self.api_args['owner'] = self.owner msg.debug(str(self.api_args)) r = api.create_workspace(self.api_args) except Exception as e: msg.error('Unable to create workspace: %s' % unicode(e)) return sublime.error_message('Unable to create workspace: %s' % unicode(e)) workspace_url = 'https://%s/%s/%s/' % (G.DEFAULT_HOST, self.owner, workspace_name) msg.log('Created workspace %s' % workspace_url) if r.code < 400: utils.add_workspace_to_persistent_json(self.owner, workspace_name, workspace_url, self.dir_to_share) return self.window.run_command('floobits_join_workspace', { 'workspace_url': workspace_url, 'agent_conn_kwargs': { 'get_bufs': False } }) msg.error('Unable to create workspace: %s' % r.body) if r.code not in [400, 402, 409]: try: r.body = r.body['detail'] except Exception: pass return sublime.error_message('Unable to create workspace: %s' % r.body) kwargs = { 'dir_to_share': self.dir_to_share, 'workspace_name': workspace_name, 'api_args': self.api_args, 'owner': self.owner, } if r.code == 400: kwargs['workspace_name'] = re.sub('[^A-Za-z0-9_\-\.]', '-', workspace_name) kwargs['prompt'] = 'Invalid name. Workspace names must match the regex [A-Za-z0-9_\-\.]. Choose another name:' elif r.code == 402: try: r.body = r.body['detail'] except Exception: pass return sublime.error_message('%s' % r.body) else: kwargs['prompt'] = 'Workspace %s/%s already exists. Choose another name:' % (self.owner, workspace_name) return self.window.run_command('floobits_create_workspace', kwargs)
def create_workspace(self, context, host, owner, name, api_args, dir_to_share): prompt = "Workspace name: " api_args["name"] = name api_args["owner"] = owner while True: new_name = yield self.user_charfield, context, prompt, name name = new_name or name try: api_args["name"] = name r = api.create_workspace(host, api_args) except Exception as e: msg.error("Unable to create workspace ", str_e(e)) editor.error_message("Unable to create workspace: %s" % str_e(e)) return if r.code < 400: workspace_url = "https://%s/%s/%s" % (host, owner, name) msg.log("Created workspace ", workspace_url) self.remote_connect(context, host, owner, name, dir_to_share, utils.JOIN_ACTION.UPLOAD) return msg.error("Unable to create workspace: ", r.body) if r.code not in (400, 402, 409): try: r.body = r.body["detail"] except Exception: pass editor.error_message("Unable to create workspace: %s" % r.body) return if r.code == 402: try: r.body = r.body["detail"] except Exception: pass yes = yield self.user_y_or_n, context, "%s Open billing settings?" % r.body, "Yes" if yes: webbrowser.open("https://%s/%s/settings#billing" % (host, owner)) return if r.code == 400: # TODO: strip leading dots/dashes/etc name = re.sub("[^A-Za-z0-9_\-\.]", "_", name) prompt = "Workspace names may only contain [A-Za-z0-9_\-\.]. Choose another name: " continue prompt = "Workspace %s/%s already exists. Choose another name: " % (owner, name)
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))
def create_workspace(self, context, host, owner, name, api_args, dir_to_share): prompt = 'Workspace name: ' api_args['name'] = name api_args['owner'] = owner while True: new_name = yield self.user_charfield, context, prompt, name name = new_name or name try: api_args['name'] = name r = api.create_workspace(host, api_args) except Exception as e: msg.error('Unable to create workspace ', str_e(e)) editor.error_message('Unable to create workspace: %s' % str_e(e)) return if r.code < 400: workspace_url = 'https://%s/%s/%s' % (host, owner, name) msg.log('Created workspace ', workspace_url) self.remote_connect(context, host, owner, name, dir_to_share, utils.JOIN_ACTION.UPLOAD) return msg.error('Unable to create workspace: ', r.body) if r.code not in (400, 402, 409): try: r.body = r.body['detail'] except Exception: pass editor.error_message('Unable to create workspace: %s' % r.body) return if r.code == 402: try: r.body = r.body['detail'] except Exception: pass yes = yield self.user_y_or_n, context, '%s Open billing settings?' % r.body, "Yes" if yes: webbrowser.open('https://%s/%s/settings#billing' % (host, owner)) return if r.code == 400: # TODO: strip leading dots/dashes/etc name = re.sub('[^A-Za-z0-9_\-\.]', '_', name) prompt = 'Workspace names may only contain [A-Za-z0-9_\-\.]. Choose another name: ' continue yes = yield self.user_y_or_n, context, 'Workspace %s/%s already exists. Overwrite?' % ( owner, name), 'Yes' if yes: # TODO: this doesn't set permissions on the workspace correctly self.remote_connect(context, host, owner, name, dir_to_share, utils.JOIN_ACTION.PROMPT) return prompt = 'Workspace %s/%s already exists. Choose new name: ' % ( owner, name)