Esempio n. 1
0
    def do_addattachment(self, zipname, filename, pagename, author=u"Scripting Subsystem", comment=u""):
        """
        Installs an attachment

        @param pagename: Page where the file is attached. Or in 2.0, the file itself.
        @param zipname: Filename of the attachment from the zip file
        @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
        """
        if self.request.user.may.write(pagename):
            _ = self.request.getText

            attachments = Page(self.request, pagename).getPagePath("attachments", check_create=1)
            filename = wikiutil.taintfilename(filename)
            zipname = wikiutil.taintfilename(zipname)
            target = os.path.join(attachments, filename)
            page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
            rev = page.current_rev()
            path = page.getPagePath(check_create=0)
            if not os.path.exists(target):
                self._extractToFile(zipname, target)
                if os.path.exists(target):
                    filesys.chmod(target, 0666 & config.umask)
                    action = 'ATTNEW'
                    edit_logfile_append(self, pagename, path, rev, action, logname='edit-log',
                                       comment=u'%(filename)s' % {"filename": filename}, author=author)
                self.msg += u"%(filename)s attached \n" % {"filename": filename}
            else:
                self.msg += u"%(filename)s not attached \n" % {"filename": filename}
        else:
            self.msg += u"action add attachment: not enough rights - nothing done \n"
Esempio n. 2
0
 def close(self):
     """ close cache file (and release lock, if any) """
     try:
         if self._fileobj:
             self._fileobj.close()
             self._fileobj = None
             if 'w' in self._mode:
                 filesys.chmod(self._tmp_fname, 0666 & config.umask) # fix mode that mkstemp chose
                 # this is either atomic or happening with real locks set:
                 filesys.rename(self._tmp_fname, self._fname)
     finally:
         if self.locking:
             self.unlock()
Esempio n. 3
0
    def do_replaceunderlayattachment(self, zipname, filename, pagename, author=u"Scripting Subsystem", comment=u""):
        """
        overwrite underlay attachments

        @param pagename: Page where the file is attached. Or in 2.0, the file itself.
        @param zipname: Filename of the attachment from the zip file
        @param filename: Filename of the attachment (just applicable for MoinMoin < 2.0)
        """
        if self.request.user.may.write(pagename):
            _ = self.request.getText
            filename = wikiutil.taintfilename(filename)
            zipname = wikiutil.taintfilename(zipname)
            page = PageEditor(self.request, pagename, do_editor_backup=0, uid_override=author)
            pagedir = page.getPagePath(use_underlay=1, check_create=1)
            attachments = os.path.join(pagedir, 'attachments')
            if not os.path.exists(attachments):
                os.mkdir(attachments)
            target = os.path.join(attachments, filename)
            self._extractToFile(zipname, target)
            if os.path.exists(target):
                filesys.chmod(target, 0666 & config.umask)
        else:
            self.msg += u"action replace underlay attachment: not enough rights - nothing done \n"