示例#1
0
    def load(self, config_override_fobj=None):
        """Look for config files on disk and load them.

        """
        # If a command-line override is given it is used exclusively.
        if config_override_fobj is not None:
            if not self._load_one(config_override_fobj):
                sys.exit(1)
        else:
            if not self._load_many(self.conf_paths):
                sys.exit(1)

        try:
            os.makedirs(self.lib_dir)
        except OSError:
            pass  # We assume the directory already exists...

        try:
            os.makedirs(self.web_dir)
        except OSError:
            pass  # We assume the directory already exists...

        try:
            os.makedirs(self.log_dir)
        except OSError:
            pass  # We assume the directory already exists...

        add_file_handler(self.log_dir)
示例#2
0
    def __init__(self):
        """Fill this object with the default values for each key.

        """
        parser = argparse.ArgumentParser(
            description="Ranking Web Server.",
            formatter_class=argparse.ArgumentDefaultsHelpFormatter)

        parser.add_argument(
            "-d", "--drop",
            action="store_true",
            help="Drop the data already stored.")

        parser.add_argument(
            "-p", "--http-port", default=8890,
            action="store", type=int,
            help="Listening HTTP port for RankingWebServer.")

        parser.add_argument(
            "--https-port",
            action="store", type=int,
            help="Listening HTTPS port for RankingWebServer.")

        parser.add_argument(
            "--https-certfile",
            action="store", type=utf8_decoder,
            help="HTTPS certificate file for RankingWebServer.")

        parser.add_argument(
            "--https-keyfile",
            action="store", type=utf8_decoder,
            help="HTTPS key file for RankingWebServer.")

        parser.add_argument(
            "-t", "--timeout", default=600,  # 10 minutes (in seconds)
            action="store", type=int,
            help="Timeout.")

        parser.add_argument(
            "-b", "--bind-address", default="",
            action="store", type=utf8_decoder,
            help="Listening address for RankingWebServer.")

        parser.add_argument(
            "--realm-name", default="Scoreboard",
            action="store", type=utf8_decoder,
            help="Realm name for authentication.")

        parser.add_argument(
            "-l", "--login", default="usern4me:passw0rd",
            action="store", type=utf8_decoder,
            help="Login information for adding and editing data.")

        parser.add_argument(
            "--buffer-size", default=100,  # Needs to be strictly positive
            action="store", type=int,
            help="Buffer size.")

        parser.add_argument(
            "-c", "--config",
            action="store", type=utf8_decoder,
            help="Path to a JSON config file.")

        parser.add_argument(
            "--log-dir", default=os.path.join("/", "var", "local", "log",
                                              "cms", "ranking"),
            action="store", type=utf8_decoder,
            help="Directory where RWS will store log files.")

        parser.add_argument(
            "--lib-dir", default=os.path.join("/", "var", "local", "lib",
                                              "cms", "ranking"),
            action="store", type=utf8_decoder,
            help="Directory where RWS will store runtime data.")

        self.args = parser.parse_args()

        # Ensure that lib and log directories exist (Python >= 3.2)
        #os.makedirs(self.args.lib_dir, exists_ok=True)
        #os.makedirs(self.args.log_dir, exists_ok=True)

        # Ensure that lib and log directories exist (Python < 3.2)
        try:
            os.makedirs(self.args.lib_dir)
        except OSError:
            pass  # We assume the directory already exists...
        try:
            os.makedirs(self.args.log_dir)
        except OSError:
            pass  # We assume the directory already exists...

        # Send log output to log_dir
        add_file_handler(self.args.log_dir)

        # Parse the authentication string into username and password
        try:
            self.username, self.password = self.args.login.split(":")
        except ValueError:
            logger.exception("The login string should follow the "
                "username:password format.")
            sys.exit(1)

        # Read (and override) options from a config file, if specified
        if self.args.config:
            self.load(self.args.config)