]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/app/mediawiki.py
Fix pylint errors.
[wizard.git] / wizard / app / mediawiki.py
index 6b39c8fd54d5721888c2a51ef13dde55a1fefc4b..5e71b4dc39dd25174f7e3d746457c40e9cd0252f 100644 (file)
@@ -6,15 +6,13 @@ import logging
 import shlex
 import shutil
 
-from wizard import app, deploy, install, scripts, shell, util
+from wizard import app, deploy, install, resolve, scripts, shell, util
 from wizard.app import php
 
 def make_filename_regex(var):
     return 'LocalSettings.php', re.compile('^(\$' + app.expand_re(var) + r'''\s*=\s*)(.*)(;)''', re.M)
 
-make_extractor = app.filename_regex_extractor(make_filename_regex)
-make_substitution = app.filename_regex_substitution(make_filename_regex)
-seed = {
+seed = util.dictmap(make_filename_regex, {
         'WIZARD_IP': 'IP', # obsolete, remove after we're done
         'WIZARD_SITENAME': 'wgSitename',
         'WIZARD_SCRIPTPATH': 'wgScriptPath',
@@ -24,28 +22,17 @@ seed = {
         'WIZARD_DBUSER': 'wgDBuser',
         'WIZARD_DBPASSWORD': 'wgDBpassword',
         'WIZARD_SECRETKEY': ('wgSecretKey', 'wgProxyKey'),
-        }
+        })
 
-class Application(deploy.Application):
+class Application(app.Application):
     parametrized_files = ['LocalSettings.php', 'php.ini']
     deprecated_keys = set(['WIZARD_IP']) | php.deprecated_keys
-    @property
-    def extractors(self):
-        if not self._extractors:
-            self._extractors = util.dictmap(make_extractor, seed)
-            self._extractors.update(php.extractors)
-        return self._extractors
-    @property
-    def substitutions(self):
-        if not self._substitutions:
-            self._substitutions = util.dictkmap(make_substitution, seed)
-            self._substitutions.update(php.substitutions)
-        return self._substitutions
-    @property
-    def install_handler(self):
-        handler = install.ArgHandler("mysql", "admin", "email")
-        handler.add(install.Arg("title", help="Title of your new MediaWiki install"))
-        return handler
+    extractors = app.make_extractors(seed)
+    extractors.update(php.extractors)
+    substitutions = app.make_substitutions(seed)
+    substitutions.update(php.substitutions)
+    install_handler = install.ArgHandler("mysql", "admin", "email")
+    install_handler.add(install.Arg("title", help="Title of your new MediaWiki install"))
     def checkConfig(self, deployment):
         return os.path.isfile(os.path.join(deployment.location, "LocalSettings.php"))
     def detectVersion(self, deployment):
@@ -54,9 +41,13 @@ class Application(deploy.Application):
         match = regex.search(contents)
         if not match: return None
         return distutils.version.LooseVersion(match.group(2)[1:-1])
-    def checkWeb(self, d):
-        page = d.fetch("index.php?title=Special:Version")
-        return page.find("MediaWiki is free software") != -1
+    def checkWeb(self, deployment, out=None):
+        page = deployment.fetch("/index.php?title=Main_Page")
+        if type(out) is list:
+            out.append(page)
+        return page.find("<!-- Served") != -1
+    def prepareMerge(self, deployment):
+        resolve.fix_newlines("LocalSettings.php")
     def install(self, version, options):
         try:
             os.unlink("LocalSettings.php")
@@ -79,15 +70,15 @@ class Application(deploy.Application):
             'SysopPass': options.admin_password,
             'SysopPass2': options.admin_password,
             }
-        result = install.fetch(options, 'config/index.php', post=postdata)
-        if options.verbose: print result
+        result = install.fetch(options, '/config/index.php', post=postdata)
+        if options.verbose or options.debug: print result
         if result.find("Installation successful") == -1:
             raise install.Failure()
         os.rename('config/LocalSettings.php', 'LocalSettings.php')
     def upgrade(self, d, version, options):
         sh = shell.Shell()
         if not os.path.isfile("AdminSettings.php"):
-            sh.call("git", "checkout", "mediawiki-" + str(version), "--", "AdminSettings.php")
+            sh.call("git", "checkout", "-q", "mediawiki-" + str(version), "--", "AdminSettings.php")
         try:
             result = sh.eval("php", "maintenance/update.php", "--quick", log=True)
         except shell.CallError as e:
@@ -95,45 +86,103 @@ class Application(deploy.Application):
         results = result.rstrip().split()
         if not results or not results[-1] == "Done.":
             raise app.UpgradeFailure(result)
