Page MenuHomePhabricator

tilde in argument to -dir causes exception
Closed, ResolvedPublic

Description

If the directory ~/.pywikibot2 doesnt exist

/path/to/current/dir/ $ python pwb.py -dir:~/.pywikibot2 version

NOTE: ~/.pywikibot2/user-config.py was not found Please follow the prompts to create it: Traceback (most recent call last): File "pwb.py", line 149, in <module> run_python_file(path, [path], [path.decode('ascii')]) File "pwb.py", line 69, in run_python_file exec(compile(source, filename, "exec"), main_mod.dict) File "generate_user_files.py", line 19, in <module> import pywikibot File "pywikibot/__init__.py", line 29, in <module> from pywikibot import config2 as config File "pywikibot/config2.py", line 209, in <module> _base_dir = get_base_dir() File "pywikibot/config2.py", line 195, in get_base_dir raise RuntimeError("Directory '%s' does not exist." % base_dir) RuntimeError: Directory '/path/to/current/dir/~/.pywikibot2' does not exist.

(that path.decode('ascii') looks defective too)


Version: core-(2.0)
Severity: trivial

Details

Reference
bz72290

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 3:52 AM
bzimport set Reference to bz72290.
bzimport added a subscriber: Unknown Object (????).

Now ~ in argument is resolved.
The exception is raised because the directory does not exist.
But I think this is the wanted behaviour (*).

python pwb.py version -dir:~/.pywikibot2

NOTE: 'user-config.py' was not found! Please follow the prompts to create it: Traceback (most recent call last): File "pwb.py", line 162, in <module> []) File "pwb.py", line 75, in run_python_file exec(compile(source, filename, "exec"), main_mod.dict) File "generate_user_files.py", line 19, in <module> import pywikibot File "pywikibot/__init__.py", line 29, in <module> from pywikibot import config2 as config File "pywikibot/config2.py", line 224, in <module> _base_dir = get_base_dir() File "pywikibot/config2.py", line 210, in get_base_dir raise RuntimeError("Directory '%s' does not exist." % base_dir) RuntimeError: Directory '/home/user/.pywikibot2' does not exist.

Note that in you example, it also fails even if the directory exists as -dir: comes before the expected script name.

python pwb.py -dir:~/.pywikibot version
Traceback (most recent call last):

File "pwb.py", line 166, in <module>
  if len(sys.argv) > 1:

OSError: -dir:~/.pywikibot.py not found!
<type 'exceptions.OSError'>

But if you put it in the expected order, which I guess is the wanted behaviour (**), then this is OK:

python pwb.py version -dir:~/.pywikibot
Pywikibot: [ssh] pywikibot-core.git (182616b, g4347, 2014/10/20, 19:36:09, OUTDATED)
...
Python: 2.7.6 (default, Mar 22 2014, 22:59:38)
[GCC 4.8.2]

unicode test: ok

I think this bug can be closed unless (*) and (**) are not as we would like this to work.

(In reply to Mpaa from comment #1)

Note that in you example, it also fails even if the directory exists as
-dir: comes before the expected script name.

python pwb.py -dir:~/.pywikibot version
Traceback (most recent call last):

File "pwb.py", line 166, in <module>
  if len(sys.argv) > 1:

OSError: -dir:~/.pywikibot.py not found!
<type 'exceptions.OSError'>

This is 'intentional'. The first parameter after 'pwb.py' MUST be the script you want to execute. Similar to how 'commit' must be directly after 'git' but '--amend' and '-a' after that can be swapped as you like.

Then, as I said, this can be closed.