Ejemplo n.º 1
0
 def rename_buf(self, buf_id, new_path):
     new_path = utils.to_rel_path(new_path)
     self.agent.put({
         'name': 'rename_buf',
         'id': buf_id,
         'path': new_path,
     })
Ejemplo n.º 2
0
 def delete_buf(path):
     if not utils.is_shared(path):
         msg.error('Skipping deleting %s because it is not in shared path %s.' % (path, G.PROJECT_PATH))
         return
     if os.path.isdir(path):
         for dirpath, dirnames, filenames in os.walk(path):
             # TODO: rexamine this assumption
             # Don't care about hidden stuff
             dirnames[:] = [d for d in dirnames if d[0] != '.']
             for f in filenames:
                 f_path = os.path.join(dirpath, f)
                 if f[0] == '.':
                     msg.log('Not deleting buf for hidden file %s' % f_path)
                 else:
                     Listener.delete_buf(f_path)
         return
     buf_to_delete = None
     rel_path = utils.to_rel_path(path)
     for buf_id, buf in BUFS.items():
         if rel_path == buf['path']:
             buf_to_delete = buf
             break
     if buf_to_delete is None:
         msg.error('%s is not in this room' % path)
         return
     msg.log('deleting buffer ', rel_path)
     event = {
         'name': 'delete_buf',
         'id': buf_to_delete['id'],
     }
     Listener.agent.put(event)
Ejemplo n.º 3
0
 def create_buf(path):
     # >>> (lambda x: lambda: x)(2)()
     # TODO: check if functools can do this in st2
     #  really_create_buf = lambda x: (lambda: Listener.create_buf(x))
     def really_create_buf(x):
         return (lambda: Listener.create_buf(x))
     if not utils.is_shared(path):
         msg.error('Skipping adding %s because it is not in shared path %s.' % (path, G.PROJECT_PATH))
         return
     if os.path.isdir(path):
         for dirpath, dirnames, filenames in os.walk(path):
             # Don't care about hidden stuff
             dirnames[:] = [d for d in dirnames if d[0] != '.']
             for f in filenames:
                 f_path = os.path.join(dirpath, f)
                 if f[0] == '.':
                     msg.log('Not creating buf for hidden file %s' % f_path)
                 else:
                     sublime.set_timeout(really_create_buf(f_path), 0)
         return
     try:
         buf_fd = open(path, 'rb')
         buf = buf_fd.read().decode('utf-8')
         rel_path = utils.to_rel_path(path)
         msg.log('creating buffer ', rel_path)
         event = {
             'name': 'create_buf',
             'buf': buf,
             'path': rel_path,
         }
         Listener.agent.put(event)
     except (IOError, OSError):
         msg.error('Failed to open %s.' % path)
     except Exception as e:
         msg.error('Failed to create buffer %s: %s' % (path, str(e)))
Ejemplo n.º 4
0
 def on_emacs_rename_buf(self, req):
     buf = self.get_buf_by_path(req['old_path'])
     if not buf:
         msg.debug('No buffer for path %s' % req['old_path'])
         return
     self.rename_buf(buf['id'], req['path'])
     self.FLOO_BUFS[buf['id']]['path'] = utils.to_rel_path(req['path'])
Ejemplo n.º 5
0
    def delete_buf(self, path):
        """deletes a path"""

        if not path:
            return

        path = utils.get_full_path(path)

        if not self.is_shared(path):
            msg.error("Skipping deleting %s because it is not in shared path %s." % (path, G.PROJECT_PATH))
            return

        if os.path.isdir(path):
            for dirpath, dirnames, filenames in os.walk(path):
                # Don't care about hidden stuff
                dirnames[:] = [d for d in dirnames if d[0] != "."]
                for f in filenames:
                    f_path = os.path.join(dirpath, f)
                    if f[0] == ".":
                        msg.log("Not deleting buf for hidden file %s" % f_path)
                    else:
                        self.delete_buf(f_path)
            return
        buf_to_delete = None
        rel_path = utils.to_rel_path(path)
        for buf_id, buf in self.FLOO_BUFS.items():
            if rel_path == buf["path"]:
                buf_to_delete = buf
                break
        if buf_to_delete is None:
            msg.error("%s is not in this room" % path)
            return
        msg.log("deleting buffer ", rel_path)
        event = {"name": "delete_buf", "id": buf_to_delete["id"]}
        self.agent.put(event)
