示例#1
0
    def RoundTrip(self):

        # Export
        view0 = self.views[0]
        sandbox0 = view0.findPath("//sandbox")
        coll0 = sandbox0.findPath("testCollection")
        account = sandbox0.findPath("account")

        shares = sharing.publish(coll0, account)
        self.assert_(len(shares) == 2, "Wrong number of shares created")
        share = sharing.getShare(coll0) # Get the 'main' share
        urls = sharing.getUrls(share)
        self.assert_(len(urls) == 2, "Wrong number of sharing urls")
        url = urls[0] # The read/write ticket url

        # Import
        view1 = self.views[1]
        coll1 = sharing.subscribe(view1, url)

        self.assertEqual(coll0.itsUUID, coll1.itsUUID, "Collection UUIDs "
            "don't match")

        # Make sure that the items we imported have the same displayNames
        # as the ones we exported (and no fewer, no more), and UUIDs match
        names = {}
        for item in coll0:
            names[item.displayName] = 1
        for item in coll1:
            self.assert_(item.displayName in names, "Imported item that wasn't "
             "exported")
            del names[item.displayName]
            self.assertEqual(item.displayName, self.uuids[item.itsUUID],
                "UUID of imported item doesn't match original")
        self.assert_(len(names) == 0, "Import is missing some items that were "
         "exported")
示例#2
0
    def RoundTrip(self):

        # Export
        view0 = self.views[0]
        sandbox0 = view0.findPath("//sandbox")
        coll0 = sandbox0.findPath("testCollection")
        account = sandbox0.findPath("account")

        shares = sharing.publish(coll0, account)
        self.assert_(len(shares) == 2, "Wrong number of shares created")
        share = sharing.getShare(coll0)  # Get the 'main' share
        urls = sharing.getUrls(share)
        self.assert_(len(urls) == 2, "Wrong number of sharing urls")
        url = urls[0]  # The read/write ticket url

        # Import
        view1 = self.views[1]
        coll1 = sharing.subscribe(view1, url)

        self.assertEqual(coll0.itsUUID, coll1.itsUUID, "Collection UUIDs "
                         "don't match")

        # Make sure that the items we imported have the same displayNames
        # as the ones we exported (and no fewer, no more), and UUIDs match
        names = {}
        for item in coll0:
            names[item.displayName] = 1
        for item in coll1:
            self.assert_(item.displayName in names,
                         "Imported item that wasn't "
                         "exported")
            del names[item.displayName]
            self.assertEqual(item.displayName, self.uuids[item.itsUUID],
                             "UUID of imported item doesn't match original")
        self.assert_(
            len(names) == 0, "Import is missing some items that were "
            "exported")
