def main_generator(start_timestamp): #chirpradio.connect("10.0.1.98:8000") chirpradio.connect() sql_db = database.Database(conf.LIBRARY_DB) pending_albums = [] this_album = [] # TODO(trow): Select the albums to import in a saner way. for vol, import_timestamp in sql_db.get_all_imports(): if start_timestamp is not None and import_timestamp < start_timestamp: continue cprint("***") cprint("*** import_timestamp = %s" % timestamp.get_human_readable(import_timestamp)) cprint("***") for au_file in sql_db.get_by_import(vol, import_timestamp): if this_album and this_album[0].album_id != au_file.album_id: alb = album.Album(this_album) pending_albums.append(alb) cprint('Adding "%s"' % alb.title()) pending_albums = maybe_flush(pending_albums) this_album = [] this_album.append(au_file) yield # Add the last album to the list of pending albums, then do the # final flush. if this_album: alb = album.Album(this_album) cprint('Adding "%s"' % alb.title()) pending_albums.append(alb) this_album = [] flush(pending_albums)
def main(): #chirpradio.connect("10.0.1.98:8000") chirpradio.connect() sql_db = database.Database(conf.LIBRARY_DB) pending_albums = [] this_album = [] # TODO(trow): Select the albums to import in a saner way. for vol, import_timestamp in sql_db.get_all_imports(): if START_TIMESTAMP is not None and import_timestamp < START_TIMESTAMP: continue print "***" print "*** import_timestamp = %s" % timestamp.get_human_readable( import_timestamp) print "***" for au_file in sql_db.get_by_import(vol, import_timestamp): if this_album and this_album[0].album_id != au_file.album_id: alb = album.Album(this_album) pending_albums.append(alb) print 'Adding "%s"' % alb.title() pending_albums = maybe_flush(pending_albums) this_album = [] this_album.append(au_file) # Add the last album to the list of pending albums, then do the # final flush. if this_album: alb = album.Album(this_album) print 'Adding "%s"' % alb.title() pending_albums.append(alb) this_album = [] flush(pending_albums)
def test_basics(self): now = timestamp.now() self.assertTrue(timestamp.is_valid(now)) # Check that we can round-trip the timestamp produced by now() # through the human-readable format. human_readable = timestamp.get_human_readable(now) parsed = timestamp.parse_human_readable(human_readable) self.assertEqual(now, parsed) # Now check that a known example encodes correctly. ts = 1228080954 self.assertTrue(timestamp.is_valid(ts)) human_readable = timestamp.get_human_readable(ts) self.assertEqual("20081130-153554", human_readable) parsed = timestamp.parse_human_readable(human_readable) self.assertEqual(ts, parsed) # Make sure that calling timestamp.get_human_readable w/o an # argument returns a value for now. We retry a few times just # in case we are very unlucky and call timestamp.now() for the # second time after the second has incremented. for _ in range(3): now_str = timestamp.get_human_readable(timestamp.now()) no_arg_str = timestamp.get_human_readable() if no_arg_str == now_str: break else: self.assertTrue(False) # Check that is_valid will reject bad timestamps. self.assertFalse(timestamp.is_valid(-1)) self.assertFalse(timestamp.is_valid(0)) self.assertFalse(timestamp.is_valid(1000)) # The distant past self.assertFalse(timestamp.is_valid(1000000000000)) # The far future self.assertFalse( timestamp.is_valid(timestamp._MIN_REASONABLE_TIMESTAMP - 1)) self.assertFalse( timestamp.is_valid(timestamp._MAX_REASONABLE_TIMESTAMP + 1)) # Should raise ValueError on bad inputs. self.assertRaises(ValueError, timestamp.get_human_readable, 0) self.assertRaises(ValueError, timestamp.parse_human_readable, "malformed") self.assertRaises(ValueError, timestamp.parse_human_readable, "20081356-999999")
def ufid_prefix(volume, import_timestamp): """Returns the prefix of a UFID string. Args: volume: An integer volume number import_timestamp: A timestamp Returns: The leading substring of all UFIDs with the given volume and timestamp. """ return "vol%02x/%s/" % (volume, timestamp.get_human_readable(import_timestamp))
def test_basics(self): now = timestamp.now() self.assertTrue(timestamp.is_valid(now)) # Check that we can round-trip the timestamp produced by now() # through the human-readable format. human_readable = timestamp.get_human_readable(now) parsed = timestamp.parse_human_readable(human_readable) self.assertEqual(now, parsed) # Now check that a known example encodes correctly. ts = 1228080954 self.assertTrue(timestamp.is_valid(ts)) human_readable = timestamp.get_human_readable(ts) self.assertEqual("20081130-153554", human_readable) parsed = timestamp.parse_human_readable(human_readable) self.assertEqual(ts, parsed) # Make sure that calling timestamp.get_human_readable w/o an # argument returns a value for now. We retry a few times just # in case we are very unlucky and call timestamp.now() for the # second time after the second has incremented. for _ in range(3): now_str = timestamp.get_human_readable(timestamp.now()) no_arg_str = timestamp.get_human_readable() if no_arg_str == now_str: break else: self.assertTrue(False) # Check that is_valid will reject bad timestamps. self.assertFalse(timestamp.is_valid(-1)) self.assertFalse(timestamp.is_valid(0)) self.assertFalse(timestamp.is_valid(1000)) # The distant past self.assertFalse(timestamp.is_valid(1000000000000)) # The far future self.assertFalse(timestamp.is_valid(timestamp._MIN_REASONABLE_TIMESTAMP - 1)) self.assertFalse(timestamp.is_valid(timestamp._MAX_REASONABLE_TIMESTAMP + 1)) # Should raise ValueError on bad inputs. self.assertRaises(ValueError, timestamp.get_human_readable, 0) self.assertRaises(ValueError, timestamp.parse_human_readable, "malformed") self.assertRaises(ValueError, timestamp.parse_human_readable, "20081356-999999")