Skip to content

Commit baf0f81

Browse files
authored
Merge pull request #10 from lutraconsulting/excluded_files
exclude some files from sync
2 parents d97ae4c + f41529d commit baf0f81

File tree

1 file changed

+25
-10
lines changed

1 file changed

+25
-10
lines changed

mergin/client.py

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,20 @@
1313

1414
this_dir = os.path.dirname(os.path.realpath(__file__))
1515
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+
1630

1731
try:
1832
import dateutil.parser
@@ -54,16 +68,17 @@ def list_project_directory(directory):
5468
for root, dirs, files in os.walk(directory, topdown=True):
5569
dirs[:] = [d for d in dirs if d not in excluded_dirs]
5670
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+
})
6782
return proj_files
6883

6984

0 commit comments

Comments
 (0)