def __init__(self, workspace_url, on_auth=None, Protocol=None, get_bufs=True, conn=None): self.sock_q = Queue.Queue() self.sock = None self.net_buf = '' self.reconnect_delay = self.INITIAL_RECONNECT_DELAY self.reconnect_timeout = None self.username = G.USERNAME self.secret = G.SECRET self.authed = False G.JOINED_WORKSPACE = False self.retries = self.MAX_RETRIES self._on_auth = on_auth self.get_bufs = get_bufs self.empty_selects = 0 self.workspace_info = {} parsed = utils.parse_url(workspace_url) print(workspace_url, parsed) self.host = parsed['host'] self.port = parsed['port'] self.secure = parsed['secure'] self.owner = parsed['owner'] self.workspace = parsed['workspace'] self.conn = conn self.protocol = Protocol(self)
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)