Commit graph

89 commits

Author SHA1 Message Date
Adrian Sampson
2023344019 Windows: fix relative paths in normpath()
The changes introduced in rc1 caused paths to be syspath-ified before they were
passed to os.path.abspath. The magic prefix caused them to be interpreted as
absolute paths even if they were relative. The fix is, in this *isolated*
case, to use Unicode but prefix-free paths in calls to the os.path.* functions.
Those functions need to act on Unicode objects but seem to be purely syntactic
-- nothing is tripped up by using long filenames without the magic prefix.
2012-12-19 12:19:23 -08:00
Adrian Sampson
c499be05ea fix some tests under PyPy
In PyPy's pure-Python implementation of the sqlite3 module, sqlite3.Row has no
__len__ method. This works around calling len(row).
2012-11-27 21:47:15 -08:00
Adrian Sampson
eef87c2189 truncation incorporates extension length (GC-461) 2012-11-27 16:54:50 -08:00
Adrian Sampson
16f207e927 make syspath/bytestring_path roundtrip on Windows
This is an alternative to #58 that makes bytestring_path perform more like the
inverse of syspath on Windows. This way, we can convert to syspath, operate on
the path, and then bring back to internal representation without data loss. This
involves looking for the magic prefix on the Unicode string and removing it
before encoding to the internal (UTF-8) representation.
2012-10-20 23:49:43 -07:00
Adrian Sampson
ef248576f0 bpd: fix crash w/ unicode extensions (GC-439) 2012-09-17 10:24:34 -07:00
Adrian Sampson
44459f88d0 Windows: represent paths as UTF-8 internally
When we store paths in the database, we always use bytestrings for consistency.
But on Windows, these paths are converted back to Unicode before they reach the
FS API. This means that the codec used internally is immaterial.

However, we were naively using sys.getfilesystemencoding() for this internal
representation. On Windows, this is MBCS, a broken encoding that can't represent
all of Unicode. This change replaces that with UTF-8, a "real" codec.

The decoding bit now tries UTF-8 and falls back to MBCS for compatibility with
existing databases. The reality, however, is that existing databases may not
work with this change -- a byte string may represent something different in
UTF-8 from what it represents in MBCS. So users should recreated their DBs if
anything goes wrong.
2012-07-17 10:54:47 -07:00
Adrian Sampson
d88afbad11 library maintains per-thread DB conns. (GC-399) 2012-06-08 10:49:47 -07:00
Adrian Sampson
a28f930c52 transaction objects to control DB access
In an attempt to finally address the longstanding SQLite locking issues, I'm
introducing a way to explicitly, lexically scope transactions. The Transaction
class is a context manager that always fully fetches after SELECTs and
automatically commits on exit. No direct access to the library is allowed, so
all changes will eventually be committed and all queries will be completed. This
will also provide a debugging mechanism to show where concurrent transactions
are beginning and ending.

To support composition (transaction reentrancy), an internal, per-Library stack
of transactions is maintained. Commits only happen when the outermost
transaction exits. This means that, while it's possible to introduce atomicity
bugs by invoking Library methods outside of a transaction, you can conveniently
call them *without* a currently-active transaction to get a single atomic
action.

Note that this "transaction stack" concepts assumes a single Library object per
thread. Because we need to duplicate Library objects for concurrent access due
to sqlite3 limitation already, this is fine for now. Later, the interface should
provide one transaction stack per thread for shared Library objects.
2012-05-06 23:24:05 -07:00
Adrian Sampson
8f128876e2 %aunique: use a single field instead of a sequence
For a less cumbersome uniquifying string, only a single field value is now used
instead of a prefix of a list of fields. The old semantics had two problems that
made it both unnecessary and insufficient:
- In the vast majority of cases, a single field suffices (year OR label OR
  catalog number, for example) and forcing the string to include many identical
  fields is unnecessary.
- If the albums are very similar, a prefix may be insufficient; a better
  solution may be found with an arbitrary subset. (Of course, we can't afford to
  search the whole power set.)
