Skip to content

Commit f0284a9

Browse files
author
Iago Veloso
committed
Fix another issue related to modify a list when looping
1 parent e984520 commit f0284a9

File tree

3 files changed

+15
-11
lines changed

3 files changed

+15
-11
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ The easier way to run this project is using docker:
4949
5050
Run example; notice `source` and `my_catalogue` need to be replace with your destinations:
5151
52-
docker run --rm -v $(pwd)/source:/input:ro -v $(pwd)/my_catalogue:/output iago1460/catalogue:1.2.4 --src /input --dst /output --operation copy
52+
docker run --rm -v $(pwd)/source:/input:ro -v $(pwd)/my_catalogue:/output iago1460/catalogue:1.2.5 --src /input --dst /output --operation copy
5353
5454
5555
### In a virtual environment
5656
5757
virtualenv venv
5858
source venv/bin/activate
59-
pip3 install https://github.com/iago1460/photo-cataloguer/archive/1.2.4.zip
59+
pip3 install https://github.com/iago1460/photo-cataloguer/archive/1.2.5.zip
6060
catalogue --help
6161
6262

catalogue/main.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -147,9 +147,10 @@ def main():
147147
chain(*[files[1:] for files in duplicated_list_of_files_to_import])
148148
)
149149

150+
files = src_catalogue.files
150151
if not dst_catalogue:
151-
logging.info(f"Detected {len(src_catalogue.files)} files:")
152-
for file in src_catalogue.files:
152+
logging.info(f"Detected {len(files)} files:")
153+
for file in files:
153154
created = file.get_creation_date()
154155
if not file.is_media_type():
155156
logging.debug(f"Ignoring {file.get_media_type()} file {file.path} ")
@@ -160,8 +161,7 @@ def main():
160161

161162
imported_files = []
162163
if dst_catalogue:
163-
logging.info(f"Processing {len(src_catalogue.files)} files:")
164-
files = src_catalogue.files
164+
logging.info(f"Processing {len(files)} files:")
165165
for file in progressbar.progressbar(files, redirect_stdout=True):
166166
media_type = file.get_media_type()
167167
if not file.is_media_type():

catalogue/model.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -139,15 +139,19 @@ def asdict(self):
139139
class Catalogue:
140140
root_path = None
141141
last_update = None
142-
files = None
142+
_files = None
143143
_files_by_path = None
144144
_files_by_size = None
145145
_files_by_short_hash = None
146146
_files_by_hash = None
147147

148+
@property
149+
def files(self):
150+
return tuple(self._files.copy())
151+
148152
def __init__(self, root_path: Path, files=None, last_update=None):
149153
self.root_path = root_path
150-
self.files = []
154+
self._files = []
151155
self.last_update = last_update
152156
self._files_by_path = {}
153157
self._files_by_size = {}
@@ -216,7 +220,7 @@ def notify(self, file, field, new_value):
216220
if not new_value.is_relative_to(self.root_path):
217221
file.unsubscribe(self)
218222
with suppress(ValueError):
219-
self.files.remove(file)
223+
self._files.remove(file)
220224
with suppress(ValueError):
221225
self._files_by_size.setdefault(file.size, []).remove(file)
222226
with suppress(ValueError):
@@ -232,7 +236,7 @@ def notify(self, file, field, new_value):
232236

233237
def add_file(self, file):
234238
file.subscribe(self)
235-
self.files.append(file)
239+
self._files.append(file)
236240
self._files_by_path[file.path] = file
237241
self._files_by_size.setdefault(file.size, []).append(file)
238242
if file._short_hash:
@@ -295,7 +299,7 @@ def file_asdict(file):
295299
return {
296300
"version": __version__,
297301
"last_update": self.last_update.isoformat(),
298-
"files": [file_asdict(file) for file in self.files],
302+
"files": [file_asdict(file) for file in self._files],
299303
}
300304

301305
def save_db(self):

0 commit comments

Comments
 (0)