Example #1
0
 def get_file_iter(self, root):
     try:
         return self.file_iter_cache[root]
     except KeyError:
         result = get_files(root, keep_top=len(get_projects()) > 1)
         self.file_iter_cache[root] = result
         return result
Example #2
0
 def get_file_iter(self, root):
     try:
         return self.file_iter_cache[root]
     except KeyError:
         result = get_files(root, keep_top=len(get_projects()) > 1)
         self.file_iter_cache[root] = result
         return result
Example #3
0
def changed_projects():
    changed = []
    for p in get_projects():
        if not os.path.exists(os.path.join(p, '.git')):
            continue

        proc = Popen(['git', 'status', '-b', '--porcelain'],
                     cwd=p,
                     stdout=PIPE,
                     stderr=PIPE)
        out, err = proc.communicate()

        if proc.returncode != 0:
            if err.strip():
                print(err)
            else:
                print('Git error', proc.returncode)
        else:
            for line in out.splitlines():
                if not line.startswith('##') or 'ahead' in line:
                    changed.append(p)
                    break

    if changed:
        print(', '.join(os.path.basename(r) for r in changed))
    else:
        echo('There are no any changes')
Example #4
0
def changed_projects():
    changed = []
    for p in get_projects():
        if not os.path.exists(os.path.join(p, '.git')):
            continue

        proc = Popen(['git', 'status', '-b', '--porcelain'],
                     cwd=p, stdout=PIPE, stderr=PIPE)
        out, err = proc.communicate()

        if proc.returncode != 0:
            if err.strip():
                print err
            else:
                print 'Git error', proc.returncode
        else:
            for line in out.splitlines():
                if not line.startswith('##') or 'ahead' in line:
                    changed.append(p)
                    break

    if changed:
        print ', '.join(os.path.basename(r) for r in changed)
    else:
        echo('There are no any changes')
Example #5
0
 def get_buffer_paths(self):
     projects = get_projects()
     multiple_projects = len(projects) > 1
     for b in vim.buffers:
         if buffer_with_file(b):
             fpath = b.name
             spath = strip_project_path(fpath, projects, multiple_projects)
             path, name = os.path.split(spath)
             yield (name, spath, '__buffer__',
                    '* ' + path, fpath)
Example #6
0
 def open(self):
     self.matcher.clear()
     self.bmatcher.clear()
     self.file_iter_cache.clear()
     self.bmatcher.extend(self.get_buffer_paths())
     self.last_window = vfunc.winnr()
     self.roots = get_projects()
     self.list_view.clear()
     self.show(u'')
     self.loop.enter()
Example #7
0
 def get_buffer_paths(self):
     projects = get_projects()
     multiple_projects = len(projects) > 1
     for b in vim.buffers:
         if buffer_with_file(b):
             fpath = b.name
             spath = strip_project_path(fpath, projects, multiple_projects)
             path, name = os.path.split(spath)
             yield (name, spath, '__buffer__',
                    '* ' + path, fpath)
Example #8
0
 def open(self):
     self.matcher.clear()
     self.bmatcher.clear()
     self.file_iter_cache.clear()
     self.bmatcher.extend(self.get_buffer_paths())
     self.last_window = vfunc.winnr()
     self.roots = get_projects()
     self.list_view.clear()
     self.show(u'')
     self.loop.enter()
Example #9
0
def grep(query):
    matcher = re.compile(re.escape(query))

    t = time() - 1
    result = []
    for r in get_projects():
        for name, path, root, top, fullpath in get_files(r):
            if time() - t >= 1:
                redraw()
                print fullpath
                t = time()

            try:
                if os.stat(fullpath).st_size > MAX_FILESIZE:
                    continue

                with open(fullpath) as f:
                    source = f.read()
                    matches = matcher.finditer(source)
                    lines = source.splitlines()
            except OSError:
                continue

            for m in matches:
                start = m.start()
                line = source.count('\n', 0, start) + 1
                offset = start - source.rfind('\n', 0, start)
                text = lines[line - 1]

                if len(text) > 100:
                    offstart = max(0, offset - 30)
                    text = text[offstart:offstart + 60] + '...'
                    if offstart:
                        text = '...' + text

                result.append({
                    'bufnr': '',
                    'filename': fullpath,
                    'pattern': '',
                    'valid': 1,
                    'nr': -1,
                    'lnum': line,
                    'vcol': 0,
                    'col': offset,
                    'text': text.replace('\x00', ' '),
                    'type': ''
                })

    vfunc.setqflist(result)

    if result:
        vim.command('cw')

    redraw()
    print '{} matches found'.format(len(result))
Example #10
0
def grep(query):
    matcher = re.compile(re.escape(query))

    t = time() - 1
    result = []
    for r in get_projects():
        for name, path, root, top, fullpath in get_files(r):
            if time() - t >= 1:
                redraw()
                print fullpath
                t = time()

            try:
                if os.stat(fullpath).st_size > MAX_FILESIZE:
                    continue

                with open(fullpath) as f:
                    source = f.read()
                    matches = matcher.finditer(source)
                    lines = source.splitlines()
            except OSError:
                continue

            for m in matches:
                start = m.start()
                line = source.count('\n', 0, start) + 1
                offset = start - source.rfind('\n', 0, start)
                text = lines[line - 1]

                if len(text) > 100:
                    offstart = max(0, offset - 30)
                    text = text[offstart:offstart+60] + '...'
                    if offstart:
                        text = '...' + text

                result.append({
                    'bufnr': '',
                    'filename': fullpath,
                    'pattern': '',
                    'valid': 1,
                    'nr': -1,
                    'lnum': line,
                    'vcol': 0,
                    'col': offset,
                    'text': text.replace('\x00', ' '),
                    'type': ''
                })

    vfunc.setqflist(result)

    if result:
        vim.command('cw')

    redraw()
    print '{} matches found'.format(len(result))
Example #11
0
def lint_all():
    t = time() - 1
    errors, warns = [], []
    for r in get_projects():
        for name, path, root, top, fullpath in get_files(r):
            if name.endswith('.py'):
                if time() - t >= 1:
                    redraw()
                    print fullpath
                    t = time()

                with open(fullpath) as f:
                    source = f.read()

                e, w = _lint(source, fullpath)
                errors += e
                warns += w

    show_lint_result(errors, warns)
Example #12
0
def lint_all():
    t = time() - 1
    errors, warns = [], []
    for r in get_projects():
        for name, path, root, top, fullpath in get_files(r):
            if name.endswith('.py'):
                if time() - t >= 1:
                    redraw()
                    print fullpath
                    t = time()

                with open(fullpath) as f:
                    source = f.read()

                e, w = _lint(source, fullpath)
                errors += e
                warns += w

    show_lint_result(errors, warns)