Esempio n. 1
0
 def test_basic(self):
     test_vol = 11
     test_ts_human = "20090102-030405"
     test_ts = timestamp.parse_human_readable(test_ts_human)
     test_fp = "1234" * 10
     # The UFID prefix should contain the volume and timestamp info.
     self.assertEqual(
         "vol0b/%s/" % test_ts_human,  # 0b = 11
         ufid.ufid_prefix(test_vol, test_ts))
     # The UFID should equal the UFID prefix + the fingerprint.
     test_ufid = ufid.ufid(test_vol, test_ts, test_fp)
     self.assertEqual(
         ufid.ufid_prefix(test_vol, test_ts) + test_fp, test_ufid)
     # We should be able to make a tag too.
     test_tag = ufid.ufid_tag(test_vol, test_ts, test_fp)
     self.assertEqual("UFID", test_tag.FrameID)
     self.assertEqual(constants.UFID_OWNER_IDENTIFIER, test_tag.owner)
     self.assertEqual(test_ufid, test_tag.data)
     # Make sure we can parse information back out of the test UFID.
     vol, ts, fp = ufid.parse(test_ufid)
     self.assertEqual(test_vol, vol)
     self.assertEqual(test_ts, ts)
     self.assertEqual(test_fp, fp)
     # Raise ValueError if we try to parse a bad UFID.
     self.assertRaises(ValueError, ufid.parse, "bad")
     self.assertRaises(ValueError, ufid.parse,
                       "vol01/20091399-666666/" + "1" * 40)
     self.assertRaises(ValueError, ufid.parse,
                       "vol01/20991001-123456" + "1" * 40)
 def commit(self, target_prefix):
     if self._dry_run:
         return
     # Start a database transaction to add the files.
     txn = self._db.begin_add(self._volume, self._import_timestamp)
     # Write each new file into the database.
     for au_file in self._all_au_files:
         txn.add(au_file)
     ufid_prefix = ufid.ufid_prefix(self._volume, self._import_timestamp)
     # Strip off trailing "/"
     if ufid_prefix.endswith("/"):
         ufid_prefix = ufid_prefix[:-1]
     tmp_dir = os.path.join(self._tmp_prefix, ufid_prefix)
     real_dir = os.path.join(target_prefix, ufid_prefix)
     cprint("*** Committing %d albums / %d bytes" % (
         self.num_albums, self.total_size_in_bytes))
     cprint("*** tmp_dir=%s" % tmp_dir)
     cprint("*** real_dir=%s" % real_dir)
     sys.stdout.flush()
     os.renames(tmp_dir, real_dir)
     txn.commit()
     # Write out a list of source files that were just committed.
     out = open(os.path.join(real_dir, "_source_files"), "w")
     for path in sorted(af.path for af in self._all_au_files):
         out.write(path)
         out.write("\n")
     out.close()
Esempio n. 3
0
 def commit(self, target_prefix):
     if self._dry_run:
         return
     # Start a database transaction to add the files.
     txn = self._db.begin_add(self._volume, self._import_timestamp)
     # Write each new file into the database.
     for au_file in self._all_au_files:
         txn.add(au_file)
     ufid_prefix = ufid.ufid_prefix(self._volume, self._import_timestamp)
     # Strip off trailing "/"
     if ufid_prefix.endswith("/"):
         ufid_prefix = ufid_prefix[:-1]
     tmp_dir = os.path.join(self._tmp_prefix, ufid_prefix)
     real_dir = os.path.join(target_prefix, ufid_prefix)
     cprint("*** Committing %d albums / %d bytes" %
            (self.num_albums, self.total_size_in_bytes))
     cprint("*** tmp_dir=%s" % tmp_dir)
     cprint("*** real_dir=%s" % real_dir)
     sys.stdout.flush()
     os.renames(tmp_dir, real_dir)
     txn.commit()
     # Write out a list of source files that were just committed.
     out = open(os.path.join(real_dir, "_source_files"), "w")
     for path in sorted(af.path for af in self._all_au_files):
         out.write(path)
         out.write("\n")
     out.close()
Esempio n. 4
0
    def canonical_directory(self, prefix=""):
        """Returns the storage directory for this file.

        This call will fail if has_ufid() returns False.

        Args:
          prefix: The directory prefix to use.

        Returns:
          The directory containing this file inside the storage tree
          rooted at 'prefix'.
        """
        return os.path.join(
            prefix, ufid.ufid_prefix(self.volume, self.import_timestamp))