Ejemplo n.º 6
0
 def delete_buf(path):
     if not utils.is_shared(path):
         msg.error('Skipping deleting %s because it is not in shared path %s.' % (path, G.PROJECT_PATH))
         return
     if os.path.isdir(path):
         for dirpath, dirnames, filenames in os.walk(path):
             # TODO: rexamine this assumption
             # Don't care about hidden stuff
             dirnames[:] = [d for d in dirnames if d[0] != '.']
             for f in filenames:
                 f_path = os.path.join(dirpath, f)
                 if f[0] == '.':
                     msg.log('Not deleting buf for hidden file %s' % f_path)
                 else:
                     Listener.delete_buf(f_path)
         return
     buf_to_delete = None
     rel_path = utils.to_rel_path(path)
     for buf_id, buf in BUFS.items():
         if rel_path == buf['path']:
             buf_to_delete = buf
             break
     if buf_to_delete is None:
         msg.error('%s is not in this room' % path)
         return
     msg.log('deleting buffer ', rel_path)
     event = {
         'name': 'delete_buf',
         'id': buf_to_delete['id'],
     }
     Listener.agent.put(event)
Ejemplo n.º 7
0
def get_view(buf_id):
    buf = BUFS[buf_id]
    for view in G.ROOM_WINDOW.views():
        if not view.file_name():
            continue
        if buf['path'] == utils.to_rel_path(view.file_name()):
            return view
    return None
Ejemplo n.º 8
0
def get_view(buf_id):
    buf = BUFS[buf_id]
    for view in G.ROOM_WINDOW.views():
        if not view.file_name():
            continue
        if buf['path'] == utils.to_rel_path(view.file_name()):
            return view
    return None
Ejemplo n.º 9
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
Ejemplo n.º 10
0
def get_buf(view):
    if view.is_scratch():
        return None
    if not view.file_name():
        return None
    if view is G.CHAT_VIEW:
        return None
    rel_path = utils.to_rel_path(view.file_name())
    for buf_id, buf in BUFS.items():
        if rel_path == buf['path']:
            return buf
    return None
Ejemplo n.º 11
0
def get_buf(view):
    if view.is_scratch():
        return None
    if not view.file_name():
        return None
    if view is G.CHAT_VIEW:
        return None
    rel_path = utils.to_rel_path(view.file_name())
    for buf_id, buf in BUFS.items():
        if rel_path == buf['path']:
            return buf
    return None
Ejemplo n.º 12
0
    def create_buf(path, always_add=False):
        if not utils.is_shared(path):
            msg.error(
                'Skipping adding %s because it is not in shared path %s.' %
                (path, G.PROJECT_PATH))
            return
        if os.path.isdir(path):
            command = 'git ls-files %s' % path
            try:
                p = subprocess.Popen(command,
                                     stdout=subprocess.PIPE,
                                     stderr=subprocess.PIPE,
                                     shell=True,
                                     cwd=path)
                stdoutdata, stderrdata = p.communicate()
                if p.returncode == 0:
                    for git_path in stdoutdata.split('\n'):
                        git_path = git_path.strip()
                        if not git_path:
                            continue
                        add_path = os.path.join(path, git_path)
                        msg.debug('adding %s' % add_path)
                        utils.set_timeout(Listener.create_buf, 0, add_path)
                    return
            except Exception as e:
                msg.debug("Couldn't run %s. This is probably OK. Error: %s" %
                          (command, str(e)))

            for dirpath, dirnames, filenames in os.walk(path):
                # Don't care about hidden stuff
                dirnames[:] = [d for d in dirnames if d[0] != '.']
                for f in filenames:
                    f_path = os.path.join(dirpath, f)
                    if f[0] == '.':
                        msg.log('Not creating buf for hidden file %s' % f_path)
                    else:
                        utils.set_timeout(Listener.create_buf, 0, f_path)
            return
        try:
            buf_fd = open(path, 'rb')
            buf = buf_fd.read().decode('utf-8')
            rel_path = utils.to_rel_path(path)
            msg.log('creating buffer ', rel_path)
            event = {
                'name': 'create_buf',
                'buf': buf,
                'path': rel_path,
            }
            Listener.agent.put(event)
        except (IOError, OSError):
            msg.error('Failed to open %s.' % path)
        except Exception as e:
            msg.error('Failed to create buffer %s: %s' % (path, str(e)))
