Commit Graph

6009 Commits

Author SHA1 Message Date
Laurent Monin
76b85a4e1f Introduce ImageList.copy()
- imagelist[:] returns a list, not an ImageList
- it returns an instance of ImageList
2019-03-22 10:32:31 +01:00
Laurent Monin
caa03f3f0a ImageList: inherit from MutableSequence instead of list
Note: i got rid of old __getitem__() which makes no sense imho
It returned an instance of itself for each element, not sure what was the goal
2019-03-22 10:32:31 +01:00
Laurent Monin
78c9890e21 Drop Metadata.append_image(), use Metadata.images.append() instead 2019-03-22 10:32:31 +01:00
Laurent Monin
6bf103bf34 Drop useless Metadata.remove_image() 2019-03-22 10:32:31 +01:00
Laurent Monin
0b837ebe8d Move Metadata.images_to_be_saved_to_tags() to ImageList.to_be_saved_to_tags()
- make it a generator
- drop @property, it's a function, no point in hiding it
- add tests
2019-03-22 10:32:31 +01:00
Laurent Monin
eb73ea6bc4 Replace Metadata.get_single_front_image() with ImageList.get_front_image()
- it makes much more sense, Metadata.images is an ImageList
- minimal changes required
- add tests for it
2019-03-22 10:32:31 +01:00
Laurent Monin
d60afe35d7 ImageList(): fix untestable class, since it requires gettext...
- image.types_as_string() was called from get_image_type() without translate=False
- dependency wasn't satisfied, so impossible to test as is
- make tests depending on languages isn't a good idea anyway
- use new CoverArtImage.normalized_types() instead
- simplify code
- add tests for ImageList.append() and ImageList.__eq__()
2019-03-22 10:32:31 +01:00
Laurent Monin
45e70a676f CoverArtImage: add a function normalizing types
This is needed because types can be in any order (and even contains duplicate)
So output of types_as_string() was differing, depending on how types were set
2019-03-22 10:32:31 +01:00
Laurent Monin
9d7b8dc995 CoverArtImage.__init__(): add parameters to override supported types
It's convenient for testing
2019-03-22 10:32:31 +01:00
Laurent Monin
4990cef589 Fix crash introduced when opening Options: KeyError: 'clear_existing_tags'
It was introduced in 04dcd4691b, settings for examples were missing this setting
2019-03-22 10:28:56 +01:00
Laurent Monin
ca069ae767 Merge pull request #1141 from zas/metadata_use_cleanup
Metadata cleanup, second pass
2019-03-21 21:52:14 +01:00
Laurent Monin
b58c353259 Metadata.__setitem__(): accept any iterable as values
https://github.com/metabrainz/picard/pull/1137#discussion_r266974994
2019-03-21 11:53:39 +01:00
Laurent Monin
b5cc54e255 Make Metadata.__setitem__() consistent with Metadata.add() regarding 0 values
m['tag'] = 0 wasn't doing the same thing as m.add('tag', 0), because the test in __setitem__()
was different: if value vs if value or value == 0
So modify it to make behavior much more consistent.

m['tag'] = 0 or m.add('tag', 0) actually set tag to ['0']
m.add('tag', '') does nothing
m['tag'] = '' explicitly delete the tag (removing it from store, adding it to deleted tags)
m = Metadata(tag='') doesn't create an entry 'tag' (at all)
m = Metadata(tag=0) creates a tag, with internal value ['0']

This way, one can rewrite:

self.metadata = Metadata()
self.metadata['album'] = name
self.metadata['albumartist'] = artist
self.metadata['totaltracks'] = 0

to:
self.metadata = Metadata(album=name, albumartist=artist, totaltracks=0)

