mirror of
https://github.com/beetbox/beets.git
synced 2025-12-26 02:24:33 +01:00
itime (#264): name change
I changed the "itime" field to "added" and the %format function to %time.
This commit is contained in:
parent
4704c4a3c8
commit
6f77169ad2
4 changed files with 16 additions and 13 deletions
|
|
@ -104,7 +104,7 @@ ITEM_FIELDS = [
|
|||
('bitdepth', 'int', False, True),
|
||||
('channels', 'int', False, True),
|
||||
('mtime', 'int', False, False),
|
||||
('itime', 'datetime', False, False),
|
||||
('added', 'datetime', False, False),
|
||||
]
|
||||
ITEM_KEYS_WRITABLE = [f[0] for f in ITEM_FIELDS if f[3] and f[2]]
|
||||
ITEM_KEYS_META = [f[0] for f in ITEM_FIELDS if f[3]]
|
||||
|
|
@ -116,7 +116,7 @@ ITEM_KEYS = [f[0] for f in ITEM_FIELDS]
|
|||
ALBUM_FIELDS = [
|
||||
('id', 'integer primary key', False),
|
||||
('artpath', 'blob', False),
|
||||
('itime', 'datetime', True),
|
||||
('added', 'datetime', True),
|
||||
|
||||
('albumartist', 'text', True),
|
||||
('albumartist_sort', 'text', True),
|
||||
|
|
@ -203,7 +203,7 @@ def format_for_path(value, key=None, pathmod=None):
|
|||
elif key == 'samplerate':
|
||||
# Sample rate formatted as kHz.
|
||||
value = u'%ikHz' % ((value or 0) // 1000)
|
||||
elif key in ('itime', 'mtime'):
|
||||
elif key in ('added', 'mtime'):
|
||||
# Times are formatted to be human-readable.
|
||||
value = time.strftime(beets.config['time_format'].get(unicode),
|
||||
time.localtime(value))
|
||||
|
|
@ -1295,7 +1295,7 @@ class Library(BaseLibrary):
|
|||
# Item manipulation.
|
||||
|
||||
def add(self, item, copy=False):
|
||||
item.itime = time.time()
|
||||
item.added = time.time()
|
||||
if copy:
|
||||
self.move(item, copy=True)
|
||||
|
||||
|
|
@ -1510,7 +1510,7 @@ class Library(BaseLibrary):
|
|||
|
||||
# When adding an album and its items for the first time, the
|
||||
# items do not yet have a timestamp.
|
||||
album_values['itime'] = time.time()
|
||||
album_values['added'] = time.time()
|
||||
|
||||
with self.transaction() as tx:
|
||||
sql = 'INSERT INTO albums (%s) VALUES (%s)' % \
|
||||
|
|
@ -1826,8 +1826,8 @@ class DefaultTemplateFunctions(object):
|
|||
return unidecode(s)
|
||||
|
||||
@staticmethod
|
||||
def tmpl_format(s, format):
|
||||
"""Format the import time to any format according to time.strfime()
|
||||
def tmpl_time(s, format):
|
||||
"""Format a time value using `strftime`.
|
||||
"""
|
||||
cur_fmt = beets.config['time_format'].get(unicode)
|
||||
return time.strftime(format, time.strptime(s, cur_fmt))
|
||||
|
|
|
|||
|
|
@ -1014,7 +1014,10 @@ def _convert_type(key, value, album=False):
|
|||
def modify_items(lib, mods, query, write, move, album, confirm):
|
||||
"""Modifies matching items according to key=value assignments."""
|
||||
# Parse key=value specifications into a dictionary.
|
||||
allowed_keys = library.ALBUM_KEYS if album else library.ITEM_KEYS_WRITABLE + ['itime']
|
||||
if album:
|
||||
allowed_keys = library.ALBUM_KEYS
|
||||
else:
|
||||
allowed_keys = library.ITEM_KEYS_WRITABLE + ['added']
|
||||
fsets = {}
|
||||
for mod in mods:
|
||||
key, value = mod.split('=', 1)
|
||||
|
|
|
|||
Binary file not shown.
|
|
@ -365,7 +365,7 @@ class DestinationTest(unittest.TestCase):
|
|||
self.assertEqual(val, u'12kHz')
|
||||
|
||||
def test_component_sanitize_datetime(self):
|
||||
val = beets.library.format_for_path(1368302461.210265, 'itime',
|
||||
val = beets.library.format_for_path(1368302461.210265, 'added',
|
||||
posixpath)
|
||||
self.assertTrue(val.startswith('2013'))
|
||||
|
||||
|
|
@ -985,16 +985,16 @@ class ImportTimeTest(_common.TestCase):
|
|||
super(ImportTimeTest, self).setUp()
|
||||
self.lib = beets.library.Library(':memory:')
|
||||
|
||||
def test_itime_for_album(self):
|
||||
def added(self):
|
||||
self.track = item()
|
||||
self.album = self.lib.add_album((self.track,))
|
||||
self.assertGreater(self.album.itime, 0)
|
||||
self.assertGreater(self.track.itime, 0)
|
||||
self.assertGreater(self.album.added, 0)
|
||||
self.assertGreater(self.track.added, 0)
|
||||
|
||||
def test_atime_for_singleton(self):
|
||||
self.singleton = item()
|
||||
self.lib.add(self.singleton)
|
||||
self.assertGreater(self.singleton.itime, 0)
|
||||
self.assertGreater(self.singleton.added, 0)
|
||||
|
||||
def suite():
|
||||
return unittest.TestLoader().loadTestsFromName(__name__)
|
||||
|
|
|
|||
Loading…
Reference in a new issue