pure: provide more correct implementation of posixfile for Windows
requires ctypes
Why is posixfile a class?
Because the implementation needs to use the Python library call os.fdopen [1],
which sets the 'name' attribute on the Python file object it creates to the
mostly meaningless string '<fdopen>', since file descriptors don't have a name.
But users of posixfile depend on the name attribute [2] being set to a proper
value, like Python's built-in 'open' function sets it on file objects.
Python file's name attribute is read-only, so we can't just assign to it after
the file object has alrady been created.
To solve this problem, we save the name of the file on a wrapper object,
and delegate the file function calls to the wrapped (private) file object
using __getattr__.
[1] http://docs.python.org/library/os.html#os.fdopen
[2] http://docs.python.org/library/stdtypes.html#file.name
# Pass all working directory files through check-code.py
import sys, os, imp
rootdir = os.path.abspath(os.path.join(os.path.dirname(sys.argv[0]), '..'))
if not os.path.isdir(os.path.join(rootdir, '.hg')):
sys.stderr.write('skipped: cannot check code on non-repository sources\n')
sys.exit(80)
checkpath = os.path.join(rootdir, 'contrib/check-code.py')
checkcode = imp.load_source('checkcode', checkpath)
from mercurial import hg, ui
u = ui.ui()
repo = hg.repository(u, rootdir)
checked = 0
wctx = repo[None]
for f in wctx:
# ignore removed and unknown files
if f not in wctx:
continue
checked += 1
checkcode.checkfile(os.path.join(rootdir, f))
if not checked:
sys.stderr.write('no file checked!\n')