|
13 | 13 |
|
14 | 14 | this_dir = os.path.dirname(os.path.realpath(__file__)) |
15 | 15 | CHUNK_SIZE = 10 * 1024 * 1024 |
| 16 | +IGNORE_EXT = re.compile(r'({})$'.format( |
| 17 | + '|'.join(re.escape(x) for x in ['-shm', '-wal', '~', 'pyc', 'swap']) |
| 18 | +)) |
| 19 | +IGNORE_FILES = ['.DS_Store', '.directory'] |
| 20 | + |
| 21 | + |
| 22 | +def ignore_file(filename): |
| 23 | + name, ext = os.path.splitext(filename) |
| 24 | + if ext and IGNORE_EXT.search(ext): |
| 25 | + return True |
| 26 | + if filename in IGNORE_FILES: |
| 27 | + return True |
| 28 | + return False |
| 29 | + |
16 | 30 |
|
17 | 31 | try: |
18 | 32 | import dateutil.parser |
@@ -54,16 +68,17 @@ def list_project_directory(directory): |
54 | 68 | for root, dirs, files in os.walk(directory, topdown=True): |
55 | 69 | dirs[:] = [d for d in dirs if d not in excluded_dirs] |
56 | 70 | for file in files: |
57 | | - abs_path = os.path.abspath(os.path.join(root, file)) |
58 | | - rel_path = os.path.relpath(abs_path, start=prefix) |
59 | | - # we need posix path |
60 | | - proj_path = '/'.join(rel_path.split(os.path.sep)) |
61 | | - proj_files.append({ |
62 | | - "path": proj_path, |
63 | | - "checksum": generate_checksum(abs_path), |
64 | | - "size": os.path.getsize(abs_path), |
65 | | - "mtime": datetime.fromtimestamp(os.path.getmtime(abs_path), tzlocal()) |
66 | | - }) |
| 71 | + if not ignore_file(file): |
| 72 | + abs_path = os.path.abspath(os.path.join(root, file)) |
| 73 | + rel_path = os.path.relpath(abs_path, start=prefix) |
| 74 | + # we need posix path |
| 75 | + proj_path = '/'.join(rel_path.split(os.path.sep)) |
| 76 | + proj_files.append({ |
| 77 | + "path": proj_path, |
| 78 | + "checksum": generate_checksum(abs_path), |
| 79 | + "size": os.path.getsize(abs_path), |
| 80 | + "mtime": datetime.fromtimestamp(os.path.getmtime(abs_path), tzlocal()) |
| 81 | + }) |
67 | 82 | return proj_files |
68 | 83 |
|
69 | 84 |
|
|
0 commit comments