コード例 #1
0
 def load(self, path):
     """fill document with information from .profile file"""
     from solipsis.services.profile.editor.file_document import FileDocument
     doc = FileDocument()
     result = doc.load(path)
     self.import_document(doc)
     return result
コード例 #2
0
def read_document(file_obj):
    """use FileDocument to load document from 'file_obj'"""
    from solipsis.services.profile.editor.file_document import FileDocument
    encoding = load_encoding(file_obj)
    config = CustomConfigParser(encoding)
    config.readfp(file_obj)
    file_obj.close()
    doc = FileDocument()
    doc.encoding = encoding
    doc.config = config
    doc.load_personals()
    return doc
コード例 #3
0
 def on_import(self, event):
     """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().match(PeerDescriptor(loader.get_pseudo(),
                                                  document = loader))
     event.Skip()
コード例 #4
0
 def test_import(self):
     # file -> cache
     new_doc = CacheDocument()
     new_doc.import_document(self.document)
     self._assertContent(new_doc)
     # cache -> cache
     cache_doc = CacheDocument()
     cache_doc.import_document(new_doc)
     self._assertContent(cache_doc)
     # cache -> file
     file_doc = FileDocument()
     file_doc.import_document(cache_doc)
     self._assertContent(file_doc)
     # file -> file
     other_doc = FileDocument()
     other_doc.import_document(file_doc)
     self._assertContent(other_doc)
コード例 #5
0
 def to_stream(self):
     """fill document with information from .profile file"""
     from solipsis.services.profile.editor.file_document import FileDocument
     doc = FileDocument()
     doc.import_document(self)
     return doc.to_stream()
コード例 #6
0
 def save(self, path):
     """fill document with information from .profile file"""
     from solipsis.services.profile.editor.file_document import FileDocument
     doc = FileDocument()
     doc.import_document(self)
     doc.save(path)
コード例 #7
0
 def test_default(self):
     document = FileDocument()
     self.assertEquals(u"", document.get_title())
     self.assertEquals(u"Name", document.get_firstname())
     self.assertEquals(u"Lastname", document.get_lastname())
     self.assertEquals(QUESTION_MARK(),
                       document.get_photo())
     self.assertEquals(u"email", document.get_email())
     self.assertEquals({},
                       document.get_custom_attributes())
     # assert correct sharing
     self.assertEquals({}, document.get_shared_files())
     self.assertEquals({}, document.get_files())
     # peers
     self.assertEquals({}, document.get_peers())
     # load
     document.load_defaults()
     self.assertEquals({'City': u'', 'Country': u'',
                        'Favourite Book': u'', 'Favourite Movie': u'',
                        'Sport': u'', 'Studies': u''},
                       document.get_custom_attributes())
コード例 #8
0
def write_test_profile():
    """write testing profile & blogs into test.prf & test.blog
    
    node_id = PROFILE_BRUCE
    
    Blog:
    `````
      'This is a test'

    Files:
    ``````
      data/
      |-- date.txt                  - tagos
      |-- emptydir           Shared
      |-- profiles
      |   `-- ...
      |-- routage            Shared
      `-- subdir1            Shared
          |-- TOtO.txt
          |-- date.doc
          `-- subsubdir
              |-- dummy.txt  Shared - tag2
              |-- null       Shared - tag1
              `-- ..."""
    # write filter
    filter_document = FilterDocument()
    peer_filter = PeerFilter("Mr_B", filter_or=False,**{
        "pseudo" : "*",
        "title": "Mr",
        "lastname": "b"})
    peer_filter.update_dict(FilterValue(name='color',
                                        value="blue",
                                        activate=True))
    file_filter = FileFilter("MP3", **{"name": ".mp3"})
    filter_document.filters[peer_filter.filter_name] = peer_filter
    filter_document.filters[file_filter.filter_name] = file_filter
    if os.path.exists(FILE_TEST + FILTER_EXT):
        os.remove(FILE_TEST + FILTER_EXT)
    filter_document.save(FILE_TEST + FILTER_EXT)
    # write blog
    blog = Blogs()
    blog.add_blog(u"This is a test", PSEUDO)
    if os.path.exists(FILE_TEST + BLOG_EXT):
        os.remove(FILE_TEST + BLOG_EXT)
    blog.save(FILE_TEST + BLOG_EXT)
    # write profile
    document = FileDocument()
    document.set_pseudo(PSEUDO)
    document.set_title(u"Mr")
    document.set_firstname(u"manu")
    document.set_lastname(u"breton")
    document.set_photo(QUESTION_MARK())
    document.set_email(u"*****@*****.**")
    document.load_defaults()
    document.add_custom_attributes(u"homepage", u"manu.com")
    document.add_custom_attributes(u'color', u'blue')
    document.remove_custom_attributes(u'Sport')
    document.add_repository(TEST_DIR)
    document.expand_dir(DATA_DIR)
    document.expand_dir(os.path.join(DATA_DIR,
                                     "subdir1"))
    document.share_files(DATA_DIR,
                         ["routage", "emptydir", "subdir1"])
    document.share_files(os.sep.join([DATA_DIR,
                                      "subdir1",
                                      "subsubdir"]),
                         ["null", "dummy.txt"])
    document.tag_file(os.path.join(DATA_DIR,
                                   "date.txt"),
                      u"tagos")
    document.tag_file(os.sep.join([DATA_DIR,
                                   "subdir1",
                                   "subsubdir",
                                   "null"]),
                      u"tag1")
    document.tag_file(os.sep.join([DATA_DIR,
                                   "subdir1",
                                   "subsubdir",
                                   "dummy.txt"]),
                      u"tag2")
    # set peers
    bruce = get_bruce_profile()
    bruce_doc = bruce.document
    bruce_blog = bruce.blog
    document.fill_data(PROFILE_BRUCE, bruce_doc)
    document.fill_blog(PROFILE_BRUCE, bruce_blog)
    document.make_friend(PROFILE_BRUCE)
    # write file
    if os.path.exists(FILE_TEST + PROFILE_EXT):
        os.remove(FILE_TEST + PROFILE_EXT)
    document.save(FILE_TEST + PROFILE_EXT)
コード例 #9
0
def get_bruce_profile():
    """return PeerDescriptor filled with:
    
    node_id = PROFILE_BRUCE
    
    Blog:
    `````
      'Hi Buddy'

    Files:
    ``````
      data/
      |-- date.txt           Shared
      |-- ...
      `-- subdir1
          |-- date.doc       Shared
          `-- ...
    """
    # write bruce blog
    bruce_blog = Blogs()
    bruce_blog.add_blog(u"Hi Buddy", u"bruce")
    # write bruce profile
    bruce_doc = FileDocument()
    bruce_doc.set_pseudo(u"bruce")
    bruce_doc.set_title(u"Mr")
    bruce_doc.set_firstname(u"bruce")
    bruce_doc.set_lastname(u"willis")
    bruce_doc.set_photo(QUESTION_MARK())
    bruce_doc.set_email(u"*****@*****.**")
    bruce_doc.add_custom_attributes(u"Homepage", u"bruce.com")
    bruce_doc.add_custom_attributes(u'Color', u'gray')
    bruce_doc.add_custom_attributes(u'Movie', u'6th Sense')
    bruce_doc.add_custom_attributes(u'Actor', u'Robin Williams')
    bruce_doc.add_repository(TEST_DIR)
    bruce_doc.share_file(os.path.join(DATA_DIR, "date.txt"))
    bruce_doc.share_file(os.sep.join([DATA_DIR,
                                      "subdir1",
                                      "date.doc"]))
    return PeerDescriptor(PROFILE_BRUCE, document=bruce_doc, blog=bruce_blog)