~ubuntu-branches/ubuntu/quantal/enigmail/quantal-security

« back to all changes in this revision

Viewing changes to build/pymake/pymake/globrelative.py

  • Committer: Package Import Robot
  • Author(s): Chris Coulson
  • Date: 2013-09-13 16:02:15 UTC
  • mfrom: (0.12.16)
  • Revision ID: package-import@ubuntu.com-20130913160215-u3g8nmwa0pdwagwc
Tags: 2:1.5.2-0ubuntu0.12.10.1
* New upstream release v1.5.2 for Thunderbird 24

* Build enigmail using a stripped down Thunderbird 17 build system, as it's
  now quite difficult to build the way we were doing previously, with the
  latest Firefox build system
* Add debian/patches/no_libxpcom.patch - Don't link against libxpcom, as it
  doesn't exist anymore (but exists in the build system)
* Add debian/patches/use_sdk.patch - Use the SDK version of xpt.py and
  friends
* Drop debian/patches/ipc-pipe_rename.diff (not needed anymore)
* Drop debian/patches/makefile_depth.diff (not needed anymore)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
"""
2
 
Filename globbing like the python glob module with minor differences:
3
 
 
4
 
* glob relative to an arbitrary directory
5
 
* include . and ..
6
 
* check that link targets exist, not just links
7
 
"""
8
 
 
9
 
import os, re, fnmatch
10
 
import util
11
 
 
12
 
_globcheck = re.compile('[[*?]')
13
 
 
14
 
def hasglob(p):
15
 
    return _globcheck.search(p) is not None
16
 
 
17
 
def glob(fsdir, path):
18
 
    """
19
 
    Yield paths matching the path glob. Sorts as a bonus. Excludes '.' and '..'
20
 
    """
21
 
 
22
 
    dir, leaf = os.path.split(path)
23
 
    if dir == '':
24
 
        return globpattern(fsdir, leaf)
25
 
 
26
 
    if hasglob(dir):
27
 
        dirsfound = glob(fsdir, dir)
28
 
    else:
29
 
        dirsfound = [dir]
30
 
 
31
 
    r = []
32
 
 
33
 
    for dir in dirsfound:
34
 
        fspath = util.normaljoin(fsdir, dir)
35
 
        if not os.path.isdir(fspath):
36
 
            continue
37
 
 
38
 
        r.extend((util.normaljoin(dir, found) for found in globpattern(fspath, leaf)))
39
 
 
40
 
    return r
41
 
 
42
 
def globpattern(dir, pattern):
43
 
    """
44
 
    Return leaf names in the specified directory which match the pattern.
45
 
    """
46
 
 
47
 
    if not hasglob(pattern):
48
 
        if pattern == '':
49
 
            if os.path.isdir(dir):
50
 
                return ['']
51
 
            return []
52
 
 
53
 
        if os.path.exists(util.normaljoin(dir, pattern)):
54
 
            return [pattern]
55
 
        return []
56
 
 
57
 
    leaves = os.listdir(dir) + ['.', '..']
58
 
 
59
 
    # "hidden" filenames are a bit special
60
 
    if not pattern.startswith('.'):
61
 
        leaves = [leaf for leaf in leaves
62
 
                  if not leaf.startswith('.')]
63
 
 
64
 
    leaves = fnmatch.filter(leaves, pattern)
65
 
    leaves = filter(lambda l: os.path.exists(util.normaljoin(dir, l)), leaves)
66
 
 
67
 
    leaves.sort()
68
 
    return leaves