def get_files(self, file_descriptors):
        """download given list of file

        file_descriptor is a list: [ [split path], size ]"""
        if self.peer.server.current_state == self.peer.server.new_state:
            SecurityAlert(self.peer.peer_id,
                          "Can't get files: peer's server not known yet")
        else:
            # display downlaod dialog if necessary
            if get_prefs("display_dl") \
                   and "wx" in sys.modules:
                print "xxx using wx"
                from solipsis.util.uiproxy import UIProxy
                from solipsis.services.profile.gui.DownloadDialog \
                     import DownloadDialog
                self.download_dlg = UIProxy(DownloadDialog(
                    get_prefs("display_dl"), None, -1))
                self.download_dlg.init()
                self.download_dlg.Show()
            # launch first download
            self.files = file_descriptors
            if self.files:
                split_path, size = self.files.pop()
                self.update_file(split_path[-1], size)
                self._connect(MESSAGE_FILES,
                                     format_data_file(split_path, size))
                # create deferred to be called when all files downloaded
                deferred = defer.Deferred()
                self.files_deferred = deferred
                return self.files_deferred
            else:
                display_warning(_("Empty List"),
                                _("No file selected to download"))
 def __set_properties(self):
     # begin wxGlade: MatchFrame.__set_properties
     self.SetTitle(_("Matches"))
     self.SetSize((460, 600))
     # end wxGlade
     width = get_prefs("match_width")
     height = get_prefs("match_height")
     self.SetSize((width, height))
 def on_close(self, evt=None):
     """hide  application"""
     # save size
     new_size = self.GetSize()
     get_prefs().set("match_width", new_size.GetWidth())
     get_prefs().set("match_height", new_size.GetHeight())
     # do not destroy window
     self.Hide()
 def on_set_repo(self, evt):
     """set download directory according to value"""
     path = self.repo_value.GetValue()
     while path and not os.path.isdir(path):
         path = os.path.dirname(path)
     get_prefs().set("download_repo", path.encode(ENCODING))
     self.repo_value.SetValue(path)
     self.repo_button.SetToolTipString(path)
     self.SetTitle()
 def SetTitle(self, title=None):
     if not title:
         if self.peer_desc:
             title = self.peer_desc.pseudo + "'s files"
         else:
             title = unicode("your files going into " + get_prefs().get("download_repo"), ENCODING)
     wx.Dialog.SetTitle(self, title)
 def get_message(self):
     """format message to send to client according to file to be
     uploaded"""
     if self.message == MESSAGE_PROFILE:
         self.file = tempfile.NamedTemporaryFile()
         message = ASK_UPLOAD_PROFILE
     elif self.message == MESSAGE_BLOG:
         self.file = StringIO()
         message = ASK_UPLOAD_BLOG
     elif self.message == MESSAGE_SHARED:
         self.file = StringIO()
         message = ASK_UPLOAD_SHARED
     elif self.message == MESSAGE_FILES:
         # TODO: check place where to download and non overwriting
         down_path = os.path.abspath(os.path.join(
             get_prefs().get("download_repo"),
             self.split_path[-1]))
         self.file = open(down_path, "w+b")
         self.manager.download_dlg.update_file(self.split_path, self.size)
         message = "%s %s"% (ASK_UPLOAD_FILES,
                             UNIVERSAL_SEP.join(self.split_path))
     else:
         print "%s not valid"% self.message
         message = MESSAGE_ERROR
     return message
