コード例 #1
0
ファイル: vds3.py プロジェクト: ajkerrigan/visidata-plugins
    def reload(self):
        """Reload the current S3 directory (prefix) listing."""
        self.columns = []

        if not (
            self.use_glob_matching
            or self.fs.exists(self.source.given)
            or self.fs.isdir(self.source.given)
        ):
            vd.fail(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)

        if self.version_aware:
            self.addColumn(
                Column("latest", type=bool, getter=lambda _, row: row.get("IsLatest"))
            )
            self.addColumn(
                Column(
                    "version_id",
                    type=str,
                    getter=lambda _, row: row.get("VersionId"),
                    width=0,
                )
            )

        super().reload()
コード例 #2
0
def remove(vd, vs):
    if vs in vd.sheets:
        vd.sheets.remove(vs)
        if vs in vd.allSheets:
            vd.allSheets.remove(vs)
            vd.allSheets.append(vs)
    else:
        vd.fail('sheet not on stack')
コード例 #3
0
ファイル: box.py プロジェクト: devottys/darkdraw
 def reverse(self):
     if not self.scr: return
     for y in range(self.y1, self.y2):
         for x in range(self.x1, self.x2):
             try:
                 self.scr.chgat(
                     y, x, 1,
                     screen_contents.get((x, y),
                                         (0, 0))[1] | curses.A_REVERSE)
             except curses.error:
                 vd.fail(y, x)
コード例 #4
0
def getCommand(self, keystrokes_or_longname):
    longname = vd.bindkeys._get(keystrokes_or_longname)
    try:
        if longname:
            return vd.commands._get(longname) or vd.fail(
                'no command "%s"' % longname)
        else:
            return vd.commands._get(keystrokes_or_longname) or vd.fail(
                'no binding for %s' % keystrokes_or_longname)
    except Exception as exc:
        return None
コード例 #5
0
def moveVisibleCol(sheet, fromVisColIdx, toVisColIdx):
    'Move visible column to another visible index in sheet.'
    if 0 <= toVisColIdx < sheet.nVisibleCols:
        fromVisColIdx = min(max(fromVisColIdx, 0), sheet.nVisibleCols-1)
        fromColIdx = sheet.columns.index(sheet.visibleCols[fromVisColIdx])
        # a regular column cannot move to the left of keycols
        if toVisColIdx <= 0:
            toColIdx = sheet.columns.index(sheet.nonKeyVisibleCols[toVisColIdx])
        else:
            toColIdx = sheet.columns.index(sheet.visibleCols[toVisColIdx])
        moveListItem(sheet.columns, fromColIdx, toColIdx)
        return toVisColIdx
    else:
        vd.fail('already at edge')
コード例 #6
0
def addRegexColumns(regexMaker, vs, colIndex, origcol, regexstr):
    regexstr or vd.fail('regex required')

    regex = re.compile(regexstr, vs.regex_flags())

    func = regexMaker(regex, origcol)

    n = options.default_sample_size
    if n and n < len(vs.rows):
        exampleRows = random.sample(vs.rows, max(
            0, n - 1))  # -1 to account for included cursorRow
    else:
        exampleRows = vs.rows

    ncols = 0  # number of new columns added already
    for r in Progress(exampleRows + [vs.cursorRow]):
        try:
            m = func(r)
            if not m:
                continue
        except Exception as e:
            vd.exceptionCaught(e)

        for _ in range(len(m) - ncols):
            c = Column(
                origcol.name + '_re' + str(ncols),
                getter=lambda col, row, i=ncols, func=func: func(row)[i],
                origCol=origcol)
            vs.addColumn(c, index=colIndex + ncols + 1)
            ncols += 1
コード例 #7
0
def undo(vd, sheet):
    if not options.undo:
        vd.fail("options.undo not enabled")

    # don't allow undo of first command on a sheet, which is always the command that created the sheet.
    for cmdlogrow in sheet.cmdlog_sheet.rows[:0:-1]:
        if cmdlogrow.undofuncs:
            for undofunc, args, kwargs, in cmdlogrow.undofuncs:
                undofunc(*args, **kwargs)
            sheet.undone.append(cmdlogrow)
            sheet.cmdlog_sheet.rows.remove(cmdlogrow)
            vd.moveToReplayContext(cmdlogrow)
            vd.clearCaches()
            vd.status("%s undone" % cmdlogrow.longname)
            return

    vd.fail("nothing to undo on current sheet")
コード例 #8
0
def to_entries(col):
    '''
    Convert values from a dict into a list of Key/Value pairs, similar
    to the to_entries function in jq:

    Abort if the specified column's value for any row is _not_ a dict.
    '''
    sheet = col.sheet
    rows = sheet.rows

    new_idx = sheet.columns.index(col) + 1
    new_col = sheet.addColumn(SettableColumn(col.name), index=new_idx)
    isNull = isNullFunc()
    for r in rows:
        val = col.getValue(r)
        if isNull(val):
            continue
        if not isinstance(val, dict):
            sheet.columns.pop(new_idx)
            vd.fail('Column "{}" is not a dict'.format(col.name))
        new_col.setValue(r, [{'Key': k, 'Value': v} for k, v in val.items()])
    col.hide()
    return new_col
コード例 #9
0
    def __init__(self, name='', *, type=anytype, cache=False, **kwargs):
        self.sheet = None  # owning Sheet, set in .recalc() via Sheet.addColumn
        self.name = name  # display visible name
        self.fmtstr = ''  # by default, use str()
        self._type = type  # anytype/str/int/float/date/func
        self.getter = lambda col, row: row
        self.setter = lambda col, row, value: vd.fail(
            col.name + ' column cannot be changed')
        self.width = None  # == 0 if hidden, None if auto-compute next time
        self.height = 1  # max height, None/0 to auto-compute for each row
        self.keycol = 0  # keycol index (or 0 if not key column)
        self.expr = None  # Column-type-dependent parameter

        self.setCache(cache)
        for k, v in kwargs.items():
            setattr(
                self, k, v
            )  # instead of __dict__.update(kwargs) to invoke property.setters
コード例 #10
0
 def openRow(self, row):
     vd.fail(f'cannot open {self.rowtype} on this sheet')
コード例 #11
0
 def _die():
     sheet.columns.pop(new_idx)
     vd.fail(f'Columns {col.name} is not a list of Key/Value pairs')
コード例 #12
0
def someSelectedRows(self):
    if self.nSelected == 0:
        vd.fail('no rows selected')
    return self.selectedRows
コード例 #13
0
 def iterload(self):
     'Override this generator for loading.'
     if False:
         yield vd.fail('no iterload for this loader yet')
コード例 #14
0
def redo(vd, sheet):
    sheet.undone or vd.fail("nothing to redo")
    cmdlogrow = sheet.undone.pop()
    vd.replayOne(cmdlogrow)
    vd.status("%s redone" % cmdlogrow.longname)
コード例 #15
0
 def putValue(self, row, value):
     subrow = self.subfunc(row, self.expr)
     if subrow is None:
         vd.fail('no source row')
     self.origcol.setValue(subrow, value)
コード例 #16
0
 def __init__(self, frame):
     frame = normalize_container(frame)
     if not isinstance(frame, Frame):
         vd.fail('%s is not a StaticFrame Frame' % type(frame).__name__)
     self.frame = frame
コード例 #17
0
 def column(self, colname):
     'Return first column whose Column.name matches colname.'
     return self.colsByName.get(colname) or vd.fail('no column matching "%s"' % colname)