示例#1
0
    def clean_merge(cls, item_from, item_to, safe=False, quick=True, **kwargs):
        kwargs.pop('asynchronous', None)  # fixme
        if safe and not cls.can_merge(item_from, item_to, quick=quick):
            raise OtherPageSaveError(
                item_from, 'Cannot merge %s with %s' % (item_from, item_to))

        cls.merge(item_from, item_to, **kwargs)
        if not item_from.isRedirectPage():
            try:
                item_from.editEntity(
                    {},
                    clear=True,
                    summary='Clearing item to prepare for redirect')
            except APIError as e:
                raise OtherPageSaveError(item_from, e)

            cls.merge(item_from, item_to)
    def save(self, *args, **kwargs):  # See Page.save().
        """
        Save page after validating the content.

        Trying to save any other content fails silently with a parameterless
        INDEX_TEMPLATE being saved.
        """
        if not self.has_valid_content():
            raise OtherPageSaveError(
                self, 'An IndexPage must consist only of a single call to '
                '{{%s}}.' % self.INDEX_TEMPLATE)
        kwargs['contentformat'] = 'text/x-wiki'
        kwargs['contentmodel'] = 'proofread-index'
        super().save(*args, **kwargs)
示例#3
0
 def handle(func, self, *args, **kwargs):
     do_async = kwargs.pop('asynchronous', False)
     callback = kwargs.pop('callback', None)
     err = None
     try:
         func(self, *args, **kwargs)
     # TODO: other "expected" error types to catch?
     except Error as edit_err:
         err = edit_err  # edit_err will be deleted in the end of the scope
         link = self.title(as_link=True)
         if do_async:
             pywikibot.error('page {} not saved due to {}\n'.format(
                 link, err))
         pywikibot.log('Error saving page {} ({})\n'.format(link, err),
                       exc_info=True)
         if not callback and not do_async:
             if isinstance(err, PageSaveRelatedError):
                 raise err
             raise OtherPageSaveError(self, err)
     if callback:
         callback(self, err)
示例#4
0
 def merge(cls, item_from, item_to, **kwargs):
     try:
         item_from.mergeInto(item_to, **kwargs)
     except APIError as e:
         raise OtherPageSaveError(item_from, e)