def check_and_join_workspace(self, args): if not self.start_ticker(): return workspace_url = args[0] self.set_globals() try: r = api.get_workspace_by_url(workspace_url) except Exception as e: return editor.error_message('Error joining %s: %s' % (workspace_url, str(e))) if r.code >= 400: return editor.error_message('Error joining %s: %s' % (workspace_url, r.body)) msg.debug('Workspace %s exists' % workspace_url) return self.join_workspace(workspace_url)
def _on_share_dir(self, data): utils.reload_settings() G.USERNAME = data['username'] G.SECRET = data['secret'] dir_to_share = data['dir_to_share'] perms = data.get('perms') dir_to_share = os.path.expanduser(dir_to_share) dir_to_share = utils.unfuck_path(dir_to_share) workspace_name = os.path.basename(dir_to_share) G.PROJECT_PATH = os.path.realpath(dir_to_share) msg.debug('%s %s %s' % (G.USERNAME, workspace_name, G.PROJECT_PATH)) if os.path.isfile(dir_to_share): return msg.error('%s is a file. Give me a directory please.' % dir_to_share) try: utils.mkdir(dir_to_share) except Exception: return msg.error( "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: msg.debug("Couldn't read the floo_info file: %s" % floo_file) workspace_url = info.get('url') if workspace_url: try: result = utils.parse_url(workspace_url) except Exception as e: msg.error(str(e)) else: workspace_name = result['workspace'] try: # TODO: blocking. beachballs sublime 2 if API is super slow api.get_workspace_by_url(workspace_url) except HTTPError: workspace_url = None workspace_name = os.path.basename(dir_to_share) else: utils.add_workspace_to_persistent_json( result['owner'], result['workspace'], workspace_url, dir_to_share) workspace_url = utils.get_workspace_by_path( dir_to_share) or workspace_url if workspace_url: try: api.get_workspace_by_url(workspace_url) except HTTPError: pass else: result = utils.parse_url(workspace_url) agent = self.remote_connect(result['owner'], result['workspace'], False) return agent.once("room_info", lambda: agent.upload(dir_to_share)) def on_done(data, choices=None): self._on_create_workspace({}, workspace_name, dir_to_share, owner=data.get('response'), perms=perms) orgs = api.get_orgs_can_admin() orgs = json.loads(orgs.read().decode('utf-8')) if len(orgs) == 0: return on_done({'response': G.USERNAME}) i = 0 choices = [] choices.append([G.USERNAME, i]) for o in orgs: i += 1 choices.append([o['name'], i]) self.get_input('Create workspace for (%s) ' % " ".join([x[0] for x in choices]), '', on_done, choices=choices)
def _on_share_dir(self, data): utils.reload_settings() G.USERNAME = data["username"] G.SECRET = data["secret"] dir_to_share = data["dir_to_share"] perms = data.get("perms") dir_to_share = os.path.expanduser(dir_to_share) dir_to_share = utils.unfuck_path(dir_to_share) workspace_name = os.path.basename(dir_to_share) G.PROJECT_PATH = os.path.realpath(dir_to_share) msg.debug("%s %s %s" % (G.USERNAME, workspace_name, G.PROJECT_PATH)) if os.path.isfile(dir_to_share): return msg.error("%s is a file. Give me a directory please." % dir_to_share) try: utils.mkdir(dir_to_share) except Exception: return msg.error("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: msg.debug("Couldn't read the floo_info file: %s" % floo_file) workspace_url = info.get("url") if workspace_url: try: result = utils.parse_url(workspace_url) except Exception as e: msg.error(str(e)) else: workspace_name = result["workspace"] try: # TODO: blocking. beachballs sublime 2 if API is super slow api.get_workspace_by_url(workspace_url) except HTTPError: workspace_url = None workspace_name = os.path.basename(dir_to_share) else: utils.add_workspace_to_persistent_json( result["owner"], result["workspace"], workspace_url, dir_to_share ) workspace_url = utils.get_workspace_by_path(dir_to_share) or workspace_url if workspace_url: try: api.get_workspace_by_url(workspace_url) except HTTPError: pass else: result = utils.parse_url(workspace_url) agent = self.remote_connect(result["owner"], result["workspace"], False) return agent.once("room_info", lambda: agent.upload(dir_to_share)) def on_done(data, choices=None): self._on_create_workspace({}, workspace_name, dir_to_share, owner=data.get("response"), perms=perms) orgs = api.get_orgs_can_admin() orgs = json.loads(orgs.read().decode("utf-8")) if len(orgs) == 0: return on_done({"response": G.USERNAME}) i = 0 choices = [] choices.append([G.USERNAME, i]) for o in orgs: i += 1 choices.append([o["name"], i]) self.get_input("Create workspace for (%s) " % " ".join([x[0] for x in choices]), "", on_done, choices=choices)