def __init__(self, args, wikiname, flags):
     self.args = args
     self.wiki = Wiki(self.args["config"], wikiname)
     self.wiki.set_date(self.args["date"])
     self.flags = flags
     dump_class = MiscDumpFactory.get_dumper(self.args["dumptype"])
     self.dumper = dump_class(self.wiki, flags["dryrun"], self.args["args"])
def usage(message=None):
    '''
    display a usage message for this script and
    the arguments for each known dump type.

    an optional message may be passed that will be
    displayed first.
    '''
    if message:
        print(message)
    usage_message = (
        """Usage: python3 generatemiscdumps.py --dumptype <type> [options] [args]

Options: --configfile, --dumptype, --wiki, --date,
         --dumponly, --indexonly, --forcerun,
         --logfile, --verbose, --quiet, --dryrun, --wiki

 --configfile:  Specify an alternate config file to read. Default
                file is 'miscdump.conf' in the current directory.
 --dumptype:    type of dump to be run.  Known types include:
                {0}
 --wiki:        Run the dumps only for the specific wiki.
 --date:        (Re)run dump of a given date (use with care).

 --dumponly:    Do only the dump without rebuilding the index.html file.
 --indexonly:   Generate the index.html file only, don't run the dump.
 --forcerun:    Do the run even if there is already a successful run in place.

 --logfile:     Name of file to which error messages and progress messages
                are to be logged. Default: log to stderr
 --verbose:     Print error messages and other informative messages.
                Default: print errors and warnings
 --quiet:       Print only serious error messages
                Default: print errors and warnings
 --dryrun:      Don't dump anything but print the commands that would be run.
 --help:        Display this message.

Args:  If your dump needs specific arguments passed to the class that
       are not provided for here, you can pass them on the command line
       before the final wikidbname argument.  Arguments with values should
       be passed as argname:value, and arguments without values (flags that
       will be set as True) should be passed simply as argname.
""").format(", ".join(MiscDumpFactory.get_known_dumptypes()))
    sys.stderr.write(usage_message)
    secondary_message = MiscDumpFactory.get_secondary_usage_all()
    sys.stderr.write("\n" + secondary_message)
    sys.exit(1)
 def __init__(self, args, wikiname, flags, log):
     self.args = args
     self.wiki = Wiki(self.args['config'], wikiname)
     self.wiki.set_date(self.args['date'])
     self.flags = flags
     self.log = log
     dump_class = MiscDumpFactory.get_dumper(self.args['dumptype'])
     self.dumper = dump_class(self.wiki, self.log, flags['dryrun'],
                              self.args['args'])
def get_config(config_file, dumptype):
    '''
    return the config for the given dumptype
    '''
    configurator = MiscDumpFactory.get_configurator(dumptype)
    if config_file:
        config = configurator(config_file)
    else:
        config = configurator()
    return config
def check_usage(flags, standard_args):
    """
    check validity of specified args
    """
    if not flags["do_dump"] and not flags["do_index"]:
        usage("You may not specify more than one of dumpsonly " "and indexonly together.")

    if standard_args["dumptype"] is None:
        usage("Mandatory dumptype argument not specified")
    elif standard_args["dumptype"] not in MiscDumpFactory.get_known_dumptypes():
        usage("No such known dump " + standard_args["dumptype"])
    def get_files_text(self, wiki):
        """
        given wiki object, return the list of links and descriptions
        for the output files for that wiki of the current dump type
        and date
        """
        dump_class = MiscDumpFactory.get_dumper(self.args["dumptype"])
        dumper = dump_class(wiki, False, self.args["args"])
        output_files, expected = dumper.get_output_files()
        files_text = self.get_outputfile_indextxt(output_files, expected, wiki.db_name, wiki.date)

        md5file = MD5File(wiki.config, wiki.date, wiki.db_name)
        md5file_text = self.get_outputfile_indextxt([md5file.get_filename()], [], wiki.db_name, wiki.date)
        files_text.extend(md5file_text)
        return files_text