Ejemplo n.º 1
0
 def testCustomizeOverrides_001(self):
     """
     Test platform=standard, no existing overrides.
     """
     config = Config()
     options = OptionsConfig()
     if PLATFORM == "standard":
         config.options = options
         customizeOverrides(config)
         self.assertEqual(None, options.overrides)
     config.options = options
     customizeOverrides(config, platform="standard")
     self.assertEqual(None, options.overrides)
Ejemplo n.º 2
0
 def testCustomizeOverrides_002(self):
     """
     Test platform=standard, existing override for cdrecord.
     """
     config = Config()
     options = OptionsConfig()
     options.overrides = [
         CommandOverride("cdrecord", "/blech"),
     ]
     if PLATFORM == "standard":
         config.options = options
         customizeOverrides(config)
         self.assertEqual([CommandOverride("cdrecord", "/blech")], options.overrides)
     config.options = options
     customizeOverrides(config, platform="standard")
     self.assertEqual([CommandOverride("cdrecord", "/blech")], options.overrides)
Ejemplo n.º 3
0
 def testCustomizeOverrides_008(self):
     """
     Test platform=debian, existing override for cdrecord and mkisofs.
     """
     config = Config()
     options = OptionsConfig()
     options.overrides = [
         CommandOverride("cdrecord", "/blech"),
         CommandOverride("mkisofs", "/blech2"),
     ]
     if PLATFORM == "debian":
         config.options = options
         customizeOverrides(config)
         self.assertEqual([CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2")], options.overrides)
     config.options = options
     customizeOverrides(config, platform="debian")
     self.assertEqual([CommandOverride("cdrecord", "/blech"), CommandOverride("mkisofs", "/blech2")], options.overrides)
Ejemplo n.º 4
0
 def testCustomizeOverrides_005(self):
     """
     Test platform=debian, no existing overrides.
     """
     config = Config()
     options = OptionsConfig()
     if PLATFORM == "debian":
         config.options = options
         customizeOverrides(config)
         self.assertEqual(
             [CommandOverride("cdrecord", "/usr/bin/wodim"), CommandOverride("mkisofs", "/usr/bin/genisoimage")],
             options.overrides,
         )
     config.options = options
     customizeOverrides(config, platform="debian")
     self.assertEqual(
         [CommandOverride("cdrecord", "/usr/bin/wodim"), CommandOverride("mkisofs", "/usr/bin/genisoimage")], options.overrides
     )
Ejemplo n.º 5
0
def setupOverrides():
    """
    Set up any platform-specific overrides that might be required.

    When packages are built, this is done manually (hardcoded) in customize.py
    and the overrides are set up in cli.cli().  This way, no runtime checks need
    to be done.  This is safe, because the package maintainer knows exactly
    which platform (Debian or not) the package is being built for.

    Unit tests are different, because they might be run anywhere.  So, we
    attempt to make a guess about plaform using platformDebian(), and use that
    to set up the custom overrides so that platform-specific unit tests continue
    to work.
    """
    config = Config()
    config.options = OptionsConfig()
    if platformDebian():
        customizeOverrides(config, platform="debian")
    else:
        customizeOverrides(config, platform="standard")
    setupPathResolver(config)
Ejemplo n.º 6
0
def cli():
    """
    Implements the command-line interface for the ``cback3-span`` script.

    Essentially, this is the "main routine" for the cback3-span script.  It does
    all of the argument processing for the script, and then also implements the
    tool functionality.

    This function looks pretty similiar to ``CedarBackup3.cli.cli()``.  It's not
    easy to refactor this code to make it reusable and also readable, so I've
    decided to just live with the duplication.

    A different error code is returned for each type of failure:

       - ``1``: The Python interpreter version is < 3.7
       - ``2``: Error processing command-line arguments
       - ``3``: Error configuring logging
       - ``4``: Error parsing indicated configuration file
       - ``5``: Backup was interrupted with a CTRL-C or similar
       - ``6``: Error executing other parts of the script

    *Note:* This script uses print rather than logging to the INFO level, because
    it is interactive.  Underlying Cedar Backup functionality uses the logging
    mechanism exclusively.

    Returns:
        Error code as described above
    """
    try:
        if list(map(int, [sys.version_info[0], sys.version_info[1]])) < [3, 7]:
            sys.stderr.write("Python 3 version 3.7 or greater required.\n")
            return 1
    except:
        # sys.version_info isn't available before 2.0
        sys.stderr.write("Python 3 version 3.7 or greater required.\n")
        return 1

    try:
        options = SpanOptions(argumentList=sys.argv[1:])
    except Exception as e:
        _usage()
        sys.stderr.write(" *** Error: %s\n" % e)
        return 2

    if options.help:
        _usage()
        return 0
    if options.version:
        _version()
        return 0
    if options.diagnostics:
        _diagnostics()
        return 0

    if options.stacktrace:
        logfile = setupLogging(options)
    else:
        try:
            logfile = setupLogging(options)
        except Exception as e:
            sys.stderr.write("Error setting up logging: %s\n" % e)
            return 3

    logger.info("Cedar Backup 'span' utility run started.")
    logger.info("Options were [%s]", options)
    logger.info("Logfile is [%s]", logfile)

    if options.config is None:
        logger.debug("Using default configuration file.")
        configPath = DEFAULT_CONFIG
    else:
        logger.debug("Using user-supplied configuration file.")
        configPath = options.config

    try:
        logger.info("Configuration path is [%s]", configPath)
        config = Config(xmlPath=configPath)
        setupPathResolver(config)
    except Exception as e:
        logger.error("Error reading or handling configuration: %s", e)
        logger.info("Cedar Backup 'span' utility run completed with status 4.")
        return 4

    if options.stacktrace:
        _executeAction(options, config)
    else:
        try:
            _executeAction(options, config)
        except KeyboardInterrupt:
            logger.error("Backup interrupted.")
            logger.info(
                "Cedar Backup 'span' utility run completed with status 5.")
            return 5
        except Exception as e:
            logger.error("Error executing backup: %s", e)
            logger.info(
                "Cedar Backup 'span' utility run completed with status 6.")
            return 6

    logger.info("Cedar Backup 'span' utility run completed with status 0.")
    return 0