AndyTechGuy has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/263233

Change subject: Simplify generate_user_files.py options
......................................................................

Simplify generate_user_files.py options

Some of the questions in generage_user_files.py can be
safetly removed in order to simplify the process. Remove
some questions from the script to make user file generation
easier.

Also remove user-fixes.py creation and instead provide a sample file.

Bug: T85270
Change-Id: I358624020a58a4829c2f2ba08448193f87c55ff5
---
M generate_user_files.py
A user-fixes.py.sample
2 files changed, 60 insertions(+), 123 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/pywikibot/core 
refs/changes/33/263233/1

diff --git a/generate_user_files.py b/generate_user_files.py
index 4455862..875e135 100755
--- a/generate_user_files.py
+++ b/generate_user_files.py
@@ -1,6 +1,6 @@
 #!/usr/bin/python
 # -*- coding: utf-8  -*-
-"""Script to create user files (user-config.py, user-fixes.py)."""
+"""Script to create user-config.py."""
 #
 # (C) Pywikibot team, 2010-2015
 #
@@ -246,50 +246,45 @@
     config_text = ''
     config_content = SMALL_CONFIG
 
-    if ((force and not config.verbose_output) or
-            pywikibot.input_yn('Would you like the extended version of '
-                               'user-config.py, with explanations '
-                               'included?', automatic_quit=False,
-                               default=True, force=force)):
-        try:
-            # config2.py will be in the pywikibot/ directory relative to this
-            # script (generate_user_files)
-            install = os.path.dirname(os.path.abspath(__file__))
-            with codecs.open(os.path.join(install, "pywikibot", "config2.py"),
-                             "r", "utf-8") as config_f:
-                config_file = config_f.read()
+    try:
+        # config2.py will be in the pywikibot/ directory relative to this
+        # script (generate_user_files)
+        install = os.path.dirname(os.path.abspath(__file__))
+        with codecs.open(os.path.join(install, "pywikibot", "config2.py"),
+                         "r", "utf-8") as config_f:
+            config_file = config_f.read()
 
-            res = re.findall("^(# ############# (?:"
-                             "LOGFILE|"
-                             "INTERWIKI|"
-                             "SOLVE_DISAMBIGUATION|"
-                             "IMAGE RELATED|"
-                             "TABLE CONVERSION BOT|"
-                             "WEBLINK CHECKER|"
-                             "DATABASE|"
-                             "SEARCH ENGINE|"
-                             "COPYRIGHT|"
-                             "FURTHER"
-                             ") SETTINGS .*)^(?=#####|# =====)",
-                             config_file, re.MULTILINE | re.DOTALL)
+        res = re.findall("^(# ############# (?:"
+                         "LOGFILE|"
+                         "INTERWIKI|"
+                         "SOLVE_DISAMBIGUATION|"
+                         "IMAGE RELATED|"
+                         "TABLE CONVERSION BOT|"
+                         "WEBLINK CHECKER|"
+                         "DATABASE|"
+                         "SEARCH ENGINE|"
+                         "COPYRIGHT|"
+                         "FURTHER"
+                         ") SETTINGS .*)^(?=#####|# =====)",
+                         config_file, re.MULTILINE | re.DOTALL)
 
-            if not res:
-                warn('Extended config extraction failed', UserWarning)
+        if not res:
+            warn('Extended config extraction failed', UserWarning)
 
-            config_text = '\n'.join(res)
-            if len(config_text.splitlines()) < 350:
-                warn('Extended config extraction too short: %d'
-                     % len(config_text.splitlines()),
-                     UserWarning)
+        config_text = '\n'.join(res)
+        if len(config_text.splitlines()) < 350:
+            warn('Extended config extraction too short: %d'
+                 % len(config_text.splitlines()),
+                 UserWarning)
 
-            config_content = EXTENDED_CONFIG
-        except Exception as e:
-            # If the warning was explicitly enabled, raise
-            if isinstance(e, UserWarning):
-                raise
-            pywikibot.output('Exception while creating extended user-config; '
-                             'falling back to simple user-config.')
-            pywikibot.exception()
+        config_content = EXTENDED_CONFIG
+    except Exception as e:
+        # If the warning was explicitly enabled, raise
+        if isinstance(e, UserWarning):
+            raise
+        pywikibot.output('Exception while creating extended user-config; '
+                         'falling back to simple user-config.')
+        pywikibot.exception()
 
     try:
         with codecs.open(_fnc, "w", "utf-8") as f:
@@ -305,31 +300,6 @@
         except:
             pass
         raise