-    def backup(self, deployment, options):
-        sh = shell.Shell()
-        # XXX: duplicate code, refactor, also, race condition
-        backupdir = os.path.join(".scripts", "backups")
-        backup = str(deployment.version) + "-" + datetime.date.today().isoformat()
-        outdir = os.path.join(backupdir, backup)
-        if not os.path.exists(backupdir):
-            os.mkdir(backupdir)
-        if os.path.exists(outdir):
-            util.safe_unlink(outdir)
-        os.mkdir(outdir)
-        outfile = os.path.join(outdir, "db.sql")
-        try:
-            sh.call("mysqldump", "--compress", "-r", outfile, *get_mysql_args(deployment))
-            sh.call("gzip", "--best", outfile)
-        except shell.CallError as e:
-            raise app.BackupFailure(e.stderr)
-        return backup
-    def restore(self, deployment, backup, options):
-        sh = shell.Shell()
-        backup_dir = os.path.join(".scripts", "backups", backup)
-        if not os.path.exists(backup_dir):
-            raise app.RestoreFailure("Backup %s doesn't exist", backup)
-        sql = open(os.path.join(backup_dir, "db.sql"), 'w+')
-        sh.call("gunzip", "-c", os.path.join(backup_dir, "db.sql.gz"), stdout=sql)
-        sql.seek(0)
-        sh.call("mysql", *get_mysql_args(deployment), stdin=sql)
-        sql.close()
+    def backup(self, deployment, backup_dir, options):
+        app.backup_database(backup_dir, deployment)
+    def restore(self, deployment, backup_dir, options):
+        app.restore_database(backup_dir, deployment)
+
+Application.resolutions = {
+'LocalSettings.php': [
+    ("""
+<<<<<<<
+***1***
+=======
+## The URL base path to the directory containing the wiki;
+## defaults for all runtime URL paths are based off of this.
+## For more information on customizing the URLs please see:
+## http://www.mediawiki.org/wiki/Manual:Short_URL
+***2***
+$wgScriptExtension  = ".php";
+
+## UPO means: this is also a user preference option
+>>>>>>>
+""", [-1]),
+    ("""
+<<<<<<<
+***1***
+=======
+
+# MySQL specific settings
+$wgDBprefix         = "";
+>>>>>>>
+""", ["\n# MySQL specific settings", 1]),
+    ("""
+<<<<<<<
+## is writable, then uncomment this:
+***1***
+=======
+## is writable, then set this to true:
+$wgEnableUploads       = false;
+>>>>>>>
+""", [-1]),
+    ("""
+<<<<<<<
+***1***
+$wgMathPath         = "{$wgUploadPath}/math";
+$wgMathDirectory    = "{$wgUploadDirectory}/math";
+$wgTmpDirectory     = "{$wgUploadDirectory}/tmp";
+=======
+$wgUseTeX           = false;
+>>>>>>>
+""", [1]),
+    # order of these rules is important
+    ("""
+<<<<<<<
+$configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
+$wgCacheEpoch = max( $wgCacheEpoch, $configdate );
+***1***
+?>
+=======
+$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
+>>>>>>>
+""", [0, 1]),
+    ("""
+<<<<<<<
+$configdate = gmdate( 'YmdHis', @filemtime( __FILE__ ) );
+$wgCacheEpoch = max( $wgCacheEpoch, $configdate );
+***1***
+=======
+$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
+>>>>>>>
+""", [0, 1]),
+    ("""
+<<<<<<<
+?>
+=======
+# When you make changes to this configuration file, this will make
+# sure that cached pages are cleared.
+$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
+>>>>>>>
+""", [0]),
+    ("""
+<<<<<<<
+***1***
+?>
+=======
+# When you make changes to this configuration file, this will make
+# sure that cached pages are cleared.
+$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
+>>>>>>>
+""", [1, 0]),
+    ("""
+<<<<<<<
+***1***
+=======
+# When you make changes to this configuration file, this will make
+# sure that cached pages are cleared.
+$wgCacheEpoch = max( $wgCacheEpoch, gmdate( 'YmdHis', @filemtime( __FILE__ ) ) );
+>>>>>>>
+""", [1, 0]),
+    ]
+}
 
-def get_mysql_args(d):
-    # XXX: add support for getting these out of options
-    vars = d.extract()
-    if 'WIZARD_DBNAME' not in vars:
-        raise app.BackupFailure("Could not determine database name")
-    triplet = scripts.get_sql_credentials()
-    args = []
-    if triplet is not None:
-        server, user, password = triplet
-        args += ["-h", server, "-u", user, "-p" + password]
-    name = shlex.split(vars['WIZARD_DBNAME'])[0]
-    args.append(name)
-    return args