Beispiel #7
0
 def save(self, directory=None, doc_extension=PROFILE_EXT):
     """save both document & blog"""
     if directory is None:
         directory = get_prefs("profile_dir")
     file_path = os.path.join(directory, self.node_id)
     self.document.save(file_path + doc_extension)
     self.blog.save(file_path + BLOG_EXT)
 def connectionMade(self):
     """after ip is checked, begin connection"""
     PeerProtocol.connectionMade(self)
     # check action to be made
     if self.factory.download.startswith(ASK_DOWNLOAD_FILES):
         if self.factory.files:
             self.setRawMode()
             # TODO: check place where to download and non overwriting
             # create file
             file_path, size = self.factory.files.pop()
             self.factory.manager.update_file(file_path[-1], size)
             down_path = os.path.abspath(os.path.join(
                 get_prefs("download_repo"),
                 file_path[-1]))
             print "loading into", down_path
             self.file = open(down_path, "w+b")
             self.sendLine("%s %s"% (self.factory.download,
                                     UNIVERSAL_SEP.join(file_path)))
         else:
             self.factory.manager._on_all_files()
     elif self.factory.download.startswith(ASK_DOWNLOAD_BLOG)\
              or self.factory.download.startswith(ASK_DOWNLOAD_SHARED):
         self.setRawMode()
         self.file = StringIO()
         self.sendLine(self.factory.download)
     elif self.factory.download.startswith(ASK_DOWNLOAD_PROFILE):
         self.setRawMode()
         self.file = tempfile.NamedTemporaryFile()
         self.sendLine(self.factory.download)
     elif self.factory.download.startswith(ASK_UPLOAD):
         self.file = None
         self.setLineMode()
         self.sendLine(self.factory.download)
     else:
         print "unexpected command %s"% self.factory.download
 def on_about(self, event): # wxGlade: FilterFrame.<event_handler>
     """display about"""
     # not modal because would freeze the wx thread while twisted
     # one goes on and initialize profile
     about_dlg = AboutDialog(get_prefs("disclaimer"), self, -1)
     about_dlg.Show()
     event.Skip()
Beispiel #10
0
def create_filter_facade(pseudo, directory=None):
    """implements pattern singleton on FilterFacade"""
    if directory is None:
        directory = get_prefs("profile_dir")
    if isinstance(pseudo, str):
        pseudo = unicode(pseudo, ENCODING)
    FilterFacade.filter_facade = FilterFacade(pseudo, directory)
    return FilterFacade.filter_facade
 def SetTitle(self, title=None):
     if not title:
         if self.peer_desc:
             title = self.peer_desc.document.get_pseudo() + "'s files"
         else:
             title = force_unicode("your files going into " + \
                             get_prefs("download_repo"))
     wx.Dialog.SetTitle(self, title)
 def __init__(self, pseudo, directory=None):
     assert isinstance(pseudo, unicode), "pseudo must be a unicode"
     if directory is None:
         directory = get_prefs("profile_dir")
     AbstractPersonalData.__init__(self)
     AbstractSharingData.__init__(self)
     AbstractContactsData.__init__(self)
     SaverMixin.__init__(self, pseudo, directory)
 def __init__(self, pseudo, directory=None):
     assert isinstance(pseudo, unicode), "pseudo must be a unicode"
     if directory is None:
         directory = get_prefs("profile_dir")
     self._desc = None
     self.pseudo = pseudo
     self._activated = True
     self.views = {}
    def __set_properties(self):
        # begin wxGlade: FilterFrame.__set_properties
        self.SetTitle(_("Profile Filters"))
        self.SetSize((709, 632))
        self.statusbar.SetStatusWidths([-1])
        # statusbar fields
        statusbar_fields = [_("status")]
        for i in range(len(statusbar_fields)):
            self.statusbar.SetStatusText(statusbar_fields[i], i)
        # end wxGlade

        # properties not generated by wxglade
        width = get_prefs("filter_width")
        height = get_prefs("filter_height")
        self.SetSize((width, height))
        self.do_modified(False)
        self.activate_item.Check()
 def on_browse_repo(self, evt):
     """select download directory in DirDialog"""
     # pop up to choose repository
     dlg = wx.DirDialog(
         self,
         message=_("Choose location to download files into"),
         defaultPath=unicode(get_prefs().get("download_repo"), ENCODING),
         style=wx.DD_DEFAULT_STYLE | wx.DD_NEW_DIR_BUTTON,
     )
     if dlg.ShowModal() == wx.ID_OK:
         # path chosen
         path = dlg.GetPath()
         get_prefs().set("download_repo", path.encode(ENCODING))
         self.repo_value.SetValue(path)
         self.repo_button.SetToolTipString(path)
         self.SetTitle()
     dlg.Destroy()
 def __init__(self, pseudo, directory=None):
     assert isinstance(pseudo, unicode), "pseudo must be a unicode"
     if directory is None:
         directory = get_prefs("profile_dir")
     CachePersonalMixin.__init__(self)
     CacheSharingMixin.__init__(self)
     CacheContactMixin.__init__(self)
     SaverMixin.__init__(self, pseudo, directory)
