1 # -*- coding: utf-8 -*-
2 ###########################################################################
3 # Copyright (C) 2008 by Andrew Mahone
4 # <andrew.mahone@gmail.com>
6 # Copyright: See COPYING file that comes with this distribution
8 ###########################################################################
10 from audiomangler
import Config
, msg
, err
, fatal
, WARNING
, ERROR
19 buf
= fsrc
.read(16384)
29 mode
= stat
.S_IMODE(st
.st_mode
)
30 if hasattr(os
, 'utime'):
32 os
.utime(dst
, (st
.st_atime
, st
.st_mtime
))
43 def test_splits(dir_list
,transcode
=False):
44 from audiomangler
import get_codec
45 if transcode
and Config
['type']:
46 targetcodec
= Config
['type']
47 if ',' in targetcodec
:
48 allowedcodecs
= targetcodec
.split(',')
49 targetcodec
= allowedcodecs
[0]
50 allowedcodecs
= frozenset(allowedcodecs
)
52 allowedcodecs
= frozenset((targetcodec
,))
53 targetcodec
= get_codec(targetcodec
)
54 postadd
= lambda type_
: {} if type_
in allowedcodecs
else {'type':targetcodec
.type_
,'ext':targetcodec
.ext
}
56 postadd
= lambda type_
: {}
57 for (dir_
, files
) in dir_list
.items():
61 dst
= fsencode(file_
.format(postadd
=postadd(file_
.type_
)))
62 dstdir
= os
.path
.split(dst
)[0]
65 onsplit
= Config
['onsplit']
66 if onsplit
== 'abort':
67 fatal(consoleformat
=u
"tracks in %(dir_p)s would be placed in different target directories, aborting\nset onsplit to 'warn' or 'ignore' to proceed anyway",
68 format
="split: %(dir_)r", dir_
=dir_
, dir_p
=fsdecode(dir_
),nologerror
=1)
71 return string
.encode(Config
['fs_encoding'],Config
.get('fs_encoding_err','underscorereplace'))
74 return string
.decode(Config
['fs_encoding'],Config
.get('fs_encoding_err','replace'))
76 __all__
= ['copy','move','fsencode','fsdecode','test_splits']