def reload(self): ''' Refresh the current S3 directory (prefix) listing. Force a refresh from the S3 filesystem to avoid using cached responses and missing recent changes. ''' import re self.columns = [] self.use_glob_matching = self.options.vds3_glob and re.search( r'[*?\[\]]', self.source.given) if not (self.use_glob_matching or self.source.fs.exists(self.source.given)): error(f'unable to open S3 path: {self.source.given}') for col in ( Column('name', getter=self.object_display_name), Column('type', getter=lambda _, row: row.get('type')), Column('size', type=int, getter=lambda _, row: row.get('Size')), Column('modtime', type=date, getter=lambda _, row: row.get('LastModified')), ): self.addColumn(col) super().reload()
def searchRegex(vd, sheet, moveCursor=False, reverse=False, **kwargs): 'Set row index if moveCursor, otherwise return list of row indexes.' def findMatchingColumn(sheet, row, columns, func): 'Find column for which func matches the displayed value in this row' for c in columns: if func(c.getDisplayValue(row)): return c vd.searchContext.update(kwargs) regex = kwargs.get("regex") if regex: vd.searchContext["regex"] = re.compile( regex, sheet.regex_flags()) or error('invalid regex: %s' % regex) regex = vd.searchContext.get("regex") or fail("no regex") columns = vd.searchContext.get("columns") if columns == "cursorCol": columns = [sheet.cursorCol] elif columns == "visibleCols": columns = tuple(sheet.visibleCols) elif isinstance(columns, Column): columns = [columns] if not columns: error('bad columns') searchBackward = vd.searchContext.get("backward") if reverse: searchBackward = not searchBackward matchingRowIndexes = 0 for rowidx in rotateRange(len(sheet.rows), sheet.cursorRowIndex, reverse=searchBackward): c = findMatchingColumn(sheet, sheet.rows[rowidx], columns, regex.search) if c: if moveCursor: sheet.cursorRowIndex = rowidx sheet.cursorVisibleColIndex = sheet.visibleCols.index(c) return else: matchingRowIndexes += 1 yield rowidx status('%s matches for /%s/' % (matchingRowIndexes, regex.pattern))
def moveFile(self, row, val): fn = row.name + row.ext newpath = os.path.join(val, fn) if not newpath.startswith('/'): newpath = os.path.join(self.source.resolve(), newpath) parent = Path(newpath).parent if parent.exists(): if not parent.is_dir(): error('destination %s not a directory' % parent) else: with contextlib.suppress(FileExistsError): os.makedirs(parent.resolve()) os.rename(row.resolve(), newpath) row.fqpn = newpath self.restat(row)
def createJoinedSheet(sheets, jointype=''): sheets[1:] or error("join requires more than 1 sheet") if jointype == 'append': return SheetConcat('&'.join(vs.name for vs in sheets), sources=sheets) elif jointype == 'extend': vs = copy(sheets[0]) vs.name = '+'.join(vs.name for vs in sheets) vs.reload = functools.partial(ExtendedSheet_reload, vs, sheets) vs.rows = tuple() # to induce reload on first push, see vdtui return vs else: return SheetJoin('+'.join(vs.name for vs in sheets), sources=sheets, jointype=jointype)