コード例 #1
0
 def update_profile_filter(self, filter_name, filter_or, customs, **props):
     if not filter_name in self.filters or not isinstance(self.filters[filter_name], PeerFilter):
         new_filter = PeerFilter(filter_name, filter_or, **props)
         new_filter.update_customs(customs)
         self.filters[filter_name] = new_filter
     else:
         new_filter = self.filters[filter_name]
         new_filter.filter_or = filter_or
         new_filter.update_properties(**props)
         new_filter.update_customs(customs)
コード例 #2
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)