Without this patch, totaltracks wasn't set at all.
2019-03-21 11:38:58 +01:00
Laurent Monin
13e8e83bc4 Merge pull request #1137 from zas/metadata_mapping
Metadata class: inherit from MutableMapping instead of dict
2019-03-21 10:52:17 +01:00
Laurent Monin
99604ac01f Test and annotate the case of del with unknown keys 2019-03-20 21:17:06 +01:00
Laurent Monin
f6e3aedf7a Raises TypeError if Metadata.update() is called without argument
This is more consistent with dict.update() behavior (and shouldn't happen anyway).
2019-03-20 11:03:56 +01:00
Laurent Monin
39b069adae Test Metadata.len() with images 2019-03-20 10:42:50 +01:00
Laurent Monin
1a1e250489 Add tests for Metadata with images 2019-03-20 10:42:50 +01:00
Laurent Monin
2aec4a4185 Metadata.update(): fix a corner case leading to inconsistent data
```python
m = Metadata(tag1='a', tag2='b')
del m['tag1']
```

```
m store: {'tag2': ['b']}
m deleted: {'tag1'}
```

```python
m2 = Metadata(tag1='c', tag2='d')
del m2['tag2']
```

```
m2 store: {'tag2': ['b']}
m2 deleted: {'tag1'}
```

```python
m.update(m2)
```

```
m store: {'tag1': ['c']}
m deleted: {'tag1', 'tag2'} <---- this was incorrect, and untested case
```

This patch fixes it, and results to:

```
m store: {'tag1': ['c']}
m deleted: {'tag2'}
```
2019-03-20 10:42:50 +01:00
Laurent Monin
090c1e4eaf Reduce code redundancy in tests 2019-03-20 10:42:50 +01:00
Laurent Monin
4e977cfb2c Improve dict compatibility of Metadata.update() + minor fixes 2019-03-20 10:42:50 +01:00
Laurent Monin
503b5203f1 Metadata class: inherit from MutableMapping instead of dict 2019-03-20 10:42:49 +01:00
Laurent Monin
2282114147 Merge pull request #1140 from zas/preservetimes_test
Fix broken preserve times test logic
2019-03-20 00:03:34 +01:00
Laurent Monin
a9cf9d55c8 File._preserve_times(): fix broken logic
- access times are likely to differ, a race condition is possible
- stat() has be done after the change to be able to compare
- comments added
- force sync after modifying test file
- make code easier to understand

See https://github.com/metabrainz/picard/pull/1132#issuecomment-474113665
2019-03-19 23:21:59 +01:00
Laurent Monin
a13a95723e Merge pull request #1136 from zas/_make_filename_fix
Make filename fix
2019-03-19 18:54:52 +01:00
Laurent Monin
70e08b47db Merge pull request #1135 from zas/file_changed_normal
Cleanup File state, tracknumber, discnumber properties
2019-03-19 17:20:51 +01:00
Laurent Monin
1accac01df Call (new) File.update_item() where appropriate
In set_pending()/clear_pending() we don't need a full update.
2019-03-18 13:18:03 +01:00
Laurent Monin
0b64620bcc Cleanup File state, tracknumber, discnumber properties
- use @property and @property.setter decorators
- make those more obvious
- drop force_update / update parameters as they were hiding File.update() calls
- remove redundant File.update() calls
- state property: only emit tagger_stats_changed signal when num_pending_files actually changed
- simplify tests in File.update(), introduced in 62c7056236
2019-03-18 13:18:00 +01:00
Laurent Monin
d4528baa2e Merge pull request #1132 from zas/os_stat_utime
PICARD-1494: Improve file times preservation using os.utime() ns parameter
2019-03-18 13:08:06 +01:00
Laurent Monin
24a5e8dbea Merge pull request #1133 from zas/cluster_add_file
Cluster.add_file(): reduce code redundancy, using add_files([file])
2019-03-18 12:09:17 +01:00
Laurent Monin
812b3ab263 Merge pull request #1138 from zas/collection_cleanup
Collection cleanup
2019-03-18 12:08:49 +01:00
Laurent Monin
85b0f7dd50 Merge pull request #1139 from phw/PICARD-1493-fix-config-upgrade-messagebox
PICARD-1493: Fixed opening message box during 1.0 config upgrade
2019-03-18 12:07:49 +01:00
Philipp Wolfer
b8c60f7bf9 PICARD-1493: Fixed opening message box during 1.0 config upgrade
Using QMessageBox.question with custom buttons is not supported in Qt5. Use custom implementation.
2019-03-18 10:42:50 +01:00
Laurent Monin
637320c8a8 Collection: reduce code redundancy and make it easier to read
- Introduce helper function get_user_collection()
- Add a debug output to list found user collections (with id and name)
2019-03-17 23:16:38 +01:00
Laurent Monin
87eaeceafa Collection: don't be quiet add/remove error
Report it on status bar and error log
2019-03-17 22:39:10 +01:00
Laurent Monin
72d6dfb313 Collection: reduce code redundancy
Most of the code is shared between add and remove actions
2019-03-17 22:19:35 +01:00
Laurent Monin
04dcd4691b _script_to_filename(): be consistent, use settings if defined 2019-03-15 17:52:08 +01:00
Laurent Monin
488b0441fb Add TODO / FIXME
This code is messy at best, prolly buggy in fact.
2019-03-15 10:41:29 +01:00
Laurent Monin
7ae49476ef Use str.starswith() 2019-03-15 10:40:55 +01:00
Laurent Monin
99d646d4f8 Simplify test for non-empty naming_format variable 2019-03-15 10:36:40 +01:00
Laurent Monin
9bf803c8c2 Use intermediate variable win_compat, improve consistency 2019-03-15 10:35:16 +01:00
Laurent Monin
f7011a7bee Move part of File._make_filename() to new File._format_filename() 2019-03-15 10:33:00 +01:00
Laurent Monin
08a7ce0d28 Fix _make_filename(): use settings instead of config.setting
- use passed settings (which defaults to config.setting) as in the rest of the function
- remove reference to nonexistent option 'windows_compatibility_drive_root'
2019-03-15 10:06:59 +01:00
Laurent Monin
6a63c3e5be Improve file times preservation using os.utime() ns parameter (py >= 3.3)
https://docs.python.org/3/library/os.html#os.utime
Since Python 3.3, ns parameter is available
"The best way to preserve exact times is to use the st_atime_ns and st_mtime_ns
fields from the os.stat() result object with the ns parameter to utime."

Make time preservation testable.
2019-03-14 10:57:55 +01:00
Laurent Monin
1ff54bdd83 Cluster.add_file(): reduce code redundancy, using add_files([file]) 2019-03-14 10:54:33 +01:00
Laurent Monin
b6dd3dfecd Merge pull request #1131 from phw/PICARD-1491-fix-plugin-list-version-check
PICARD-1491: Fix plugin version check when loading plugin list
2019-03-12 19:16:29 +01:00
Laurent Monin
95f60e5d94 Merge pull request #1129 from phw/PICARD-1490-fix-local-cover-art
PICARD-1490: Fix local cover art loading on Windows
2019-03-12 19:14:15 +01:00
Philipp Wolfer
0cdbfdd586 PICARD-1491: Fix plugin version check when loading plugin list 2019-03-12 18:05:53 +01:00
Philipp Wolfer
6ce942f2b1 More NEWS.txt formatting fixes 2019-03-12 16:25:47 +01:00
Philipp Wolfer
bba5cef5fe PICARD-1490: Run Windows path test on Windows only 2019-03-12 16:18:45 +01:00