class FileStorageHelper(Piu): def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) self.filesdir = PowerDirPath(os.path.join(self.dbpath, 'files')) self.filesdir.todir() # print('piu build up...:\nfids:',self.get('fids:')) if not self.get('fids', None): self.add(fids=[]) if self.get('first_fid', T.NOT_EXISTS) == T.NOT_EXISTS: self.add(first_id='0') if not self.get('last_fid', None): self.add(last_fid=self.get('first_fid')) def add_fid(self, fid): fids = self.get('fids') fids.append(fid) self.add(last_fid=fid) self.add(fids=fids) def gen_fid(self): last_fid = int(self.get('last_fid')) last_fid = str(last_fid + 1) self.add(last_fid=last_fid) self.add_fid(last_fid) # print('new fids:',self.get('fids')) return last_fid def get_filepath(self, fid): # print(self.get('last_fid')) return self.filesdir / fid if fid in self.get('fids') else None def gen_filepath(self, fid): self.add_fid(fid) if not fid in self.get('fids') else None return self.filesdir / fid
def dir(self, name): path = self._truepath(name) p = PowerDirPath(path) p.todir() return p