示例#1
0
 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
示例#2
0
 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
示例#3
0
 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)
示例#4
0
 def get_item(self, itemname):
     try:
         return FileItem(self, itemname)
     except NoFileError:
         try:
             return DirItem(self, itemname)
         except NoDirError:
             raise NoSuchItemError()
示例#5
0
    def get_item(self, itemname):
        item_id = self._get_item_id(itemname)
        if item_id is None:
            raise NoSuchItemError("No such item '%r'." % itemname)

        item = Item(self, itemname)
        item._fs_item_id = item_id
        item._fs_metadata = None

        return item
示例#6
0
 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
示例#7
0
 def get_item(self, itemname):
     """
     @see: Backend.get_item.__doc__
     """
     session = self.Session()
     # The following fails if not EXACTLY one column is found, i.e., it also fails
     # if MORE than one item is found, which should not happen since names should be
     # unique.
     try:
         # Query for the item that matches the given itemname.
         item = session.query(SQLAItem).filter_by(_name=itemname).one()
         # SQLA doesn't call __init__, so we need to take care of that.
         item.setup(self)
         # Maybe somebody already got an instance of this Item and thus there already is a Lock for that Item.
         if not item.id in self._item_metadata_lock:
             self._item_metadata_lock[item.id] = Lock()
         return item
     except NoResultFound:
         raise NoSuchItemError("The item '%s' could not be found." % itemname)
     finally:
         session.close()
 def get_item(self, name):
     raise NoSuchItemError('should not be visible')
示例#9
0
    def get_item(self, itemname):
        item_id = self._get_item_id(itemname)
        if item_id is None:
            raise NoSuchItemError("No such item '%r'." % itemname)

        return Item(self, itemname, _fs_item_id=item_id)
示例#10
0
 def get_item(self, itemname):
     if not self._exists(itemname):
         raise NoSuchItemError("No such item, %r" % (itemname))
     return Item(self, itemname)