Beispiel #17
0
def create_facade(pseudo, directory=None):
    """implements pattern singleton on Facade. User may specify
    document end/or view to initialize facade with at creation"""
    if directory is None:
        directory = get_prefs("profile_dir")
    if isinstance(pseudo, str):
        pseudo = unicode(pseudo, ENCODING)
    Facade.s_facade = Facade(pseudo, directory)
    return Facade.s_facade
 def __set_properties(self):
     # begin wxGlade: FilterFrame.__set_properties
     self.SetTitle(_("Profile Filters"))
     self.SetSize((460, 600))
     self.statusbar.SetStatusWidths([-1])
     # statusbar fields
     statusbar_fields = [_("status")]
     for i in range(len(statusbar_fields)):
         self.statusbar.SetStatusText(statusbar_fields[i], i)
     # end wxGlade
     width = get_prefs("filter_width")
     height = get_prefs("filter_height")
     self.SetSize((width, height))
     self.do_modified(False)
     self.activate_item.Check()
     # should be passed through constructor but wxglade does not allow it
     self.personal_filter_tab.do_modified = self.do_modified
     self.file_filter_tab.do_modified = self.do_modified
Beispiel #19
0
 def __init__(self, pseudo, directory=None):
     assert isinstance(pseudo, unicode), "pseudo must be a unicode"
     if directory is None:
         directory = get_prefs("profile_dir")
     self.pseudo = pseudo 
     self._dir = directory
     self.blogs = []
     # tag class to be enable retro-compatibility
     self.version = VERSION
Beispiel #20
0
 def get_files(self, peer_id, file_descriptors):
     """request downwload of given files"""
     if self.editor_frame and get_prefs().get("display_dl"):
         self.editor_frame.download_dlg.init()
         self.editor_frame.download_dlg.Show()
     deferred = self.network.get_files(peer_id, file_descriptors,
                                       self._on_all_files)
     deferred and deferred.addCallback(
         lambda file_name: sys.stdout.write("%s downloaded\n"% file_name))
