def get_known_tables(self):
     dbserver = DbServerInfo(self, self.db_name)
     commands = dbserver.build_sql_command("'show tables'")
     echocmd = commands[0]
     mysqlcmd = commands[1]
     to_run = " ".join(echocmd) + " | " + " ".join(mysqlcmd) + " --silent"
     results = RunSimpleCommand.run_with_output(to_run, shell=True)
     return results.decode('utf-8').splitlines()
Exemple #2
0
def run_simple_query(query, wiki):
    '''
    run a mysql query which returns only one field from
    one row.
    return the value of that one field (as a string)
    '''
    db_info = DbServerInfo(wiki, wiki.db_name)
    commands = db_info.build_sql_command(query)
    echocmd = commands[0]
    mysqlcmd = commands[1]
    to_run = " ".join(echocmd) + " | " + " ".join(mysqlcmd) + " --silent"
    log.info("running with no output: " + to_run)
    return RunSimpleCommand.run_with_output(to_run, shell=True)
 def run(self, wiki, filenameformat, output_dir, overwrite, base=None):
     '''
     run a (maintenance) script on one wiki, expecting relevant output to
     go to a file
     '''
     filenameformat = filenameformat.replace('{d}', '{{d}}')
     filenameformat = filenameformat.replace('{w}', '{{w}}')
     filenameformat = filenameformat.format(s=self.scriptname)
     (outfile_base, outfile_path) = self.skip_if_done(
         wiki, filenameformat, output_dir, overwrite)
     if outfile_base is None:
         return True
     command = self.get_command(wiki, outfile_path, outfile_base, base)
     if self.dryrun:
         print("Would run:", command)
         return True
     return RunSimpleCommand.run_with_output(
         command, maxtries=1, shell=False)
 def get_domain_from_wikidbname(self):
     '''
     given the name of the wiki db, turn this into the
     fqdn of the wiki project (i.e. enwiki -> en.wikipedia.org)
     '''
     script_command = MultiVersion.mw_script_as_array(self.wiki.config,
                                                      "eval.php")
     # echo $wgCanonicalServer | php "$multiversionscript" eval.php $wiki
     command = ["echo", "'echo $wgCanonicalServer;'", "|", self.wiki.config.php]
     command.extend(script_command)
     command.append(self.wiki.db_name)
     command_text = " ".join(command)
     self.log.info("running with no output: %s", command_text)
     output = RunSimpleCommand.run_with_output(command_text, shell=True)
     if not output:
         self.log.warning("error retrieving domain for wiki %s", self.wiki.db_name)
         return None
     # rstrip gets rid of any trailing newlines from eval.php
     return output.decode('utf-8').split('//')[1].rstrip()
    def get_db_user_and_password(self):
        # get these by running a MediaWiki maintenance script;
        # yes, this means you need a full installation of MediaWiki
        # (but not web service) in order to use these methods

        command_list = MultiVersion.mw_script_as_array(self.config, "getConfiguration.php")
        pull_vars = ["wgDBuser", "wgDBpassword"]
        command = "{php} {command} --wiki={dbname} --format=json --regex='{vars}'"
        command = command.format(
            php=MiscUtils.shell_escape(self.config.php),
            command=" ".join(command_list),
            dbname=MiscUtils.shell_escape(self.db_name),
            vars="|".join(pull_vars))
        results = RunSimpleCommand.run_with_output(command, shell=True).strip()
        settings = json.loads(results.decode('utf-8'))
        db_user = settings['wgDBuser']
        db_password = settings['wgDBpassword']

        return db_user, db_password