Esempio n. 5
0
    def canonical_directory(self, prefix=""):
        """Returns the storage directory for this file.

        This call will fail if has_ufid() returns False.

        Args:
          prefix: The directory prefix to use.

        Returns:
          The directory containing this file inside the storage tree
          rooted at 'prefix'.
        """
        return os.path.join(prefix,
                            ufid.ufid_prefix(self.volume,
                                             self.import_timestamp))
 def test_basic(self):
     test_vol = 11
     test_ts_human = "20090102-030405"
     test_ts = timestamp.parse_human_readable(test_ts_human)
     test_fp = "1234" * 10
     # The UFID prefix should contain the volume and timestamp info.
     self.assertEqual("vol0b/%s/" % test_ts_human, ufid.ufid_prefix(test_vol, test_ts))  # 0b = 11
     # The UFID should equal the UFID prefix + the fingerprint.
     test_ufid = ufid.ufid(test_vol, test_ts, test_fp)
     self.assertEqual(ufid.ufid_prefix(test_vol, test_ts) + test_fp, test_ufid)
     # We should be able to make a tag too.
     test_tag = ufid.ufid_tag(test_vol, test_ts, test_fp)
     self.assertEqual("UFID", test_tag.FrameID)
     self.assertEqual(constants.UFID_OWNER_IDENTIFIER, test_tag.owner)
     self.assertEqual(test_ufid, test_tag.data)
     # Make sure we can parse information back out of the test UFID.
     vol, ts, fp = ufid.parse(test_ufid)
     self.assertEqual(test_vol, vol)
     self.assertEqual(test_ts, ts)
     self.assertEqual(test_fp, fp)
     # Raise ValueError if we try to parse a bad UFID.
     self.assertRaises(ValueError, ufid.parse, "bad")
     self.assertRaises(ValueError, ufid.parse, "vol01/20091399-666666/" + "1" * 40)
     self.assertRaises(ValueError, ufid.parse, "vol01/20991001-123456" + "1" * 40)
Esempio n. 7
0
    au_file.mutagen_id3.add(talb)
    trck = mutagen.id3.TRCK(text=["%d/7" % ((n % 7) + 1)])
    au_file.mutagen_id3.add(trck)
    talb = mutagen.id3.TPUB(text=["  Bad    whitespace    "])
    au_file.mutagen_id3.add(talb)
    # Finally return the thing.
    return au_file


get_test_audio_file.__test__ = False  # not a test itself

TEST_VOL = 65
TEST_TS = 1230430574
TEST_FP = "7" * 40
TEST_UFID = ufid.ufid(TEST_VOL, TEST_TS, TEST_FP)
TEST_UFID_PREFIX = ufid.ufid_prefix(TEST_VOL, TEST_TS)


class AudioFileTest(unittest.TestCase):
    def test_basic(self):
        # Assemble a basic test object.
        au_file = audio_file.AudioFile()
        au_file.volume = TEST_VOL
        au_file.import_timestamp = TEST_TS
        au_file.fingerprint = TEST_FP

        # Check the generated UFID.
        self.assertEqual(TEST_UFID, au_file.ufid())

        # Check the generated UFID tag.
        ufid_tag = au_file.ufid_tag()
    au_file.mutagen_id3.add(talb)
    trck = mutagen.id3.TRCK(text=["%d/7" % ((n % 7) + 1)])
    au_file.mutagen_id3.add(trck)
    talb = mutagen.id3.TPUB(text=["  Bad    whitespace    "])
    au_file.mutagen_id3.add(talb)
    # Finally return the thing.
    return au_file

get_test_audio_file.__test__ = False  # not a test itself


TEST_VOL = 65
TEST_TS = 1230430574
TEST_FP = "7" * 40
TEST_UFID = ufid.ufid(TEST_VOL, TEST_TS, TEST_FP)
TEST_UFID_PREFIX = ufid.ufid_prefix(TEST_VOL, TEST_TS)


class AudioFileTest(unittest.TestCase):

    def test_basic(self):
        # Assemble a basic test object.
        au_file = audio_file.AudioFile()
        au_file.volume = TEST_VOL
        au_file.import_timestamp = TEST_TS
        au_file.fingerprint = TEST_FP

        # Check the generated UFID.
        self.assertEqual(TEST_UFID, au_file.ufid())
        
        # Check the generated UFID tag.