~divmod-dev/divmod.org/request-uri-2562

« back to all changes in this revision

Viewing changes to Mantissa/xmantissa/website.py

  • Committer: exarkun
  • Date: 2008-03-26 14:19:40 UTC
  • Revision ID: svn-v4:866e43f7-fbfc-0310-8f2a-ec88d1da2979:trunk:15240
Merge better-site-upgrader-2533-3

Author: exarkun
Reviewer: pjd
Fixes #2533

Fix several problems with the WebSite upgrader:

  * Make sure the old object is uninstalled
  * Make sure an AnonymousSite is created
  * Make sure a LoginSystem is properly installed

Show diffs side-by-side

added added

removed removed

Lines of Context:
34
34
from axiom.item import Item, _PowerupConnector, declareLegacyItem
35
35
from axiom.attributes import AND, integer, text, reference, bytes, boolean
36
36
from axiom.userbase import LoginSystem
37
 
from axiom.dependency import installOn
 
37
from axiom.dependency import installOn, uninstallFrom, installedOn
38
38
 
39
39
from xmantissa.ixmantissa import (
40
40
    ISiteRootPlugin, ISessionlessSiteRootPlugin, IProtocolFactoryFactory,
705
705
 
706
706
 
707
707
 
708
 
def _makeSiteConfiguration(oldSite, couldHavePorts):
709
 
    if oldSite.store.parent is not None:
710
 
        return
 
708
def _makeSiteConfiguration(currentVersion, oldSite, couldHavePorts):
 
709
    from xmantissa.publicweb import AnonymousSite
 
710
 
 
711
    newSite = oldSite.upgradeVersion(
 
712
        'mantissa_web_powerup', currentVersion, 6,
 
713
        hitCount=oldSite.hitCount)
 
714
 
 
715
    if newSite.store.parent is not None:
 
716
        return newSite
 
717
 
 
718
    # SiteConfiguration dependsOn LoginSystem.  LoginSystem was probably
 
719
    # installed by the mantissa axiomatic command.  During the dependency
 
720
    # system conversion, that command was changed to use installOn on the
 
721
    # LoginSystem.  However, no upgrader was supplied to create the new
 
722
    # dependency state.  Consequently, there may be none.  Consequently, a new
 
723
    # LoginSystem will be created if an item which dependsOn LoginSystem is
 
724
    # installed.  This would be bad.  So, set up the necessary dependency state
 
725
    # here, before instantiating SiteConfiguration. -exarkun
 
726
 
 
727
    # Addendum: it is almost certainly the case that there are not legitimate
 
728
    # configurations which lack a LoginSystem.  However, a large number of
 
729
    # database upgrade tests construct unrealistic databases.  One aspect of
 
730
    # the unrealism is that they lack a LoginSystem.  Therefore, rather than
 
731
    # changing all the bogus stubs and regenerating the stubs, I will just
 
732
    # support the case where LoginSystem is missing.  However, note that a
 
733
    # LoginSystem upgrader may invalidate this check and result in a duplicate
 
734
    # being created anyway. -exarkun
 
735
    loginSystem = oldSite.store.findUnique(LoginSystem, default=None)
 
736
    if loginSystem is not None and installedOn(loginSystem) is None:
 
737
        installOn(loginSystem, oldSite.store)
 
738
 
 
739
    uninstallFrom(oldSite.store, oldSite)
711
740
 
712
741
    site = SiteConfiguration(
713
742
        store=oldSite.store,
715
744
        hostname=getattr(oldSite, "hostname", None) or u"localhost")
716
745
    installOn(site, site.store)
717
746
 
 
747
    anonymousAvatar = AnonymousSite(store=oldSite.store)
 
748
    installOn(anonymousAvatar, oldSite.store)
 
749
 
718
750
    if couldHavePorts:
719
751
        for tcp in site.store.query(TCPPort, TCPPort.factory == oldSite):
720
752
            tcp.factory = site
721
753
        for ssl in site.store.query(SSLPort, SSLPort.factory == oldSite):
722
754
            ssl.factory = site
723
755
    else:
724
 
        oldSite.store.powerDown(oldSite, IService)
725
 
 
726
756
        if oldSite.portNumber is not None:
727
757
            port = TCPPort(
728
758
                store=oldSite.store,
734
764
        certificateFile = oldSite.certificateFile
735
765
        if securePortNumber is not None and certificateFile:
736
766
            oldCertPath = site.store.dbdir.preauthChild(certificateFile)
737
 
            if oldCertPath.exists():
738
 
                newCertPath = site.store.newFilePath('server.pem')
739
 
                oldCertPath.copyTo(newCertPath)
740
 
                port = SSLPort(
741
 
                    store=site.store,
742
 
                    portNumber=oldSite.securePortNumber,
743
 
                    certificatePath=newCertPath,
744
 
                    factory=site)
745
 
                installOn(port, site.store)
 
767
            newCertPath = site.store.newFilePath('server.pem')
 
768
            oldCertPath.moveTo(newCertPath)
 
769
            port = SSLPort(
 
770
                store=site.store,
 
771
                portNumber=oldSite.securePortNumber,
 
772
                certificatePath=newCertPath,
 
773
                factory=site)
 
774
            installOn(port, site.store)
 
775
 
 
776
    newSite.deleteFromStore()
746
777
 
747
778
 
748
779
declareLegacyItem(
754
785
        certificateFile = bytes(default=None)))
755
786
 
756
787
def upgradeWebSite1To6(oldSite):
757
 
    newSite = oldSite.upgradeVersion(
758
 
        'mantissa_web_powerup', 1, 6,
759
 
        hitCount=oldSite.hitCount)
760
 
    _makeSiteConfiguration(oldSite, False)
761
 
    return newSite
 
788
    return _makeSiteConfiguration(1, oldSite, False)
762
789
upgrade.registerUpgrader(upgradeWebSite1To6, 'mantissa_web_powerup', 1, 6)
763
790
 
764
791
declareLegacyItem(
772
799
 
773
800
def upgradeWebSite2to6(oldSite):
774
801
    # This is dumb and we should have a way to run procedural upgraders.
775
 
    newSite = oldSite.upgradeVersion(
776
 
        'mantissa_web_powerup', 2, 6,
777
 
        hitCount=oldSite.hitCount)
 
802
    newSite = _makeSiteConfiguration(2, oldSite, False)
778
803
    staticMistake = newSite.store.findUnique(StaticSite,
779
804
                                             StaticSite.prefixURL == u'static/mantissa',
780
805
                                             default=None)
783
808
        staticMistake.store.powerDown(staticMistake, ISessionlessSiteRootPlugin)
784
809
        staticMistake.deleteFromStore()
785
810
 
786
 
    _makeSiteConfiguration(oldSite, False)
787
811
    return newSite
788
812
upgrade.registerUpgrader(upgradeWebSite2to6, 'mantissa_web_powerup', 2, 6)
789
813
 
797
821
        httpLog = bytes(default=None)))
