3
# Permission is hereby granted, free of charge, to any person
4
# obtaining a copy of this software and associated documentation
5
# files (the "Software"), to deal in the Software without
6
# restriction, including without limitation the rights to use,
7
# copy, modify, merge, publish, distribute, sublicense, and/or
8
# sell copies of the Software, and to permit persons to whom the
9
# Software is furnished to do so, subject to the following conditions:
11
# The above copyright notice and this permission notice shall be included
12
# in all copies or substantial portions of the Software.
14
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
15
# OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17
# THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
19
# FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER
20
# DEALINGS IN THE SOFTWARE.
27
This source file is a modified version of autopath.py taken
30
http://codespeak.net/svn/pypy/dist/pypy/tool/autopath.py
32
It has just been modified to fit with pyinotify.
34
USAGE: in order to use this script, edit it
35
- root_dir: set the root directory of your project
36
- this_dir: set the location of writable version of this script
39
self cloning, automatic path configuration
41
copy this into any subdirectory of pypy from which scripts need
42
to be run, typically all of the test subdirs.
43
The idea is that any such script simply issues
47
and this will make sure that the parent directory containing 'src'
50
If you modify the master version (in src/autopath.py) you can
51
directly run it which will copy itself on all autopath.py files
52
it finds under the src root directory.
54
This module always provides these attributes:
56
root_dir src root directory path
57
this_dir directory where this autopath.py resides
64
""" return (partdir, this_dir) and insert parent of partdir
65
into sys.path. If the parent directories don't have the part
66
an EnvironmentError is raised."""
70
head = this_dir = os.path.realpath(os.path.dirname(__file__))
72
head = this_dir = os.path.realpath(os.path.dirname(sys.argv[0]))
76
head, tail = os.path.split(head)
80
raise EnvironmentError, "'%s' missing in '%r'" % (partdir, this_dir)
82
checkpaths = sys.path[:]
83
d_root = os.path.join(head, '')
86
orig = checkpaths.pop()
87
fullorig = os.path.join(os.path.realpath(orig), '')
88
if fullorig.startswith(d_root):
89
if os.path.exists(os.path.join(fullorig, '__init__.py')):
91
if head not in sys.path:
92
sys.path.insert(0, head)
95
for name, mod in sys.modules.items():
96
fn = getattr(mod, '__file__', None)
97
if '.' in name or not isinstance(fn, str):
99
newname = os.path.splitext(os.path.basename(fn))[0]
100
if not newname.startswith(part + '.'):
102
path = os.path.join(os.path.dirname(os.path.realpath(fn)), '')
103
if path.startswith(d_root) and newname != part:
104
modpaths = os.path.normpath(path[len(d_root):]).split(os.sep)
105
if newname != '__init__':
106
modpaths.append(newname)
107
modpath = '.'.join(modpaths)
108
if modpath not in sys.modules:
109
munged[modpath] = mod
111
for name, mod in munged.iteritems():
112
if name not in sys.modules:
113
sys.modules[name] = mod
115
prename = name[:name.rfind('.')]
116
postname = name[len(prename)+1:]
117
if prename not in sys.modules:
119
if not hasattr(sys.modules[prename], postname):
120
setattr(sys.modules[prename], postname, mod)
122
return partdir, this_dir
125
""" clone master version of autopath.py into all subdirs """
126
from os.path import join, walk
127
if not this_dir.endswith(join('src','pyinotify')):
128
raise EnvironmentError("can only clone master version "
129
"'%s'" % join(root_dir, 'pyinotify',_myname))
132
def sync_walker(arg, dirname, fnames):
133
if _myname in fnames:
134
fn = join(dirname, _myname)
145
s = open(join(root_dir, 'pyinotify', _myname), 'rb').read()
146
walk(root_dir, sync_walker, s)
148
_myname = 'autopath.py'
150
# set guaranteed attributes
152
root_dir, this_dir = __dirinfo('src')
154
if __name__ == '__main__':