31 |
|
|
32 |
def listdir(path, extensions, dirs=0): |
def listdir(path, extensions, dirs=0): |
33 |
""" |
""" |
34 |
Returns all directories and files with specific |
listdir(path, extensions, dirs=0) |
35 |
extensions under path. Nonrecursive. |
|
36 |
|
Quite specialized listdir, which returns all directories and files |
37 |
|
with specific extensions under given path. Nonrecursive. |
38 |
|
|
39 |
|
Skipping files starting with '.' or including some of 'CVS', '#', '~'. |
40 |
""" |
""" |
41 |
files = [f for f in os.listdir(path) if not f.startswith('.') |
files = [f for f in os.listdir(path) if not f.startswith('.') |
42 |
and not f == 'CVS' and '#' not in f and '~' not in f] |
and not f == 'CVS' and '#' not in f and '~' not in f] |
43 |
|
|
44 |
files = [f for f in files if extensions.count(f.split('.')[-1]) > 0 \ |
if extensions: |
45 |
or os.path.isdir(slashify(path)+f)] |
files = [f for f in files if extensions.count(f.split('.')[-1]) > 0 \ |
46 |
|
or os.path.isdir(slashify(path)+f)] |
47 |
if not dirs: |
if not dirs: |
48 |
files = [f for f in files if os.path.isfile(slashify(path)+f)] |
files = [f for f in files if os.path.isfile(slashify(path)+f)] |
49 |
return files |
return files |
50 |
|
|
51 |
def slashify(path): |
def slashify(path): |
52 |
""" |
""" |
53 |
Add a trailing slash if not already there. |
slashify(path) |
54 |
|
|
55 |
|
Ends path with a trailing slash, if still necessary. |
56 |
""" |
""" |
57 |
if len(path) > 0: |
if len(path) > 0: |
58 |
return (path+'/').replace('//','/') |
return (path+'/').replace('//','/') |
60 |
|
|
61 |
def relative_path(source, target): |
def relative_path(source, target): |
62 |
""" |
""" |
63 |
Returns a relative path from the source to the target. |
relative_path(source, target) |
64 |
|
|
65 |
|
Returns a relative filepath from the source filepath to the target |
66 |
|
filepath. |
67 |
""" |
""" |
68 |
import config |
import config |
69 |
dbg = config.dbg.shorthand('path') |
dbg = config.dbg.shorthand('path') |