示例#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)
示例#2
0
    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 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")
示例#4
0
def parse(ufid_str):
    """Extract information from a UFID string.
    
    Args:
      ufid_str: A string, probably produced by a prior call to ufid()
      
    Returns:
      A (volume number, deposit timestamp, fingerprint) 3-tuple.

    Raises:
      ValueError: if ufid_str is invalid.
    """
    match = _UFID_RE.match(ufid_str)
    if match:
        vol = int(match.group(1), 16)
        ts = timestamp.parse_human_readable(match.group(2))
        fp = match.group(3)
        if vol > 0 and timestamp.is_valid(ts) and fingerprint.is_valid(fp):
            return vol, ts, fp
    raise ValueError("Bad UFID string \"%s\"" % ufid_str)
示例#5
0
def parse(ufid_str):
    """Extract information from a UFID string.
    
    Args:
      ufid_str: A string, probably produced by a prior call to ufid()
      
    Returns:
      A (volume number, deposit timestamp, fingerprint) 3-tuple.

    Raises:
      ValueError: if ufid_str is invalid.
    """
    match = _UFID_RE.match(ufid_str)
    if match:
        vol = int(match.group(1), 16)
        ts = timestamp.parse_human_readable(match.group(2))
        fp = match.group(3)
        if vol > 0 and timestamp.is_valid(ts) and fingerprint.is_valid(fp):
            return vol, ts, fp
    raise ValueError("Bad UFID string \"%s\"" % ufid_str)
                              
 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)
from chirp.library import constants
from chirp.library import database
from chirp.library import order
from chirp.library import titles

from chirp.common import chirpradio
from google.appengine.ext import db
from djdb import models
from djdb import search

START_TIMESTAMP = 0
start_at_flag = "--start-at="
for arg in sys.argv:
    if arg.startswith(start_at_flag):
        arg = arg[len(start_at_flag):]
        START_TIMESTAMP = timestamp.parse_human_readable(arg)
        break

# TODO(trow): Is this optimal?
_NUM_ALBUMS_PER_FLUSH = 3

_DISC_NUM_RE = re.compile("disc\s+(\d+)", re.IGNORECASE)

_artist_cache = {}

DRY_RUN = False


class UnknownArtistError(Exception):
    pass
from chirp.library import constants
from chirp.library import database
from chirp.library import order
from chirp.library import titles

from chirp.common import chirpradio
from google.appengine.ext import db
from djdb import models
from djdb import search

START_TIMESTAMP = 0
start_at_flag = "--start-at="
for arg in sys.argv:
    if arg.startswith(start_at_flag):
        arg = arg[len(start_at_flag):]
        START_TIMESTAMP = timestamp.parse_human_readable(arg)
        break

# TODO(trow): Is this optimal?
_NUM_ALBUMS_PER_FLUSH = 3

_DISC_NUM_RE = re.compile("disc\s+(\d+)", re.IGNORECASE)

_artist_cache = {}

DRY_RUN = False


class UnknownArtistError(Exception):
    pass