def load_document(pseudo, directory=None):
    """build FileDocumentn from file"""
    assert isinstance(pseudo, unicode), "pseudo must be a unicode"
    if directory is None:
        directory = get_prefs("profile_dir")
    from solipsis.services.profile.file_document import FileDocument
    doc = FileDocument(pseudo, directory)
    if not doc.load():
        print "Could not find document"
    return doc
 def __init__(self, pseudo, directory=None):
     assert isinstance(pseudo, unicode), "pseudo must be a unicode"
     if directory is None:
         directory = get_prefs("profile_dir")
     self.encoding = ENCODING
     self.config = CustomConfigParser(ENCODING)
     FilePersonalMixin.__init__(self, pseudo)
     FileSharingMixin.__init__(self)
     FileContactMixin.__init__(self)
     FileSaverMixin.__init__(self, pseudo, directory)
 def on_export(self, evt):
     """export .html"""
     dlg = wx.FileDialog(
         self, message="Export HTML file as ...",
         defaultDir=get_prefs("profile_dir"),
         defaultFile="%s.html"% get_facade().get_pseudo(),
         wildcard="HTML File (*.html)|*.html",
         style=wx.SAVE)
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()
         get_facade().export_profile(path)
 def on_close(self, evt=None):
     """hide  application"""
     # ask for saving
     if self.modified:
         self.do_modified(False)
         dlg = wx.MessageDialog(
             self,
             'Your profile has been modified. Do you want to change it?',
             'Saving Dialog',
             wx.YES_NO | wx.ICON_INFORMATION)
         if dlg.ShowModal() == wx.ID_YES:
             self.on_save(evt)
     # save size
     new_size = self.GetSize()
     get_prefs().set("filter_width", new_size.GetWidth())
     get_prefs().set("filter_height", new_size.GetHeight())
     # close dialog
     if self.options["standalone"]:
         self._close()
     else:
         self.Hide()
 def __set_properties(self):
     # begin wxGlade: FileDialog.__set_properties
     self.SetTitle(_("Chose Files"))
     self.SetSize((460, 410))
     self.repo_button.SetToolTipString(_("Dowload repository"))
     self.repo_button.SetSize(self.repo_button.GetBestSize())
     self.download_button.SetToolTipString(_("Download selected files"))
     self.download_button.SetSize(self.download_button.GetBestSize())
     # end wxGlade
     self.repo_value.SetValue(unicode(get_prefs().get("download_repo"), ENCODING))
     if not self.plugin:
         self.download_button.Enable(False)
 def __set_properties(self):
     """generated by SetTitle"""
     # begin wxGlade: EditorFrame.__set_properties
     self.SetTitle(_("Profile Editor"))
     self.SetSize((460, 600))
     self.profile_statusbar.SetStatusWidths([-1])
     # statusbar fields
     profile_statusbar_fields = [_("status")]
     for i in range(len(profile_statusbar_fields)):
         self.profile_statusbar.SetStatusText(profile_statusbar_fields[i], i)
     # end wxGlade
     # set previous size
     width = get_prefs().get("profile_width")
     height = get_prefs().get("profile_height")
     self.SetSize((width, height))
     self.do_modified(False)
     self.activate_item.Check()
     # should be passed through constructor but wxglade does not allow it
     self.personal_tab.do_modified = self.do_modified
     self.blog_tab.do_modified = self.do_modified
     self.file_tab.do_modified = self.do_modified
    def __init__(self, frame, *args, **kwds):
        self.frame = frame
        # begin wxGlade: EditProfilePanel.__init__
        kwds["style"] = wx.TAB_TRAVERSAL
        wx.Panel.__init__(self, *args, **kwds)
        self.all_label = wx.StaticText(self, -1, _("Search :"))
        self.all_value = wx.TextCtrl(self, -1, "")
        self.title_label = wx.StaticText(self, -1, _("Title :"))
        self.title_value = wx.ComboBox(self, -1, choices=["", _("Mr"), _("Mrs"), _("Ms")], style=wx.CB_DROPDOWN|wx.CB_SIMPLE|wx.CB_READONLY)
        self.firstname_label = wx.StaticText(self, -1, _("First name :"))
        self.firstname_value = wx.TextCtrl(self, -1, "")
        self.lastname_label = wx.StaticText(self, -1, _("Last name :"))
        self.lastname_value = wx.TextCtrl(self, -1, "")
        self.pseudo_label = wx.StaticText(self, -1, _("Pseudo :"))
        self.pseudo_value = wx.TextCtrl(self, -1, "")
        self.email_label = wx.StaticText(self, -1, _("Email :"))
        self.email_value = wx.TextCtrl(self, -1, "")
        self.customs_label = wx.StaticText(self, -1, _("Customs :"))
        self.customs_list = MyListCtrl(self, -1, style=wx.LC_REPORT|wx.LC_EDIT_LABELS|wx.LC_SORT_ASCENDING|wx.SUNKEN_BORDER)
        self.logic_checkbox = wx.CheckBox(self, -1, _("AND search (default: OR)"))
        self.spacer_label = wx.StaticText(self, -1, "")
        self.mode_button = wx.Button(self, -1, _("Advanced mode"))
        self.clear_button = wx.Button(self, -1, _("Clear"))
        self.apply_button = wx.Button(self, -1, _("Apply"))

        self.__set_properties()
        self.__do_layout()

        self.Bind(wx.EVT_LIST_ITEM_RIGHT_CLICK, self.on_right_click, self.customs_list)
        self.Bind(wx.EVT_LIST_COL_RIGHT_CLICK, self.on_right_click, self.customs_list)
        self.Bind(wx.EVT_BUTTON, self.on_switch_mode, self.mode_button)
        self.Bind(wx.EVT_BUTTON, self.on_clear, self.clear_button)
        self.Bind(wx.EVT_BUTTON, self.on_apply, self.apply_button)
        # end wxGlade

        # custom list
        self.customs_list.InsertColumn(0, "Name")
        self.customs_list.InsertColumn(1, "Value")
        self.customs_list.SetColumnWidth(0, wx.LIST_AUTOSIZE_USEHEADER)
        self.customs_list.SetColumnWidth(1, wx.LIST_AUTOSIZE_USEHEADER)

        # popup menu
        self.popup_menu = wx.Menu()
        self.new_item = wx.MenuItem(self.popup_menu, wx.NewId(), _("New"))
        self.delete_item = wx.MenuItem(self.popup_menu, wx.NewId(), _("Delete selected(s)"))
        self.popup_menu.AppendItem(self.new_item)
        self.popup_menu.AppendItem(self.delete_item)
        self.Bind(wx.EVT_MENU, self.on_new_custom, self.new_item)
        self.Bind(wx.EVT_MENU, self.on_delete_custom, self.delete_item)

        if not get_prefs("simple_mode"):
            self.on_switch_mode(None)
 def on_import(self, evt):
     """match current filter with given profile"""
     dlg = wx.FileDialog(
         self, message="Match profile ...",
         defaultDir=get_prefs("profile_dir"),
         defaultFile="",
         wildcard="Solipsis file (*.prf)|*.prf",
         style=wx.OPEN)
     if dlg.ShowModal() == wx.ID_OK:
         path = dlg.GetPath()[:-4]
         loader = FileDocument()
         loader.load(path + PROFILE_EXT)
         get_facade().fill_data(loader.get_pseudo(), loader)
         get_filter_facade().fill_data(loader.get_pseudo(), loader)
Beispiel #29
0
def retro_compatibility(blogs):
    """make sure that downloaded version is the good one"""
    if not hasattr(blogs, "version"):
        # v 0.1.0: owner only
        blogs.pseudo = blogs.owner
        blogs._dir = get_prefs("profile_dir")
        return blogs.copy()
    elif blogs.version == "0.2.0":
        # v 0.2.0: path derived from _id & _dir. owner becomes pseudo
        blogs.pseudo = blogs._id
        return blogs.copy()
    elif blogs.version in ["0.2.1", "0.2.2"]:
        # v 0.2.1: path derived from pseudo & dir. _id removed
        return blogs
    else:
        raise ValueError("blog format not recognized.")
Beispiel #30
0
def load_blogs(pseudo, directory=None):
    """use pickle to loas blogs. file name given without extension
    (same model as profile"""
    if directory is None:
        directory = get_prefs("profile_dir")
    # reformating name
    file_name =  os.path.join(directory, pseudo)
    file_name += BLOG_EXT
    # loading
    if os.path.exists(file_name):
        blog_file = open(file_name)
        blogs = pickle.load(blog_file)
        blog_file.close()
        return retro_compatibility(blogs)
    else:
        raise ValueError("blog file %s not found"% file_name)