798
822
 
799
823
def upgradeWebsite3to6(oldSite):
800
 
    newSite = oldSite.upgradeVersion(
801
 
        'mantissa_web_powerup', 3, 6,
802
 
        hitCount=oldSite.hitCount)
803
 
    _makeSiteConfiguration(oldSite, False)
804
 
    return newSite
 
824
    return _makeSiteConfiguration(3, oldSite, False)
805
825
upgrade.registerUpgrader(upgradeWebsite3to6, 'mantissa_web_powerup', 3, 6)
806
826
 
807
827
declareLegacyItem(
815
835
        httpLog=bytes(default=None)))
816
836
 
817
837
def upgradeWebsite4to6(oldSite):
818
 
    newSite = oldSite.upgradeVersion(
819
 
        'mantissa_web_powerup', 4, 6,
820
 
        hitCount=oldSite.hitCount)
821
 
    _makeSiteConfiguration(oldSite, False)
822
 
    return newSite
 
838
    return _makeSiteConfiguration(4, oldSite, False)
823
839
upgrade.registerUpgrader(upgradeWebsite4to6, 'mantissa_web_powerup', 4, 6)
824
840
 
825
841
declareLegacyItem(
833
849
    """
834
850
    Create a L{SiteConfiguration} if this is a site store's L{WebSite}.
835
851
    """
836
 
    newSite = oldSite.upgradeVersion(
837
 
        oldSite.typeName, 5, 6,
838
 
        hitCount=oldSite.hitCount)
839
 
    _makeSiteConfiguration(oldSite, True)
840
 
    return newSite
 
852
    return _makeSiteConfiguration(5, oldSite, True)
841
853
upgrade.registerUpgrader(upgradeWebsite5to6, WebSite.typeName, 5, 6)
842
854