Ejemplo n.º 13
0
    def create_buf(path, always_add=False):
        if not utils.is_shared(path):
            msg.error('Skipping adding %s because it is not in shared path %s.' % (path, G.PROJECT_PATH))
            return
        if os.path.isdir(path):
            command = 'git ls-files %s' % path
            try:
                p = subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, shell=True, cwd=path)
                stdoutdata, stderrdata = p.communicate()
                if p.returncode == 0:
                    for git_path in stdoutdata.split('\n'):
                        git_path = git_path.strip()
                        if not git_path:
                            continue
                        add_path = os.path.join(path, git_path)
                        msg.debug('adding %s' % add_path)
                        utils.set_timeout(Listener.create_buf, 0, add_path)
                    return
            except Exception as e:
                msg.debug("Couldn't run %s. This is probably OK. Error: %s" % (command, str(e)))

            for dirpath, dirnames, filenames in os.walk(path):
                # Don't care about hidden stuff
                dirnames[:] = [d for d in dirnames if d[0] != '.']
                for f in filenames:
                    f_path = os.path.join(dirpath, f)
                    if f[0] == '.':
                        msg.log('Not creating buf for hidden file %s' % f_path)
                    else:
                        utils.set_timeout(Listener.create_buf, 0, f_path)
            return
        try:
            buf_fd = open(path, 'rb')
            buf = buf_fd.read().decode('utf-8')
            rel_path = utils.to_rel_path(path)
            msg.log('creating buffer ', rel_path)
            event = {
                'name': 'create_buf',
                'buf': buf,
                'path': rel_path,
            }
            Listener.agent.put(event)
        except (IOError, OSError):
            msg.error('Failed to open %s.' % path)
        except Exception as e:
            msg.error('Failed to create buffer %s: %s' % (path, str(e)))
Ejemplo n.º 14
0
    def get_buf(self, vim_buf):
        """None- no sharing, False- should be but isn't """
        if vim_buf.name is None:
            msg.debug('get:buf buffer has no filename')
            return None

        if not self.is_shared(vim_buf.name):
            msg.debug('get_buf: %s is not shared' % vim_buf.name)
            return None

        rel_path = utils.to_rel_path(vim_buf.name)
        for buf_id, buf in self.FLOO_BUFS.iteritems():
            if rel_path == buf['path']:
                return buf

        msg.debug('get_buf: no buf has path %s' % rel_path)
        return False
Ejemplo n.º 15
0
    def get_buf(self, vim_buf):
        """None- no sharing, False- should be but isn't """
        if vim_buf.name is None:
            msg.debug('get:buf buffer has no filename')
            return None

        if not self.is_shared(vim_buf.name):
            msg.debug('get_buf: %s is not shared' % vim_buf.name)
            return None

        rel_path = utils.to_rel_path(vim_buf.name)
        for buf_id, buf in self.FLOO_BUFS.iteritems():
            if rel_path == buf['path']:
                return buf

        msg.debug('get_buf: no buf has path %s' % rel_path)
        return False
