~mvo/update-manager/not-automatic

« back to all changes in this revision

Viewing changes to DistUpgrade/dist-upgrade.py

  • Committer: Michael Vogt
  • Date: 2009-01-20 12:02:08 UTC
  • Revision ID: michael.vogt@ubuntu.com-20090120120208-g8qjrh8j22pmnrv8
AutoUpgradeTester/UpgradeTestBackendChroot.py: move tempdir, cachetarball into the new CHROOT section

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
#!/usr/bin/python
2
2
 
3
 
from DistUpgradeMain import main
 
3
from DistUpgradeController import DistUpgradeController
 
4
from DistUpgradeConfigParser import DistUpgradeConfig
 
5
import logging
 
6
import os
 
7
import sys
 
8
from optparse import OptionParser
 
9
from gettext import gettext as _
4
10
 
5
11
if __name__ == "__main__":
6
 
    main()
 
12
 
 
13
    parser = OptionParser()
 
14
    parser.add_option("-c", "--cdrom", dest="cdromPath", default=None,
 
15
                      help=_("Use the given path to search for a cdrom with upgradable packages"))
 
16
    parser.add_option("--have-prerequists", dest="havePrerequists",
 
17
                      action="store_true", default=False)
 
18
    parser.add_option("--with-network", dest="withNetwork",action="store_true")
 
19
    parser.add_option("--without-network", dest="withNetwork",action="store_false")
 
20
    parser.add_option("--frontend", dest="frontend",default=None,
 
21
                      help=_("Use frontend. Currently available: \n"\
 
22
                             "DistUpgradeViewText, DistUpgradeViewGtk, DistUpgradeViewKDE"))
 
23
    parser.add_option("--mode", dest="mode",default="desktop",
 
24
                      help=_("*DEPRECATED* this option will be ignore"))
 
25
    parser.add_option("--partial", dest="partial", default=False,
 
26
                      action="store_true", 
 
27
                      help=_("Perform a partial upgrade only (no sources.list rewriting)"))
 
28
    parser.add_option("--datadir", dest="datadir", default=None,
 
29
                      help=_("Set datadir"))
 
30
    (options, args) = parser.parse_args()
 
31
 
 
32
    config = DistUpgradeConfig(".")
 
33
 
 
34
    logdir = config.getWithDefault("Files","LogDir","/var/log/dist-upgrade/")
 
35
    if not os.path.exists(logdir):
 
36
        os.mkdir(logdir)
 
37
    fname = os.path.join(logdir,"main.log")
 
38
    # do not overwrite the default main.log
 
39
    if options.partial:
 
40
        fname += ".partial"
 
41
    logging.basicConfig(level=logging.DEBUG,
 
42
                        filename=fname,
 
43
                        format='%(asctime)s %(levelname)s %(message)s',
 
44
                        filemode='w')
 
45
 
 
46
    from DistUpgradeVersion import VERSION
 
47
    logging.info("release-upgrader version '%s' started" % VERSION)
 
48
    
 
49
    # the commandline overwrites the configfile
 
50
    for requested_view in [options.frontend]+config.getlist("View","View"):
 
51
        if not requested_view:
 
52
            continue
 
53
        try:
 
54
            view_modul = __import__(requested_view)
 
55
            view_class = getattr(view_modul, requested_view)
 
56
            break
 
57
        except (ImportError, AttributeError, TypeError), e:
 
58
            logging.warning("can't import view '%s' (%s)" % (requested_view,e))
 
59
            print "can't load %s (%s)" % (requested_view, e)
 
60
    else:
 
61
        logging.error("No view can be imported, aborting")
 
62
        print "No view can be imported, aborting"
 
63
        sys.exit(1)
 
64
 
 
65
    # get a view
 
66
    view = view_class(logdir=logdir)
 
67
    app = DistUpgradeController(view, options, datadir=options.datadir)
 
68
 
 
69
    # partial upgrade only
 
70
    if options.partial:
 
71
        if not app.doPartialUpgrade():
 
72
            sys.exit(1)
 
73
        sys.exit(0)
 
74
 
 
75
    # full upgrade
 
76
    app.run()
 
77