jenkins-bot has submitted this change and it was merged.

Change subject: Preload pywikibot library in pwb shell
......................................................................


Preload pywikibot library in pwb shell

The pwb shell script has not pre-loaded the pywikibot library, or
injected any other python objects into the shell environment.
This is useful, when the user needs to set up their own environment.

However the more common case is the user wants to be able to
use pywikibot command line arguments, and pre-load the pywikibot library.

Change-Id: I976a4b19d7a3eebb13a37dccce6bbe6454294c78
---
M scripts/shell.py
M tests/script_tests.py
2 files changed, 27 insertions(+), 4 deletions(-)

Approvals:
  XZise: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/scripts/shell.py b/scripts/shell.py
index 0f7337f..baa82cc 100644
--- a/scripts/shell.py
+++ b/scripts/shell.py
@@ -4,7 +4,13 @@
 Spawns an interactive Python shell.
 
 Usage:
-    python pwb.py shell
+    python pwb.py shell [args]
+
+If no arguments are given, the pywikibot library will not be loaded.
+
+The following parameters are supported:
+
+&params;
 
 """
 # (C) Pywikibot team, 2014
@@ -14,6 +20,23 @@
 __version__ = '$Id$'
 #
 
-if __name__ == "__main__":
+
+def main(*args):
+    """Script entry point."""
+    env = None
+    if args:
+        import pywikibot
+        pywikibot.handle_args(*args)
+        env = locals()
+
     import code
-    code.interact("""Welcome to the Pywikibot interactive shell!""")
+    code.interact("""Welcome to the Pywikibot interactive shell!""", local=env)
+
+
+if __name__ == "__main__":
+    import sys
+    args = []
+    if set(sys.argv) - set(['shell', 'shell.py']):
+        args = sys.argv
+    del sys
+    main(*args)
diff --git a/tests/script_tests.py b/tests/script_tests.py
index dcd3f3e..d575a66 100644
--- a/tests/script_tests.py
+++ b/tests/script_tests.py
@@ -348,7 +348,7 @@
             else:
                 test_name = 'test_' + script_name + '_help'
             dct[test_name] = test_execution(script_name, ['-help'])
-            if script_name in ['shell', 'version',
+            if script_name in ['version',
                                'data_ingestion',  # bug 68611
                                'replicate_wiki',  # bug 68664
                                'script_wui',      # Failing on travis-ci

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I976a4b19d7a3eebb13a37dccce6bbe6454294c78
Gerrit-PatchSet: 2
Gerrit-Project: pywikibot/core
Gerrit-Branch: master
Gerrit-Owner: John Vandenberg <[email protected]>
Gerrit-Reviewer: John Vandenberg <[email protected]>
Gerrit-Reviewer: Ladsgroup <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Merlijn van Deen <[email protected]>
Gerrit-Reviewer: XZise <[email protected]>
Gerrit-Reviewer: Xqt <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

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

Reply via email to