Example #1
0
    def load_tmp(self):
        """Load from slot path as TempFile."""
        # load line info
        linfos = LineInfo.load(self.path, self.ctx)
        return TempFile(self.ctx, self.path, linfos)

    def remove(self):
        os.remove(self.path)
        self._linfos.remove_saved(self.path)


class SlotMap(object):

    def __init__(self, ctx):
        self.ctx = ctx
        self._dict = dict()

    def __call__(self, userid, slotname):
        key = userid, slotname
        if key not in self._dict:
            name = NAMED_TMP_PREFIX + userid + '-' + slotname
            tmp_dir = get_tmp_dir()
            self._dict[key] = Slot(self.ctx, os.path.join(tmp_dir, name))
        return self._dict[key]


pctx = Property()
pctx.fields = {}
file_field = FileField(pctx)