-
-
-def create_user_fixes():
-    """Create a basic user-fixes.py in base_dir."""
-    _fnf = os.path.join(base_dir, "user-fixes.py")
-    if not file_exists(_fnf):
-        with codecs.open(_fnf, "w", "utf-8") as f:
-            f.write(r"""# -*- coding: utf-8  -*-
-
-#
-# This is only an example. Don't use it.
-#
-
-fixes['example'] = {
-    'regex': True,
-    'msg': {
-        '_default': u'no summary specified',
-    },
-    'replacements': [
-        (r'\bword\b', u'two words'),
-    ]
-}
-
-""")
-        pywikibot.output(u"'%s' written." % _fnf)
 
 
 def main(*args):
@@ -349,6 +319,8 @@
     # and 'force' mode can be activated below.
     (config.family, config.mylang) = ('wikipedia', None)
 
+    pywikibot.output(u'You can abort at any time by pressing ctrl-c')
+
     local_args = pywikibot.handle_args(args)
     if local_args:
         pywikibot.output('Unknown arguments: %s' % ' '.join(local_args))
@@ -365,67 +337,16 @@
     username = config.usernames[config.family].get(config.mylang)
     args = (config.family, config.mylang, username)
 
-    while not force or config.verbose_output:
+    if not force or config.verbose_output:
         pywikibot.output(u'\nYour default user directory is "%s"' % base_dir)
-        if pywikibot.input_yn("Do you want to use that directory?",
-                              default=True, automatic_quit=False,
-                              force=force):
-            break
-        else:
-            new_base = change_base_dir()
-            if new_base:
-                base_dir = new_base
-                break
 
-    copied_config = False
-    copied_fixes = False
-    while not force or config.verbose_output:
-        if os.path.exists(os.path.join(base_dir, "user-config.py")):
-            break
-        if pywikibot.input_yn(
-                "Do you want to copy user files from an existing Pywikibot "
-                "installation?",
-                default=False, force=force,
-                automatic_quit=False):
-            oldpath = pywikibot.input("Path to existing user-config.py?")
-            if not os.path.exists(oldpath):
-                pywikibot.error("Not a valid path")
-                continue
-            if os.path.isfile(oldpath):
-                # User probably typed /user-config.py at the end, so strip it
-                oldpath = os.path.dirname(oldpath)
-            if not os.path.isfile(os.path.join(oldpath, "user-config.py")):
-                pywikibot.error("No user_config.py found in that directory")
-                continue
-            shutil.copyfile(os.path.join(oldpath, "user-config.py"),
-                            os.path.join(base_dir, "user-config.py"))
-            copied_config = True
-
-            if os.path.isfile(os.path.join(oldpath, "user-fixes.py")):
-                shutil.copyfile(os.path.join(oldpath, "user-fixes.py"),
-                                os.path.join(base_dir, "user-fixes.py"))
-                copied_fixes = True
-
-        else:
-            break
     if not os.path.isfile(os.path.join(base_dir, "user-config.py")):
-        if ((force and not config.verbose_output) or
-                pywikibot.input_yn('Create user-config.py file? Required for '
-                                   'running bots.',
-                                   default=True, automatic_quit=False,
-                                   force=force)):
-            create_user_config(args, force=force)
-    elif not copied_config:
+        create_user_config(args, force=force)
+    else:
         pywikibot.output("user-config.py already exists in the directory")
-    if not os.path.isfile(os.path.join(base_dir, "user-fixes.py")):
-        if ((force and not config.verbose_output) or
-                pywikibot.input_yn('Create user-fixes.py file? Optional and '
-                                   'for advanced users.',
-                                   force=force,
-                                   default=False, automatic_quit=False)):
-            create_user_fixes()
-    elif not copied_fixes:
-        pywikibot.output("user-fixes.py already exists in the directory")
+    # user-fixes.py used to be created here, but has been replaced by an 
example file.
+
+    pywikibot.output("You can re-run this configuration script by running 
generate_user_files.py")
 
 if __name__ == '__main__':
     main()
diff --git a/user-fixes.py.sample b/user-fixes.py.sample
new file mode 100644
index 0000000..71d9e35
--- /dev/null
+++ b/user-fixes.py.sample
@@ -0,0 +1,16 @@
+# -*- coding: utf-8  -*-
+
+#
+# This is only an example. Don't use it.
+#
+
+fixes['example'] = {
+    'regex': True,
+    'msg': {
+        '_default': u'no summary specified',
+    },
+    'replacements': [
+        (r'\bword\b', u'two words'),
+    ]
+}
+

-- 
To view, visit https://gerrit.wikimedia.org/r/263233
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I358624020a58a4829c2f2ba08448193f87c55ff5
Gerrit-PatchSet: 1
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: AndyTechGuy <[email protected]>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to