~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/readdir.py

  • Committer: Robert Collins
  • Date: 2006-06-09 15:34:26 UTC
  • mto: This revision was merged to the branch mainline in revision 3682.
  • Revision ID: robertc@robertcollins.net-20060609153426-803129580b26d89f
Add a replacement for os.listdir which returns file kind information from readdir when it is available. This drops our osutils.walkdirs time further, down to 77ms.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
# Bazaar-NG -- distributed version control
 
2
#
 
3
# Copyright (C) 2006 by Canonical Ltd
 
4
#
 
5
# This program is free software; you can redistribute it and/or modify
 
6
# it under the terms of the GNU General Public License as published by
 
7
# the Free Software Foundation; either version 2 of the License, or
 
8
# (at your option) any later version.
 
9
#
 
10
# This program is distributed in the hope that it will be useful,
 
11
# but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
# GNU General Public License for more details.
 
14
#
 
15
# You should have received a copy of the GNU General Public License
 
16
# along with this program; if not, write to the Free Software
 
17
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 
18
 
 
19
"""Wrapper for readdir which grabs file type from d_type."""
 
20
 
 
21
 
 
22
import os
 
23
 
 
24
 
 
25
def read_dir(path):
 
26
    """Like os.listdir, this reads a directories contents.
 
27
 
 
28
    There is a C module which is recommended which will return
 
29
    a file kind in the second element of the returned tuples.
 
30
 
 
31
    :param path: the directory to list.
 
32
    :return: a list of (basename, None) tuples.
 
33
    """
 
34
    return [(name, None) for name in os.listdir(path)]