Esempio n. 1
0
def get_workspace_window(abs_path):
    workspace_window = None
    for w in sublime.windows():
        for f in w.folders():
            if utils.unfuck_path(f) == utils.unfuck_path(abs_path):
                workspace_window = w
                break
    return workspace_window
Esempio n. 2
0
def get_workspace_window(abs_path):
    workspace_window = None
    for w in sublime.windows():
        for f in w.folders():
            if utils.unfuck_path(f) == utils.unfuck_path(abs_path):
                workspace_window = w
                break
    return workspace_window
Esempio n. 3
0
 def finish(w):
     folders = []
     project_data = w.project_data() or {}
     try:
         folders = project_data.get('folders', [])
     except Exception:
         pass
     p = utils.unfuck_path(abs_path)
     if not [utils.unfuck_path(f.get('path')) == p for f in folders]:
         folders.insert(0, {'path': abs_path})
     project_data['folders'] = folders
     w.set_project_data(project_data)
     cb(w)
Esempio n. 4
0
def get_workspace_window(abs_path):
    found = False
    workspace_window = None
    unfucked_path = utils.unfuck_path(abs_path)
    for w in sublime.windows():
        for f in w.folders():
            if utils.unfuck_path(f) == unfucked_path:
                workspace_window = w
                found = True
                break
        if found:
            break
    return workspace_window
Esempio n. 5
0
 def finish(w):
     folders = []
     project_data = w.project_data() or {}
     try:
         folders = project_data.get('folders', [])
     except Exception:
         pass
     p = utils.unfuck_path(abs_path)
     if not [utils.unfuck_path(f.get('path')) == p for f in folders]:
         folders.insert(0, {'path': abs_path})
     project_data['folders'] = folders
     w.set_project_data(project_data)
     cb(w)
Esempio n. 6
0
def get_workspace_window(abs_path):
    found = False
    workspace_window = None
    unfucked_path = utils.unfuck_path(abs_path)
    for w in sublime.windows():
        for f in w.folders():
            if utils.unfuck_path(f) == unfucked_path:
                workspace_window = w
                found = True
                break
        if found:
            break
    return workspace_window
Esempio n. 7
0
 def is_shared(self, p):
     if not self.agent.is_ready():
         msg.debug('agent is not ready. %s is not shared' % p)
         return False
     p = utils.unfuck_path(p)
     # TODO: tokenize on path seps and then look for ..
     if utils.to_rel_path(p).find("../") == 0:
         return False
     return True
    def _on_share_dir(self, data):
        file_to_share = None
        utils.reload_settings()
        G.USERNAME = data['username']
        G.SECRET = data['secret']
        dir_to_share = data['dir_to_share']
        perms = data['perms']
        editor.line_endings = data['line_endings'].find(
            "unix") >= 0 and "\n" or "\r\n"
        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):
            file_to_share = dir_to_share
            dir_to_share = os.path.dirname(dir_to_share)

        try:
            utils.mkdir(dir_to_share)
        except Exception:
            return msg.error(
                "The directory %s doesn't exist and I can't create 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 as e:
            msg.warn("Couldn't read .floo file: %s: %s" % (floo_file, str(e)))

        workspace_url = info.get('url')
        if workspace_url:
            parsed_url = api.prejoin_workspace(workspace_url, dir_to_share,
                                               {'perms': perms})
            if parsed_url:
                # TODO: make sure we create_flooignore
                # utils.add_workspace_to_persistent_json(parsed_url['owner'], parsed_url['workspace'], workspace_url, dir_to_share)
                agent = self.remote_connect(parsed_url['owner'],
                                            parsed_url['workspace'], False)
                return agent.once(
                    "room_info",
                    lambda: agent.upload(file_to_share or dir_to_share))

        parsed_url = utils.get_workspace_by_path(
            dir_to_share, lambda workspace_url: api.prejoin_workspace(
                workspace_url, dir_to_share, {'perms': perms}))
        if parsed_url:
            agent = self.remote_connect(parsed_url['owner'],
                                        parsed_url['workspace'], False)
            return agent.once(
                "room_info",
                lambda: agent.upload(file_to_share or dir_to_share))

        def on_done(data, choices=None):
            self.get_input('Workspace name:',
                           workspace_name,
                           self._on_create_workspace,
                           workspace_name,
                           dir_to_share,
                           owner=data.get('response'),
                           perms=perms)

        try:
            r = api.get_orgs_can_admin()
        except IOError as e:
            return editor.error_message('Error getting org list: %s' % str(e))
        if r.code >= 400 or len(r.body) == 0:
            return on_done({'response': G.USERNAME})
        i = 0
        choices = []
        choices.append([G.USERNAME, i])
        for org in r.body:
            i += 1
            choices.append([org['name'], i])

        self.get_input('Create workspace owned by (%s) ' %
                       " ".join([x[0] for x in choices]),
                       '',
                       on_done,
                       choices=choices)
Esempio n. 9
0
    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)
Esempio n. 10
0
    def _on_share_dir(self, data):
        file_to_share = None
        utils.reload_settings()
        G.USERNAME = data['username']
        G.SECRET = data['secret']
        dir_to_share = data['dir_to_share']
        perms = data['perms']
        editor.line_endings = data['line_endings'].find("unix") >= 0 and "\n" or "\r\n"
        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):
            file_to_share = dir_to_share
            dir_to_share = os.path.dirname(dir_to_share)

        try:
            utils.mkdir(dir_to_share)
        except Exception:
            return msg.error("The directory %s doesn't exist and I can't create 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 as e:
            msg.warn("Couldn't read .floo file: %s: %s" % (floo_file, str(e)))

        workspace_url = info.get('url')
        if workspace_url:
            parsed_url = api.prejoin_workspace(workspace_url, dir_to_share, {'perms': perms})
            if parsed_url:
                # TODO: make sure we create_flooignore
                # utils.add_workspace_to_persistent_json(parsed_url['owner'], parsed_url['workspace'], workspace_url, dir_to_share)
                agent = self.remote_connect(parsed_url['owner'], parsed_url['workspace'], False)
                return agent.once("room_info", lambda: agent.upload(file_to_share or dir_to_share))

        parsed_url = utils.get_workspace_by_path(dir_to_share,
                                                 lambda workspace_url: api.prejoin_workspace(workspace_url, dir_to_share, {'perms': perms}))
        if parsed_url:
            agent = self.remote_connect(parsed_url['owner'], parsed_url['workspace'], False)
            return agent.once("room_info", lambda: agent.upload(file_to_share or dir_to_share))

        def on_done(data, choices=None):
            self.get_input('Workspace name:',
                           workspace_name,
                           self._on_create_workspace,
                           workspace_name,
                           dir_to_share,
                           owner=data.get('response'),
                           perms=perms)

        try:
            r = api.get_orgs_can_admin()
        except IOError as e:
            return editor.error_message('Error getting org list: %s' % str(e))
        if r.code >= 400 or len(r.body) == 0:
            return on_done({'response': G.USERNAME})
        i = 0
        choices = []
        choices.append([G.USERNAME, i])
        for org in r.body:
            i += 1
            choices.append([org['name'], i])

        self.get_input('Create workspace owned by (%s) ' % " ".join([x[0] for x in choices]), '', on_done, choices=choices)
Esempio n. 11
0
    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)