Ejemplo n.º 16
0
    def create_buf(self, path, text=None):
        if 'create_buf' not in self.perms:
            msg.error("Skipping %s. You don't have permission to create buffers in this room." % path)
            return
        if not self.is_shared(path):
            msg.error('Skipping adding %s because it is not in shared path %s.' % (path, G.PROJECT_PATH))
            return
        if os.path.isdir(path):
            for dirpath, dirnames, filenames in os.walk(path):
                # Don't care about hidden stuff
                dirnames[:] = [d for d in dirnames if d[0] != '.']
                for f in filenames:
                    f_path = os.path.join(dirpath, f)
                    if f[0] == '.':
                        msg.log('Not creating buf for hidden file %s' % f_path)
                        continue
                    if f in self.ignored_names:
                        # TODO: prompt instead of being lame
                        msg.log('Not creating buf for ignored file %s' % f_path)
                        continue
                    sublime.set_timeout(self.create_buf, 0, f_path)
            return

        if self.get_buf_by_path(path):
            msg.debug('Buf %s already exists in room. Skipping adding.' % path)
            return

        try:
            if text is None:
                buf_fd = open(path, 'rb')
                text = buf_fd.read().decode('utf-8')
            rel_path = utils.to_rel_path(path)
            msg.debug('creating buffer ', rel_path)
            event = {
                'name': 'create_buf',
                'buf': text,
                'path': rel_path,
            }
            self.agent.put(event)
        except (IOError, OSError):
            msg.error('Failed to open %s.' % path)
        except Exception as e:
            msg.error('Failed to create buffer %s: %s' % (path, str(e)))
Ejemplo n.º 17
0
    def create_buf(self, path):
        if 'create_buf' not in self.perms:
            msg.error("Skipping %s. You don't have permission to create buffers in this room." % path)
            return
        if not self.is_shared(path):
            msg.error('Skipping adding %s because it is not in shared path %s.' % (path, G.PROJECT_PATH))
            return
        if os.path.isdir(path):
            for dirpath, dirnames, filenames in os.walk(path):
                # Don't care about hidden stuff
                dirnames[:] = [d for d in dirnames if d[0] != '.']
                for f in filenames:
                    f_path = os.path.join(dirpath, f)
                    if f[0] == '.':
                        msg.log('Not creating buf for hidden file %s' % f_path)
                    if f in self.ignored_names:
                        # TODO: prompt instead of being lame
                        msg.log('Not creating buf for ignored file %s' % f_path)
                    else:
                        sublime.set_timeout(self.create_buf, 0, f_path)
            return

        if self.get_buf_by_path(path):
            msg.debug('Buf %s already exists in room. Skipping adding.' % path)
            return

        try:
            buf_fd = open(path, 'rb')
            buf = buf_fd.read().decode('utf-8')
            rel_path = utils.to_rel_path(path)
            msg.debug('creating buffer ', rel_path)
            event = {
                'name': 'create_buf',
                'buf': buf,
                'path': rel_path,
            }
            self.agent.put(event)
        except (IOError, OSError):
            msg.error('Failed to open %s.' % path)
        except Exception as e:
            msg.error('Failed to create buffer %s: %s' % (path, str(e)))
Ejemplo n.º 18
0
    def create_buf(self, path, force=False):
        if G.SPARSE_MODE and not force:
            msg.debug("Skipping %s because user enabled sparse mode." % path)
            return
        if "create_buf" not in self.perms:
            msg.error("Skipping %s. You don't have permission to create buffers in this room." % path)
            return
        if not self.is_shared(path):
            msg.error("Skipping adding %s because it is not in shared path %s." % (path, G.PROJECT_PATH))
            return
        if os.path.isdir(path):
            for dirpath, dirnames, filenames in os.walk(path):
                # Don't care about hidden stuff
                dirnames[:] = [d for d in dirnames if d[0] != "."]
                for f in filenames:
                    f_path = os.path.join(dirpath, f)
                    if f[0] == ".":
                        msg.log("Not creating buf for hidden file %s" % f_path)
                        continue
                    if f in self.ignored_names:
                        # TODO: prompt instead of being lame
                        msg.log("Not creating buf for ignored file %s" % f_path)
                        continue
                    sublime.set_timeout(self.create_buf, 0, f_path, force)
            return

        if self.get_buf_by_path(path):
            msg.debug("Buf %s already exists in room. Skipping adding." % path)
            return

        try:
            buf_fd = open(path, "rb")
            buf = buf_fd.read().decode("utf-8")
            rel_path = utils.to_rel_path(path)
            msg.debug("creating buffer ", rel_path)
            event = {"name": "create_buf", "buf": buf, "path": rel_path}
            self.agent.put(event)
        except (IOError, OSError):
            msg.error("Failed to open %s." % path)
        except Exception as e:
            msg.error("Failed to create buffer %s: %s" % (path, str(e)))
