예제 #1
0
 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>"
예제 #2
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)
예제 #3
0
 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>"
예제 #4
0
 def _on_complete_pickle(self, file_obj):
     """callback when finished downloading blog"""
     try:
         obj_str = file_obj.getvalue()
         return pickle.loads(obj_str)
     except Exception, err:
         display_error(_("Your version of Solipsis is not compatible with the one "
                         "of the peer you wish to download from. "
                         "Make sure you both use the latest (%s)"% VERSION),
                       title="Download error", error=err)
예제 #5
0
 def _on_complete_pickle(self, donwload_msg):
     """callback when finished downloading blog"""
     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)
예제 #6
0
 def on_browse(self, evt):
     """add shared directory to list"""
     # pop up to choose repository
     dlg = wx.DirDialog(self, message=_("Choose your repository"),
                        defaultPath = os.path.expanduser("~/"),
                        style=wx.DD_DEFAULT_STYLE|wx.DD_NEW_DIR_BUTTON)
     if dlg.ShowModal() == wx.ID_OK:
         # path chosen
         path = dlg.GetPath()
         try:
             get_facade().add_repository(path)
             get_facade().recursive_share(path, True)
         except ContainerException, err:
             display_error(_("Could not add directory %s: %s"% (path, str(err))),
                             title=_("Existing directory"),
                             error=err)
예제 #7
0
 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)
예제 #8
0
 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)
예제 #9
0
 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)
예제 #10
0
        
    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),