def __init__(self, backend, name): Item.__init__(self, backend, name) try: itemname, attachname = name.rsplit('/') except ValueError: # no '/' in there raise NoSuchItemError("No such attachment item, %r" % name) editlogpath = self._backend._get_item_path(itemname, 'edit-log') self._fs_current = 0 # attachments only have 1 revision with revno 0 self._fs_meta = {} # no attachment item level metadata self._fs_editlog = EditLog(editlogpath, idx=backend.idx) attachpath = self._backend._get_att_path(itemname, attachname) if not os.path.isfile(attachpath): # no attachment file means no item raise NoSuchItemError("No such attachment item, %r" % name) self._fs_attachname = attachname self._fs_attachpath = attachpath # fetch parent page's ACL as it protected the attachment also: try: parentpage = FsPageItem(backend, itemname) parent_current_rev = parentpage.get_revision(-1) acl = parent_current_rev._fs_meta.get(ACL) except (NoSuchItemError, NoSuchRevisionError): acl = None self._fs_parent_acl = acl self._syspages = backend._syspages uuid = backend.idx.content_uuid(name) self.uuid = self._fs_meta[UUID] = uuid
def __init__(self, backend, name): Item.__init__(self, backend, name) filepath = backend._item2path(name) try: self._fs_stat = os.stat(filepath) except OSError, err: raise NoSuchItemError("No such item, %r" % name)
def __init__(self, backend, itemname): Item.__init__(self, backend, itemname) currentpath = self._backend._current_path(itemname) editlogpath = self._backend._get_item_path(itemname, 'edit-log') self._fs_meta = { } # 'current' is the only page metadata and handled elsewhere try: current = int(open( currentpath, 'r').read().strip()) - 1 # new api is 0-based, old is 1-based except (OSError, IOError): # no current file means no item raise NoSuchItemError("No such item, %r" % itemname) except ValueError: # we have a current file, but its content is damaged raise # TODO: current = determine_current(revdir, editlog) self._fs_current = current self._fs_editlog = EditLog(editlogpath, idx=backend.idx) self._syspages = backend._syspages if backend.deleted_mode == DELETED_MODE_KILL: try: FsPageRevision(self, current) except NoSuchRevisionError: raise NoSuchItemError( 'deleted_mode wants killing/ignoring of page %r and its attachments' % itemname) uuid = backend.idx.content_uuid(itemname) self.uuid = self._fs_meta[UUID] = uuid
def __init__(self, backend, itemname=None, old_id=None): if itemname is not None: # get_item calls us with a new itemname (uuid) uuid = str(itemname) old_id = backend.idx.user_old_id(uuid=uuid) if not self.user_re.match(old_id): raise NoSuchItemError("userid does not match user_re") Item.__init__(self, backend, itemname) # itemname might be None still try: meta = self._parse_userprofile(old_id) except (OSError, IOError): # no current file means no item raise NoSuchItemError("No such item, %r" % itemname) self._fs_meta = meta = self._process_usermeta(meta) if itemname is None: # iteritems calls us without itemname, just with old_id uuid = backend.idx.user_uuid(name=meta['name'], old_id=old_id) itemname = unicode(uuid) Item.__init__(self, backend, itemname) # XXX init again, with itemname self.uuid = meta[UUID] = uuid
def get_item(self, name): return Item(self, name)
def iteritems(self): filenames = os.listdir(self._path) for filename in filenames: yield Item(self, self._unquote(filename))
def create_item(self, itemname): if not isinstance(itemname, (str, unicode)): raise TypeError("Item names must have string type, not %s" % (type(itemname))) elif self.has_item(itemname): raise ItemAlreadyExistsError("An Item with the name %r already exists!" % (itemname)) return Item(self, itemname)
def get_item(self, itemname): if not self._exists(itemname): raise NoSuchItemError("No such item, %r" % (itemname)) return Item(self, itemname)