def OnGetItem(self, n):
     """callback to display item"""
     try:
         return self.blog.get_blog(n).html()
     except IndexError, err:
         display_error(_('Could not get blog.'), error=err)
         return "<p>Corrupted Blog</p>"
 def OnGetItem(self, n):
     """callback to display item"""
     assert get_facade(), "Facade not initialiazed"
     try:
         return get_facade()._desc.blog.get_blog(n).html()
     except IndexError, err:
         display_error(_('Could not get blog.'), error=err)
         return "<p>Corrupted Blog</p>"
Beispiel #3
0
 def add_comment(self, index, text, author=None, date=None):
     """get blog at given index and delegate add_comment to it"""
     try:
         blog = self.get_blog(index)
         blog.add_comment(text, author, date)
     except IndexError, err:
         display_error(_("Could not add comment: blog not valid"),
                       error=err)
Beispiel #4
0
 def _on_complete_pickle(self, donwload_msg):
     """callback when finished downloading blog"""
     log("_on_complete_pickle: ", self.peer.peer_id)
     try:
         return pickle.load(donwload_msg.file)
     except Exception, err:
         display_error(
             _(
                 "Your version of Solipsis is not compatible "
                 "with the peer'sone you wish to download from "
                 "Make sure you both use the latest (%s)" % VERSION
             ),
             title="Download error",
             error=err,
         )
 def select_files(self, peer_id, deferred=None):
     """request downwload of list of shared files"""
     on_done = self.network.get_shared_files(peer_id)
     if on_done != None:
         on_done.addCallback(self._on_shared_files, peer_id)
         on_done.addErrback(lambda x: display_error("Could not get shared files: " + str(x)))
         deferred and on_done.chainDeferred(deferred)
 def get_blog_file(self, peer_id, deferred=None):
     """request downwload of blog"""
     on_done = self.network.get_blog_file(peer_id)
     if on_done != None:
         on_done.addCallback(self._on_new_blog, peer_id)
         on_done.addErrback(lambda x: display_error("Could not get blog: " + str(x)))
         deferred and on_done.chainDeferred(deferred)
 def fill_shared_files(self, peer_id, files, flag_update=True):
     """connect shared files with shared files"""
     if not isinstance(files, SharedFiles):
         raise TypeError("data expected as SharedFiles")
     assert self.has_peer(peer_id), "no profile for %s in %s"\
            % (peer_id, self.__class__)
     peer_desc = self.get_peer(peer_id)
     # set repositories
     for repo in files:
         # do not check validity of path since files are located on
         # remote computer => checked=False
         try:
             peer_desc.document.add_repository(repo, checked=False)
         except ContainerException, err:
             display_error(_("Could not import directory %s"% repo),
                           title=_("Partial import"),
                           error=err)
 def import_document(self, other_document):
     """copy data from another document into self"""
     try:
         # others' data
         self.reset_peers()
         peers = other_document.get_peers()
         for peer_id, peer_desc in peers.iteritems():
             self.set_peer(peer_id,
                           PeerDescriptor(peer_id,
                                          document=peer_desc.document,
                                          blog=peer_desc.blog,
                                          state=peer_desc.state))
     except TypeError, err:
         display_error(_("Could not import Profile: "
                         "no contacts impmorted"),
                       title=_("Profile Corrupted"),
                       error=err)
 def import_document(self, other_document):
     """copy data from another document into self"""
     try:
         # personal data (unicode)
         self.set_pseudo(other_document.get_pseudo())
         self.set_title(other_document.get_title())
         self.set_firstname(other_document.get_firstname())
         self.set_lastname(other_document.get_lastname())
         self.set_photo(other_document.get_photo())
         self.set_email(other_document.get_email())
         # custom data
         attributes = other_document.get_custom_attributes()
         for key, val in attributes.iteritems():
             self.add_custom_attributes(key, val)
     except TypeError, err:
         display_error(_("Could not import Profile: "
                         "using default values for personal data"),
                         title=_("Profile Corrupted"),
                         error=err)
        
    def del_repository(self, path):
        if not isinstance(path, str):
            raise TypeError("repository to remove expected as str")
        del self.files[path]
        
    def expand_dir(self, path):
        if not isinstance(path, str):
            raise TypeError("dir to expand expected as str")
        errors = []
        try:
            errors += self._get_sharing_container(path).expand_dir(path)
        except ContainerException, err:
            errors.append(str(err))
        if errors:
            display_error("\n".join(errors),
                          title="Errors when expanding")
        return errors

    def expand_children(self, path):
        if not isinstance(path, str):
            raise TypeError("dir to expand expected as str")
        errors = []
        try:
            container = self.get_container(path)
            for dir_container in [cont for cont in container.values()
                                  if isinstance(cont, DictContainer)]:
                errors += self.expand_dir(dir_container.get_path())
        except ContainerException, err:
            errors.append(str(err))
        if errors:
            display_error("\n".join(errors),