Hi, I write scripts, mostly for temporary tasks. I understand, that pwb.py handles arguments and logs and finds my script in /scripts/userscripts. Most of these scripts don't excpect arguments, the task is wired in. So is there any advantage of using pwb.py in this case?
Hi Bináris,
using the pwb.py wrapper is optional but you can call a script directly without it. There are a few advantages:
1. You don’t have to give script path where the script resides. You can give some user script paths in your user-config.py, it also searches for scripts in scripts/user scripts/ and scripts/ and finally in Pywikibot/scripts/ folder. 2. Scripts can be found even there is a spelling mistake in the script name you typed in. For example try pwb hello :) 3. The pwb.py checks wether your Python version is high enough. 4. The wrapper also validates dependencies and their version. 5. It provides all global options even your script does not use pywikibot.handleargs(). This may be useful e.g. to set different sites with, different user accounts with your script, run the script in simulation without api write, use a different user-config.py file. Also all numeric (and boolean) config values can be set as global option.
There is no disadvantage known when using it.
Best xqt
Am 16.11.2022 um 23:13 schrieb Bináris wikiposta@gmail.com:
Hi, I write scripts, mostly for temporary tasks. I understand, that pwb.py handles arguments and logs and finds my script in /scripts/userscripts. Most of these scripts don't excpect arguments, the task is wired in. So is there any advantage of using pwb.py in this case?
-- Bináris _______________________________________________ pywikibot mailing list -- pywikibot@lists.wikimedia.org To unsubscribe send an email to pywikibot-leave@lists.wikimedia.org
info@gno.de ezt írta (időpont: 2022. nov. 17., Cs, 8:19):
There is no disadvantage known when using it.
Thank you! But, there is. I have a special case, because I suffer with a low space storage device. I know, this is my fault, but anyway, it IS a problem (although I regularly free up space, something eats it very quickly, and I cannot guess what it is). I also kwo that Black Friday is coming... But the problem is currently existing.
So I realized that pwb.py wants to log soemthing even if I use -nolog. It also wants to cache something or read some cache, not that I wuld have said to it to do so. And if pwb. py is unhappy with this, it * writes many kilometers of error messages, that I cannot read, becuase 90% ran out of screen (I don't think any developer wants to read this in the life) * generates additional errors during writing the previous errors, so the message gets pretty long * the witing itself last half a minute or a minute (yes, so long!), and takes my time unless I use ctrl C. * I cannot find he useful writing on screen, if it exists at all * the task is often not completed or partially completed, even if it has nothing to do with the storage device.
I think it does not take seriously the -nolog.
Example 1: I wrote a script which generates lists in memory, compares with the existing lists on Wikipedia and uploads if there is a difference. This script ran 10 minutes before it found the first list to upload. It wrote all the titles on screen, so I know, it has just created the appropriate list. But INSTEAD of saving it to wiki, it began to write this long looped error message, and did not execute the put command, rather it terminated. After I freed up soma space, it ran properly.
Example 2: I run python pwb.py -version -nolog because I know you would ask for it. For the first time it generated a mile long error message again, and did not writ the config which it should have done. Then I freed up some space, and itt worked. So -nolog is useless if I want to avoid troubles. Here goes the VERY tail of the first run, and the result of the second run below.
--- Logging error --- Traceback (most recent call last): File "C:\Python37\lib\logging\handlers.py", line 69, in emit if self.shouldRollover(record): File "C:\Python37\lib\logging\handlers.py", line 186, in shouldRollover self.stream.seek(0, 2) #due to non-posix-compliant Windows feature OSError: [Errno 28] No space left on device Call stack: File "pwb.py", line 524, in <module> main() File "pwb.py", line 508, in main if not execute(): File "pwb.py", line 489, in execute run_python_file(filename, script_args, module) File "pwb.py", line 152, in run_python_file main_mod.__dict__) File "pywikibot\scripts\version.py", line 106, in <module> main() File "pywikibot\scripts\version.py", line 102, in main pywikibot.output('\t{}: {}'.format(lang, username)) File "c:\Pywikibot\pywikibot\tools_deprecate.py", line 399, in wrapper return obj(*__args, **__kw) File "c:\Pywikibot\pywikibot\logging.py", line 170, in info logoutput(msg, *args, **kwargs) File "c:\Pywikibot\pywikibot\tools_deprecate.py", line 399, in wrapper return obj(*__args, **__kw) File "c:\Pywikibot\pywikibot\logging.py", line 152, in logoutput logger.log(level, msg, extra=context, **kwargs) Message: '\t*: BinBot' Arguments: () --- Logging error --- Traceback (most recent call last): File "C:\Python37\lib\logging\handlers.py", line 69, in emit if self.shouldRollover(record): File "C:\Python37\lib\logging\handlers.py", line 186, in shouldRollover self.stream.seek(0, 2) #due to non-posix-compliant Windows feature OSError: [Errno 28] No space left on device Call stack: File "c:\Pywikibot\pywikibot\comms\http.py", line 81, in flush log('Closing network session.') File "c:\Pywikibot\pywikibot\tools_deprecate.py", line 399, in wrapper return obj(*__args, **__kw) File "c:\Pywikibot\pywikibot\logging.py", line 255, in log logoutput(msg, *args, level=VERBOSE, **kwargs) File "c:\Pywikibot\pywikibot\tools_deprecate.py", line 399, in wrapper return obj(*__args, **__kw) File "c:\Pywikibot\pywikibot\logging.py", line 152, in logoutput logger.log(level, msg, extra=context, **kwargs) Message: 'Closing network session.' Arguments: () --- Logging error --- Traceback (most recent call last): File "C:\Python37\lib\logging\handlers.py", line 69, in emit if self.shouldRollover(record): File "C:\Python37\lib\logging\handlers.py", line 186, in shouldRollover self.stream.seek(0, 2) #due to non-posix-compliant Windows feature OSError: [Errno 28] No space left on device Call stack: File "c:\Pywikibot\pywikibot\comms\http.py", line 87, in flush log('Network session closed.') File "c:\Pywikibot\pywikibot\tools_deprecate.py", line 399, in wrapper return obj(*__args, **__kw) File "c:\Pywikibot\pywikibot\logging.py", line 255, in log logoutput(msg, *args, level=VERBOSE, **kwargs) File "c:\Pywikibot\pywikibot\tools_deprecate.py", line 399, in wrapper return obj(*__args, **__kw) File "c:\Pywikibot\pywikibot\logging.py", line 152, in logoutput logger.log(level, msg, extra=context, **kwargs) Message: 'Network session closed.' Arguments: ()
c:\Pywikibot>python pwb.py -version -nolog Pywikibot: [https] r-pywikibot-core.git (8f3a50c, g1, 2022/10/10, 17:24:18, OUTDATED) Release version: 7.7.1 setuptools version: 57.0.0 mwparserfromhell version: 0.6.3 wikitextparser version: 0.51.0 requests version: 2.25.1 cacerts: C:\Python37\lib\site-packages\certifi\cacert.pem certificate test: ok Python: 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:34:20) [MSC v.1916 64 bit (AMD64)] PYWIKIBOT_DIR: Not set PYWIKIBOT_DIR_PWB: '' PYWIKIBOT_NO_USER_CONFIG: Not set Config base dir: c:\Pywikibot Usernames for family 'wikipedia': *: BinBot
To the prevoius: The snake bites its own tail, we say here. There are a lot of logging errors because the script could not log the previous error. But it should not have logged anything, only perform a task, and write on screen and modify a page on wiki. In MY script nothing uses the device.
info@gno.de ezt írta (időpont: 2022. nov. 17., Cs, 20:56):
Hi Binaris,
Seems the config.log variable isn’t an empty list. Refer my other may to figure it out.
For some reason, I had log = ['*'] # type: List[str] in my user-config. I don't know why, at least I don't remember modifying it at any time. So I have changed it to log = [] # type: List[str] and now the problem seems to have been disappeared. Thank you very much, that was a great help!
Have you ever cleared the api cache?
Do you mean c:\Pywikibot\apicache-py3? No, but it takes only 450K.
Did you ever run Pywikibot tests? tests have its own api cache. No, I didn't.
Maybe there are some you don’t need and space can be freed. For example wikitextparser is not necessary if you have mwparserfromhell installed.
Uninstalled wikitextparser. :-) But I don't think any part of Pywikibot would be the secret agent which is consuming my device. :-) Thank you again!