示例#3
0
def save(rv, filename):
    """
    Save selected settings information, including all sharing accounts
    and shares (whether published or subscribed), to an INI file.

    @param rv:       Repository view
    @param filename: File to save settings into
    """

    cfg = ConfigObj()
    cfg.encoding = "UTF8"
    cfg.filename = filename

    # Sharing accounts
    counter = 1
    for account in sharing.SharingAccount.iterItems(rv):
        if account.username: # skip account if not configured
            section_name = u"sharing_account_%d" % counter
            cfg[section_name] = {}
            if isinstance(account, sharing.HubAccount):
                cfg[section_name][u"type"] = u"hub account"
            elif isinstance(account, sharing.CosmoAccount):
                cfg[section_name][u"type"] = u"cosmo account"
            else:
                cfg[section_name][u"type"] = u"webdav account"
            cfg[section_name][u"uuid"] = account.itsUUID
            cfg[section_name][u"title"] = account.displayName
            cfg[section_name][u"host"] = account.host
            cfg[section_name][u"path"] = account.path
            cfg[section_name][u"username"] = account.username
            savePassword(cfg[section_name], account.password)
            cfg[section_name][u"port"] = account.port
            cfg[section_name][u"usessl"] = account.useSSL
            counter += 1
            
    # Subscriptions
    mine = schema.ns("osaf.pim", rv).mine
    counter = 1
    sidebar = schema.ns("osaf.app", rv).sidebarCollection
    for col in sidebar:
        share = sharing.getShare(col)
        if share:
            section_name = u"share_%d" % counter
            cfg[section_name] = {}
            cfg[section_name][u"type"] = u"share"
            cfg[section_name][u"title"] = share.contents.displayName
            cfg[section_name][u"mine"] = col in mine.sources
            uc = usercollections.UserCollection(col)
            if getattr(uc, "color", False):
                color = uc.color
                cfg[section_name][u"red"] = color.red
                cfg[section_name][u"green"] = color.green
                cfg[section_name][u"blue"] = color.blue
                cfg[section_name][u"alpha"] = color.alpha
            urls = sharing.getUrls(share)
            if sharing.isSharedByMe(share):
                cfg[section_name][u"publisher"] = u"True"
                if isinstance(share.conduit, sharing.CosmoConduit):
                    c = share.conduit
                    cfg[section_name][u"url"] = c.getLocation(morsecode=True)
                else:
                    cfg[section_name][u"url"] = share.getLocation()
            else:
                cfg[section_name][u"publisher"] = u"False"
                url = share.getLocation()
                cfg[section_name][u"url"] = url
                if url != urls[0]:
                    cfg[section_name][u"ticket"] = urls[0]
            if isinstance(share.conduit, sharing.RecordSetConduit):
                c = share.conduit
                cfg[section_name][u"filters"] = ",".join(c.filters)
            counter += 1

    # SMTP accounts
    counter = 1
    currentAccount = getattr(schema.ns("osaf.pim", rv).currentOutgoingAccount,
                             "item", None)

    for account in pim.mail.SMTPAccount.iterItems(rv):
        if account.isActive and account.host:
            section_name = u"smtp_account_%d" % counter
            cfg[section_name] = {}
            cfg[section_name][u"type"] = u"smtp account"
            cfg[section_name][u"uuid"] = account.itsUUID
            cfg[section_name][u"title"] = account.displayName
            cfg[section_name][u"host"] = account.host
            cfg[section_name][u"auth"] = account.useAuth
            cfg[section_name][u"username"] = account.username
            savePassword(cfg[section_name], account.password)

            if currentAccount and account is currentAccount:
                cfg[section_name][u"default"] = u"True"

            if account.fromAddress:
                cfg[section_name][u"name"] = account.fromAddress.fullName
                cfg[section_name][u"address"] = account.fromAddress.emailAddress

            cfg[section_name][u"port"] = account.port
            cfg[section_name][u"security"] = account.connectionSecurity
            counter += 1

    # IMAP accounts
    currentAccount = getattr(schema.ns("osaf.pim", rv).currentIncomingAccount,
                             "item", None)
    counter = 1
    for account in pim.mail.IMAPAccount.iterItems(rv):
        if account.isActive and account.host:
            section_name = u"imap_account_%d" % counter
            cfg[section_name] = {}
            cfg[section_name][u"type"] = u"imap account"
            cfg[section_name][u"uuid"] = account.itsUUID
            cfg[section_name][u"title"] = account.displayName
            cfg[section_name][u"host"] = account.host
            cfg[section_name][u"username"] = account.username
            savePassword(cfg[section_name], account.password)

            if account.replyToAddress:
                cfg[section_name][u"name"] = account.replyToAddress.fullName
                cfg[section_name][u"address"] = account.replyToAddress.emailAddress

            cfg[section_name][u"port"] = account.port
            cfg[section_name][u"security"] = account.connectionSecurity

            if currentAccount and account is currentAccount:
                cfg[section_name][u"default"] = u"True"

            folderNum = len(account.folders)

            if folderNum:
                cfg[section_name]["imap_folder_num"] = folderNum

                fCounter = 0

                for folder in account.folders:
                    fname = "imap_folder_%d" % fCounter
                    cfg[section_name][fname] = {}
                    cfg[section_name][fname][u"type"] = u"imap folder"
                    cfg[section_name][fname][u"uuid"] = folder.itsUUID
                    cfg[section_name][fname][u"title"] = folder.displayName
                    cfg[section_name][fname][u"name"] = folder.folderName
                    cfg[section_name][fname][u"type"] = folder.folderType
                    # Commented out for 1.0. These features are not
                    # supported in the Chandler UI. So leave them out
                    # of the ini files as well.
                    #cfg[section_name][fname][u"max"] = folder.downloadMax
                    #cfg[section_name][fname][u"del"] = folder.deleteOnDownload
                    fCounter += 1

            counter += 1

    # POP accounts
    currentAccount = getattr(schema.ns("osaf.pim", rv).currentIncomingAccount,
                             "item", None)


    counter = 1
    for account in pim.mail.POPAccount.iterItems(rv):
        if account.isActive and account.host:
            section_name = u"pop_account_%d" % counter
            cfg[section_name] = {}
            cfg[section_name][u"type"] = u"pop account"
            cfg[section_name][u"uuid"] = account.itsUUID
            cfg[section_name][u"title"] = account.displayName
            cfg[section_name][u"host"] = account.host
            cfg[section_name][u"username"] = account.username
            savePassword(cfg[section_name], account.password)

            if account.replyToAddress:
                cfg[section_name][u"name"] = account.replyToAddress.fullName
                cfg[section_name][u"address"] = account.replyToAddress.emailAddress

            cfg[section_name][u"port"] = account.port
            cfg[section_name][u"security"] = account.connectionSecurity
            cfg[section_name][u"del"] = account.deleteOnDownload

            if currentAccount and account is currentAccount:
                cfg[section_name][u"default"] = u"True"
            counter += 1

    # Show timezones
    cfg[u"timezones"] = {}
    showTZ = schema.ns("osaf.pim", rv).TimezonePrefs.showUI
    cfg[u"timezones"][u"type"] = u"show timezones"
    cfg[u"timezones"][u"show_timezones"] = showTZ

    # Visible hours
    cfg[u"visible_hours"] = {}
    cfg[u"visible_hours"][u"type"] = u"visible hours"
    calPrefs = schema.ns("osaf.framework.blocks.calendar", rv).calendarPrefs
    cfg[u"visible_hours"][u"height_mode"] = calPrefs.hourHeightMode
    cfg[u"visible_hours"][u"num_hours"] = calPrefs.visibleHours

    # Master password
    prefs = schema.ns("osaf.framework.MasterPassword", rv).masterPasswordPrefs
    cfg[u"master_password"] = {}
    cfg[u"master_password"][u"masterPassword"] = prefs.masterPassword
    cfg[u"master_password"][u"timeout"] = prefs.timeout
    if hasattr(prefs, "protect"):
        cfg[u"master_password"][u"protect"] = prefs.protect

    # password, we'll just use the master password section as they are tied
    dummy = schema.ns("osaf.framework.password", rv).passwordPrefs.dummyPassword
    savePassword(cfg[u"master_password"], dummy, sectionName=u"dummyPassword")

    cfg.write()