3

I am probably using pywikibot in ways that were beyond the ways the project was intended. I want several users to use the same user-config.py. Unfortunately this gives me this error:

WARNING: Skipped '...pywikibot/user-config.py': owned by someone else.

My current solution is to just comment some of this code at pywikibot/config2.py:

    _filestatus = os.stat(_filename)
    _filemode = _filestatus[0]
    _fileuid = _filestatus[4]
    if sys.platform == 'win32' or _fileuid in [os.getuid(), 0]:
        if sys.platform == 'win32' or _filemode & 0o02 == 0:
            with open(_filename, 'rb') as f:
                exec(compile(f.read(), _filename, 'exec'), _uc)
        else:
            print("WARNING: Skipped '%(fn)s': writeable by others."
                  % {'fn': _filename})
    else:
        print("WARNING: Skipped '%(fn)s': owned by someone else."
              % {'fn': _filename})

I.e. I'm only keeping this part:

    with open(_filename, 'rb') as f:
        exec(compile(f.read(), _filename, 'exec'), _uc)

It's really not a great way to handle this. So I'm curious, is there a better way? Better: things won't break here if I (or someone else in the future) upgrades Pywikibot.

(Creating an issue in the Pywikibot bug tracker could be a good way to start work towards a more sustainable solution but the project is so spread out I can't really figure out where to do that.)

2
  • Is this on Windows or Linux?
    – wallyk
    Aug 16, 2016 at 17:30
  • Good question. It was on Windows with Cygwin. But IIRC I've experienced a very similar issue on Linux in the past.
    – the
    Aug 16, 2016 at 20:59

2 Answers 2

1

I found this thread when trying to debug this same issue. I'm using WSL and ended up using OP's workaround (commenting out those lines of code) but additionally had to comment one more line of code:

def file_mode_checker(filename, mode=0o600):
    """Check file mode and update it, if needed.

    @param filename: filename path
    @type filename: basestring
    @param mode: requested file mode
    @type mode: int

    """
    warn_str = 'File {0} had {1:o} mode; converted to {2:o} mode.'
    st_mode = os.stat(filename).st_mode
    if stat.S_ISREG(st_mode) and (st_mode - stat.S_IFREG != mode):
        # the following is the line I commented:
        # os.chmod(filename, mode)
        # re-read and check changes
        if os.stat(filename).st_mode != st_mode:
            warn(warn_str.format(filename, st_mode - stat.S_IFREG, mode))

The above is from __init__.py in pywikibot/tools. I haven't updated PWB in a couple years so not sure how much it's changed since, but hopefully this is relevant to someone (or at least it will be useful to me whenever I upgrade PWB lol).

The issue in WSL specifically is that I'm unable to chown to myself so afaik the only other option is to do everything as root, and I guess I'd rather comment this code than be root for everything.


Update - I wrote an entire blog post about making PWB work in WSL 1 if anyone else is interested in doing this

0

change the read/write permission to read-only with:

chmod 600 user-config.py

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.