So we're going with a single field for now. This should cause far less
confusion.
2012-04-24 21:15:50 -07:00
Adrian Sampson
8fe3738710 default arguments to %aunique{} (#190) 2012-04-24 20:34:51 -07:00
Adrian Sampson
f20fbede5e sanitize output of %unique 2012-04-20 10:17:19 -07:00
Adrian Sampson
ffa2402ff4 revamp default character substitutions
There's no longer a distinction between Unix and Windows substitutions. Enough
users reported problems with Windows-forbidden characters on Samba shares that
it seems appropriate to make all filenames Windows-safe, even on Unix. Users who
really want those additional characters (<>:"?*|\) can re-enable them via the
"replace" option. Nobody has complained about beets being *too* conservative.

This also adds sanitization of control characters, which is an all-around good
idea, and the substitution now runs in the Unicode (rather than byte) domain.
2012-04-03 14:22:38 -07:00
Adrian Sampson
781c26ffd0 normalize to NFC on non-Mac platforms (#367) 2012-03-27 10:44:11 -07:00
Adrian Sampson
06f137bff9 %unique path function
Generates disambiguating strings to distinguish albums from one another. To be
used as the basis for a simpler path field, $unique, as a default disambiguator.
2012-03-22 18:04:06 -07:00
Adrian Sampson
5a0105b12c fall back to unittest2 (#275) 2012-01-31 15:25:09 -08:00
Adrian Sampson
bb4be3a303 lower case extensions in destination (#331) 2012-01-31 15:11:19 -08:00
Adrian Sampson
337e2556a6 sanitize path components from plugins (#315) 2012-01-30 16:53:05 -08:00
Adrian Sampson
fe33926038 add new audio properties to library/DB
$samplerate now expands to "##kHz" in path formats.
2012-01-27 16:04:51 -08:00
Adrian Sampson
0e81900675 mtime tests at integral second resolution (#298) 2012-01-18 14:08:15 -08:00
Adrian Sampson
d73c133a53 query-conditioned path formats (#210)
Also, Library.path_formats is now a list of pairs instead of a dictionary. (I
would have used an OrderedDict, but that was added in 2.7.)
2011-12-28 19:01:13 -08:00
Adrian Sampson
b44195853c zero-pad date values in path formats (#282) 2011-12-22 15:57:02 -08:00
Adrian Sampson
b493bc7004 configurable pathname substitution (#115) 2011-12-19 18:37:35 -08:00
Adrian Sampson
46a3bde5b5 fix empty function arguments
Previously, an empty argument was treated as "not an argument at all". Now,
every function call always has at least one argument -- i.e., %foo{} is a
function call whose only argument is "" -- and %foo{,bar} is valid syntax.
2011-12-16 12:08:39 -08:00
Adrian Sampson
255fbf6c41 add a small set of default path functions (#231) 2011-12-15 14:27:59 -08:00
Adrian Sampson
b9d6928278 consistency policy for DB mtimes (#227) 2011-12-03 17:18:51 -08:00
Adrian Sampson
a448879ca9 infer album artist or VA for as-is imports (#161) 2011-06-29 10:36:07 -07:00
Adrian Sampson
40035bfdf4 format $bitrate in path formats as "XXkbps" 2011-06-13 20:52:52 -07:00
Adrian Sampson
85ddfa4381 relocatable test rsrc directory 2011-04-12 14:26:48 -07:00
Adrian Sampson
e669868896 move a bunch of functions to util 2011-04-10 21:48:05 -07:00
Adrian Sampson
b28ef722a5 singleton path format 2011-04-09 14:50:48 -07:00
Adrian Sampson
61ef980797 $albumartist falls back to $artist (#166) 2011-04-09 12:36:52 -07:00
Adrian Sampson
7f7c45b252 refactoring, tests, NEWS note on wlof's directory-pruning patch 2011-03-23 16:53:24 -07:00
Adrian Sampson
43a5e913a7 move some reused testing stuff to _common module 2011-03-23 16:15:18 -07:00
Adrian Sampson
f69f69cecf merge in some fixes from wlof's repository 2011-03-23 15:50:11 -07:00
Adrian Sampson
096816cba7 path formats can now be specified by album type 2011-03-22 20:09:27 -07:00
wlof
7be77a99d9 .. is now inserted at the beginning of sys.path so that local beets
files are used instead of installed ones
2011-03-19 01:45:35 +01:00
Adrian Sampson
0d869340ec fixes for album artist inference
- Inference must be enabled explicitly with the "infer_aa" flag. It does not
  happen transparently.
- Infer both artist and artist ID.
- Fixed a bug where only the database row was using the inferred data, not the
  returned data structure.
- Added tests.
2011-02-18 12:17:22 -08:00
Adrian Sampson
ce5f9f9936 move BaseAlbum tests to test_db (with other album tests) 2011-02-18 11:36:52 -08:00
Adrian Sampson
eb1a6c8ae3 tests for multiple paths feature; legacy path_format overrides 2011-01-24 19:40:09 -08:00
Adrian Sampson
66b3e5675c update default path formats; make $artist fall back on $albumartist
The default path formats now include both a "default", which is the same as
before but now uses $albumartist instead of $artist, and a "comp" path, which
uses a Compilations directory. Old paths are supported as-is by letting $artist
refer to either a track artist (when present, as it is in all old library
tracks) or album artist (when the track artist isn't present, as is the case
with most albums imported now).
2011-01-24 10:14:19 -08:00
Adrian Sampson
0c24376e6a migration of album table's artist field to albumartist; fix ls -a 2011-01-23 22:49:52 -08:00
Adrian Sampson
75e0924832 move _sanitize_for_path to module namespace 2011-01-23 19:59:41 -08:00
Adrian Sampson
6ade5635e1 light refactoring and renaming for patch
Changed mb_albumtype to albumtype.
Changed album_artist to albumartist.
Reinstated subset relationship between album fields and item fields.
2011-01-23 19:49:48 -08:00
Adrian Sampson
342c360285 apply jonathan.buchanan's compilation patch from issue #48 2011-01-23 18:41:35 -08:00
Adrian Sampson
0b0d7e0b67 fixes for tests' cross-platformness by jonathan.buchanan 2011-01-20 09:29:09 -08:00
Adrian Sampson
4359845a01 prohibit trailing spaces in Windows filenames 2011-01-19 13:17:54 -08:00
Adrian Sampson
5904852e4b use "long filename" support instead of short truncation on Windows (#127)
(Patch by jonathan.buchanan. Thanks!)
2011-01-19 13:14:54 -08:00
Adrian Sampson
ab35db7b7a truncate path components to 30 characters on Windows (work around #120) 2011-01-18 20:13:57 -08:00
Adrian Sampson
7cf10d13e5 fix escaping of / in paths on Windows 2010-09-27 16:56:40 -07:00
Adrian Sampson
633b97b302 decode unicode art paths from legacy databases 2010-08-06 10:44:00 -07:00