Ejemplo n.º 19
0
    def on_post_save(self, view):
        def cleanup():
            del self.between_save_events[view.buffer_id()]
        if view == G.CHAT_VIEW or view.file_name() == G.CHAT_VIEW_PATH:
            return cleanup()
        else:
            print(G.CHAT_VIEW_PATH, "not", view.file_name())
        event = None
        buf = get_buf(view)
        name = utils.to_rel_path(view.file_name())
        old_name = self.between_save_events[view.buffer_id()]

        if buf is None:
            if utils.is_shared(view.file_name()):
                msg.log('new buffer ', name, view.file_name())
                event = {
                    'name': 'create_buf',
                    'buf': get_text(view),
                    'path': name
                }
        elif name != old_name:
            if utils.is_shared(view.file_name()):
                msg.log('renamed buffer {0} to {1}'.format(old_name, name))
                event = {
                    'name': 'rename_buf',
                    'id': buf['id'],
                    'path': name
                }
            else:
                msg.log('deleting buffer from shared: {0}'.format(name))
                event = {
                    'name': 'delete_buf',
                    'id': buf['id'],
                }

        if event and Listener.agent:
            Listener.agent.put(event)

        cleanup()
Ejemplo n.º 20
0
    def on_post_save(self, view):
        def cleanup():
            del self.between_save_events[view.buffer_id()]
        if view == G.CHAT_VIEW or view.file_name() == G.CHAT_VIEW_PATH:
            return cleanup()
        else:
            print(G.CHAT_VIEW_PATH, "not", view.file_name())
        event = None
        buf = get_buf(view)
        name = utils.to_rel_path(view.file_name())
        old_name = self.between_save_events[view.buffer_id()]

        if buf is None:
            if utils.is_shared(view.file_name()):
                msg.log('new buffer ', name, view.file_name())
                event = {
                    'name': 'create_buf',
                    'buf': get_text(view),
                    'path': name
                }
        elif name != old_name:
            if utils.is_shared(view.file_name()):
                msg.log('renamed buffer {0} to {1}'.format(old_name, name))
                event = {
                    'name': 'rename_buf',
                    'id': buf['id'],
                    'path': name
                }
            else:
                msg.log('deleting buffer from shared: {0}'.format(name))
                event = {
                    'name': 'delete_buf',
                    'id': buf['id'],
                }

        if event and Listener.agent:
            Listener.agent.put(event)

        cleanup()
Ejemplo n.º 21
0
 def get_vim_buf_by_path(self, p):
     for vim_buf in vim.buffers:
         if vim_buf.name and p == utils.to_rel_path(vim_buf.name):
             return vim_buf
     return None
Ejemplo n.º 22
0
 def get_vim_buf_by_path(self, p):
     for vim_buf in vim.buffers:
         if vim_buf.name and p == utils.to_rel_path(vim_buf.name):
             return vim_buf
     return None
Ejemplo n.º 23
0
 def get_buf_by_path(self, path):
     rel_path = utils.to_rel_path(path)
     for buf_id, buf in self.FLOO_BUFS.iteritems():
         if rel_path == buf['path']:
             return buf
     return None
Ejemplo n.º 24
0
 def on_pre_save(self, view):
     p = view.name()
     if view.file_name():
         p = utils.to_rel_path(view.file_name())
     self.between_save_events[view.buffer_id()] = p
Ejemplo n.º 25
0
 def on_pre_save(self, view):
     p = view.name()
     if view.file_name():
         p = utils.to_rel_path(view.file_name())
     self.between_save_events[view.buffer_id()] = p