def find_workspace(workspace_url): try: api.get_workspace_by_url(workspace_url) except HTTPError: try: result = utils.parse_url(workspace_url) d = utils.get_persistent_data() del d['workspaces'][result['owner']][result['name']] utils.update_persistent_data(d) except Exception as e: msg.debug(unicode(e)) return False on_room_info_waterfall.add(on_room_info_msg) on_room_info_waterfall.add(ignore.create_flooignore, dir_to_share) on_room_info_waterfall.add(Listener.create_buf, dir_to_share) return True
def floobits_check_and_join_workspace(workspace_url): 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 floobits_join_workspace(workspace_url)
def find_workspace(workspace_url): if ssl is False: # No ssl module (broken Sublime Text). Just behave as if the workspace exists. return True try: api.get_workspace_by_url(workspace_url) except HTTPError: try: result = utils.parse_url(workspace_url) d = utils.get_persistent_data() del d['workspaces'][result['owner']][result['name']] utils.update_persistent_data(d) except Exception as e: msg.debug(unicode(e)) return False on_room_info_waterfall.add(on_room_info_msg) on_room_info_waterfall.add(ignore.create_flooignore, dir_to_share) on_room_info_waterfall.add(Listener.create_buf, dir_to_share) return True
def find_workspace(workspace_url): r = api.get_workspace_by_url(workspace_url) if r.code < 400: return r try: result = utils.parse_url(workspace_url) d = utils.get_persistent_data() del d['workspaces'][result['owner']][result['name']] utils.update_persistent_data(d) except Exception as e: msg.debug(str_e(e))
def find_workspace(workspace_url): r = api.get_workspace_by_url(workspace_url) if r.code < 400: on_room_info_waterfall.add(ignore.create_flooignore, dir_to_share) on_room_info_waterfall.add(lambda: G.AGENT.upload(dir_to_share, on_room_info_msg)) return r try: result = utils.parse_url(workspace_url) d = utils.get_persistent_data() del d['workspaces'][result['owner']][result['name']] utils.update_persistent_data(d) except Exception as e: msg.debug(unicode(e)) return
def prejoin_workspace(self, workspace_url, dir_to_share, api_args): try: result = utils.parse_url(workspace_url) except Exception as e: msg.error(str_e(e)) return False host = result.get('host') if not api.get_basic_auth(host): raise ValueError( 'No auth credentials for %s. Please add a username and secret for %s in your ~/.floorc.json' % (host, host)) try: w = api.get_workspace_by_url(workspace_url) except Exception as e: editor.error_message('Error opening url %s: %s' % (workspace_url, str_e(e))) return False if w.code >= 400: try: d = utils.get_persistent_data() try: del d['workspaces'][result['owner']][result['name']] except Exception: pass try: del d['recent_workspaces'][workspace_url] except Exception: pass utils.update_persistent_data(d) except Exception as e: msg.debug(str_e(e)) return False msg.debug('workspace: ', json.dumps(w.body)) anon_perms = w.body.get('perms', {}).get('AnonymousUser', []) msg.debug('api args: ', api_args) new_anon_perms = api_args.get('perms', {}).get('AnonymousUser', []) # TODO: prompt/alert user if going from private to public if set(anon_perms) != set(new_anon_perms): msg.debug(str(anon_perms), str(new_anon_perms)) w.body['perms']['AnonymousUser'] = new_anon_perms response = api.update_workspace(workspace_url, w.body) msg.debug(str(response.body)) utils.add_workspace_to_persistent_json(w.body['owner'], w.body['name'], workspace_url, dir_to_share) return result
def prejoin_workspace(self, workspace_url, dir_to_share, api_args): try: result = utils.parse_url(workspace_url) except Exception as e: msg.error(str_e(e)) return False host = result.get("host") if not api.get_basic_auth(host): raise ValueError( "No auth credentials for %s. Please add a username and secret for %s in your ~/.floorc.json" % (host, host) ) try: w = api.get_workspace_by_url(workspace_url) except Exception as e: editor.error_message("Error opening url %s: %s" % (workspace_url, str_e(e))) return False if w.code >= 400: try: d = utils.get_persistent_data() try: del d["workspaces"][result["owner"]][result["name"]] except Exception: pass try: del d["recent_workspaces"][workspace_url] except Exception: pass utils.update_persistent_data(d) except Exception as e: msg.debug(str_e(e)) return False msg.debug("workspace: ", json.dumps(w.body)) anon_perms = w.body.get("perms", {}).get("AnonymousUser", []) msg.debug("api args: ", api_args) new_anon_perms = api_args.get("perms", {}).get("AnonymousUser", []) # TODO: prompt/alert user if going from private to public if set(anon_perms) != set(new_anon_perms): msg.debug(str(anon_perms), str(new_anon_perms)) w.body["perms"]["AnonymousUser"] = new_anon_perms response = api.update_workspace(workspace_url, w.body) msg.debug(str(response.body)) utils.add_workspace_to_persistent_json(w.body["owner"], w.body["name"], workspace_url, dir_to_share) return result
def share_dir(self, dir_to_share, perms=None): 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: return self.remote_connect(workspace_url, lambda this: this.protocol.create_buf(dir_to_share)) def on_done(data, choices=None): self.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 [press tab for completion]: ', '', on_done, choices=choices)
def on_input(self, dir_to_share): file_to_share = None dir_to_share = os.path.expanduser(dir_to_share) dir_to_share = os.path.realpath(utils.unfuck_path(dir_to_share)) workspace_name = os.path.basename(dir_to_share) print(G.COLAB_DIR, G.USERNAME, workspace_name) if os.path.isfile(dir_to_share): file_to_share = dir_to_share dir_to_share = os.path.dirname(dir_to_share) else: 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) workspace_url = info.get('url') try: result = utils.parse_url(workspace_url) except Exception: workspace_url = None 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: add_workspace_to_persistent_json(result['owner'], result['workspace'], workspace_url, dir_to_share) for owner, workspaces in utils.get_persistent_data()['workspaces'].items(): for name, workspace in workspaces.items(): if workspace['path'] == dir_to_share: workspace_url = workspace['url'] print('found workspace url', workspace_url) break if workspace_url: try: api.get_workspace_by_url(workspace_url) except HTTPError: pass else: on_room_info_waterfall.add(on_room_info_msg) on_room_info_waterfall.add(ignore.create_flooignore, dir_to_share) on_room_info_waterfall.add(Listener.create_buf, dir_to_share) return self.window.run_command('floobits_join_workspace', {'workspace_url': workspace_url}) # make & join workspace on_room_info_waterfall.add(ignore.create_flooignore, dir_to_share) on_room_info_waterfall.add(Listener.create_buf, file_to_share or dir_to_share) def on_done(owner): self.window.run_command('floobits_create_workspace', { 'workspace_name': workspace_name, 'dir_to_share': dir_to_share, 'api_args': self.api_args, 'owner': owner[0], }) orgs = api.get_orgs_can_admin() orgs = json.loads(orgs.read().decode('utf-8')) if len(orgs) == 0: return on_done([G.USERNAME]) orgs = [[org['name'], 'Create workspace under %s' % org['name']] for org in orgs] orgs.insert(0, [G.USERNAME, 'Create workspace under %s' % G.USERNAME]) self.window.show_quick_panel(orgs, lambda index: index < 0 or on_done(orgs[index]))