

def rehashdir_f(self, arg):
    ' Add executables in all specified dirs to alias table\n     \n    Usage:\n\n    %rehashdir c:/bin;c:/tools\n      - Add all executables under c:/bin and c:/tools to alias table, in \n      order to make them directly executable from any directory.\n        \n      Without arguments, add all executables in current directory.\n      \n    '

    def isjunk(fname):
        junk = ['*~']
        for j in junk:
            if fnmatch.fnmatch(fname, j):
                return True
        return False
    created = []
    if (not arg):
        arg = '.'
    path = list(map(os.path.abspath, arg.split(';')))
    alias_table = self.shell.alias_manager.alias_table
    if (os.name == 'posix'):
        isexec = (lambda fname: (os.path.isfile(fname) and os.access(fname, os.X_OK)))
    else:
        try:
            winext = os.environ['pathext'].replace(';', '|').replace('.', '')
        except KeyError:
            winext = 'exe|com|bat|py'
        if ('py' not in winext):
            winext += '|py'
        execre = re.compile(('(.*)\\.(%s)$' % winext), re.IGNORECASE)
        isexec = (lambda fname: (os.path.isfile(fname) and execre.match(fname)))
    savedir = os.getcwd()
    try:
        if (os.name == 'posix'):
            for pdir in path:
                os.chdir(pdir)
                for ff in os.listdir(pdir):
                    if (isexec(ff) and (not isjunk(ff))):
                        (src, tgt) = (os.path.splitext(ff)[0], os.path.abspath(ff))
                        created.append(src)
                        alias_table[src] = (0, tgt)
        else:
            for pdir in path:
                os.chdir(pdir)
                for ff in os.listdir(pdir):
                    if (isexec(ff) and (not isjunk(ff))):
                        (src, tgt) = (execre.sub('\\1', ff), os.path.abspath(ff))
                        src = src.lower()
                        created.append(src)
                        alias_table[src] = (0, tgt)
        self.shell.alias_table_validate()
    finally:
        os.chdir(savedir)
    return created

dataset/ETHPy150Open ipython/ipython-py3k/IPython/quarantine/ipy_rehashdir.py rehashdir_f/original