Beispiel #1
0
 def test_id_from_footer(self):
     footer = "Mutopia-2012/10/20-123"
     (pdate, id) = id_from_footer(footer)
     self.assertEqual(id, "123")
     # bad footers should just return false
     self.assertFalse(id_from_footer("bad-1882/4/4-999"))
     self.assertFalse(id_from_footer("Mutopia-today/5"))
Beispiel #2
0
 def test_id_from_footer(self):
     footer = 'Mutopia-2012/10/20-123'
     (pdate,id) = id_from_footer(footer)
     self.assertEqual(id, '123')
     # bad footers should just return false
     self.assertFalse(id_from_footer('bad-1882/4/4-999'))
     self.assertFalse(id_from_footer('Mutopia-today/5'))
Beispiel #3
0
    def test_id_from_footer(self):
        footer = 'Mutopia-2012/10/20-123'
        (pdate,id) = id_from_footer(footer)
        self.assertEqual(id, '123')

        # bad footers should just return false
        self.assertFalse(id_from_footer('bad-1882/4/4-999'))
        self.assertFalse(id_from_footer('Mutopia-today/5'))

        # cover the empty argument branch
        self.assertIsNone(id_from_footer(''))
Beispiel #4
0
    def test_can_build_rdf_graph(self):
        path = 'mutopia/tests/for-testing.rdf'

        g = Graph().parse(path)
        self.assertTrue(isinstance(g, Graph))

        # Because our RDF's are defined as 'rdf:about:"."' the subject
        # line is an URI reference to the absolute dirname.
        subj = URIRef('file://' + os.path.dirname(os.path.abspath(path)) + '/')

        footer = g.value(subject=subj, predicate=MP.id)
        self.assertEquals(str(footer), "Mutopia-2014/02/24-411")
        _, id = id_from_footer(footer)
        self.assertEqual(int(id), 411)
Beispiel #5
0
    def update_pieces(self):
        # get all RDF specs with a null piece reference
        rmap = AssetMap.objects.all().filter(piece__isnull=True)
        for r in rmap:
            path = '/'.join([
                FTP_URL,
                r.folder,
                r.name + '.rdf',
            ])
            print(path)
            graph = Graph().parse(URIRef(path))
            # Since we know the composer is required (which we have
            # from the spec) we can get the subject.
            mp_subj = graph.value(subject=None,
                                  predicate=MP.composer,
                                  object=Literal(r.get_composer()))

            # A footer isn't stored in the database but its bit parts are.
            footer = graph.value(mp_subj, MP.id)
            if footer is None:
                self.stderr.write('Failed to get footer from {0}'.format(path))
                break
            (pubdate, mutopia_id) = id_from_footer(footer)
            pdvec = [int(x) for x in pubdate.split('/')]

            # Determine if this is an update or a new piece
            piece = None
            status = None
            comp = Composer.objects.get(
                composer=graph.value(mp_subj, MP.composer))
            try:
                piece = Piece.objects.get(pk=mutopia_id)
                piece.title = graph.value(mp_subj, MP.title)
                piece.composer = comp
                status = 'update'
            except Piece.DoesNotExist:
                piece = Piece(piece_id=mutopia_id,
                              title=graph.value(mp_subj, MP.title),
                              composer=comp)
                status = 'new'

            # fill out the remainder of piece
            piece.style = Style.objects.get(pk=graph.value(mp_subj, MP.style))
            piece.raw_instrument = graph.value(mp_subj, MP['for'])
            piece.license = License.objects.get(
                name=graph.value(mp_subj, MP.licence))
            # use routines to get maintainer and version because we
            # might have to create them on the fly
            piece.maintainer = Contributor.find_or_create(
                graph.value(mp_subj, MP.maintainer),
                email=graph.value(mp_subj, MP.maintainerEmail),
                url=-graph.value(mp_subj, MP.maintainerWeb))
            piece.version = LPVersion.find_or_create(
                graph.value(mp_subj, MP.lilypondVersion))
            piece.lyricist = graph.value(mp_subj, MP.lyricist)
            piece.date_composed = graph.value(mp_subj, MP.date)
            piece.date_published = date(pdvec[0], pdvec[1], pdvec[2])
            piece.source = graph.value(mp_subj, MP.source)
            piece.moreinfo = graph.value(mp_subj, MP.moreInfo)
            piece.opus = graph.value(mp_subj, MP.opus)
            piece.save()
            r.piece = piece
            r.save()
            self.stdout.write('  {0}: {1}'.format(status, piece))
Beispiel #6
0
    def update_pieces(self):
        # get all RDF specs with a null piece reference
        rmap = AssetMap.objects.all().filter(piece__isnull=True)
        for r in rmap:
            path = '/'.join([
                FTP_URL,
                r.folder,
                r.name + '.rdf',
            ])
            self.stdout.write(path)
            try:
                graph = Graph().parse(URIRef(path))
            except (FileNotFoundError, HTTPError):
                # This AssetMap element is invalid somehow, just delete it.
                r.delete()
                continue

            # Because our RDF's are defined as 'rdf:about:"."' the subject
            # is an URI reference to the containing folder
            mp_subj = URIRef('/'.join([
                FTP_URL,
                r.folder,
            ]) + '/')

            # A footer isn't stored in the database but its bit parts are.
            footer = graph.value(mp_subj, MP.id)
            if footer is None:
                self.stderr.write('Failed to get footer from {0}'.format(path))
                break
            (pubdate, mutopia_id) = id_from_footer(footer)
            pdvec = [int(x) for x in pubdate.split('/')]

            # Determine if this is an update or a new piece
            piece = None
            status = None
            comp = Composer.objects.get(
                composer=graph.value(mp_subj, MP.composer))
            try:
                piece = Piece.objects.get(pk=mutopia_id)
                piece.title = graph.value(mp_subj, MP.title)
                piece.composer = comp
                status = 'update'
            except Piece.DoesNotExist:
                piece = Piece(piece_id=mutopia_id,
                              title=graph.value(mp_subj, MP.title),
                              composer=comp)
                status = 'new'

            # fill out the remainder of piece
            piece.style = Style.objects.get(pk=graph.value(mp_subj, MP.style))
            piece.raw_instrument = graph.value(mp_subj, MP['for'])
            piece.license = License.objects.get(
                name=graph.value(mp_subj, MP.licence))
            # use routines to get maintainer and version because we
            # might have to create them on the fly
            piece.maintainer = Contributor.find_or_create(
                graph.value(mp_subj, MP.maintainer),
                graph.value(mp_subj, MP.maintainerEmail),
                graph.value(mp_subj, MP.maintainerWeb))
            piece.version = LPVersion.find_or_create(
                graph.value(mp_subj, MP.lilypondVersion))
            piece.lyricist = graph.value(mp_subj, MP.lyricist)
            piece.date_composed = graph.value(mp_subj, MP.date)
            piece.date_published = date(pdvec[0], pdvec[1], pdvec[2])
            piece.source = graph.value(mp_subj, MP.source)
            piece.moreinfo = graph.value(mp_subj, MP.moreInfo)
            piece.opus = graph.value(mp_subj, MP.opus)
            piece.save()
            r.piece = piece
            r.save()
            self.stdout.write('  {0}: {1}'.format(status, piece))
Beispiel #7
0
    def update_pieces(self):
        # get all RDF specs with a null piece reference
        rmap = AssetMap.objects.all().filter(piece__isnull=True)
        for r in rmap:
            path = '/'.join([FTP_URL, r.folder, r.name+'.rdf',])
            self.stdout.write(path)
            try:
                graph = Graph().parse(URIRef(path))
            except (FileNotFoundError, HTTPError):
                # This AssetMap element is invalid somehow, just delete it.
                r.delete()
                continue

            # Because our RDF's are defined as 'rdf:about:"."' the subject
            # is an URI reference to the containing folder
            mp_subj = URIRef('/'.join([FTP_URL, r.folder,]) + '/')

            # A footer isn't stored in the database but its bit parts are.
            footer = graph.value(mp_subj, MP.id)
            if footer is None:
                self.stderr.write('Failed to get footer from {0}'.format(path))
                break
            (pubdate, mutopia_id) = id_from_footer(footer)
            pdvec = [ int(x) for x in pubdate.split('/') ]

            # Determine if this is an update or a new piece
            piece = None
            status = None
            comp = Composer.objects.get(composer=graph.value(mp_subj, MP.composer))
            try:
                piece = Piece.objects.get(pk=mutopia_id)
                piece.title = graph.value(mp_subj, MP.title)
                piece.composer = comp
                status = 'update'
            except Piece.DoesNotExist:
                piece = Piece(piece_id = mutopia_id,
                              title = graph.value(mp_subj, MP.title),
                              composer = comp)
                status = 'new'

            # fill out the remainder of piece
            piece.style = Style.objects.get(pk=graph.value(mp_subj,MP.style))
            piece.raw_instrument = graph.value(mp_subj, MP['for'])
            piece.license = License.objects.get(name=graph.value(mp_subj, MP.licence))
            # use routines to get maintainer and version because we
            # might have to create them on the fly
            piece.maintainer = Contributor.find_or_create(
                graph.value(mp_subj, MP.maintainer),
                graph.value(mp_subj, MP.maintainerEmail),
                graph.value(mp_subj, MP.maintainerWeb))
            piece.version = LPVersion.find_or_create(
                graph.value(mp_subj, MP.lilypondVersion))
            piece.lyricist = graph.value(mp_subj, MP.lyricist)
            piece.date_composed = graph.value(mp_subj, MP.date)
            piece.date_published = date(pdvec[0], pdvec[1], pdvec[2])
            piece.source = graph.value(mp_subj, MP.source)
            piece.moreinfo = graph.value(mp_subj, MP.moreInfo)
            piece.opus = graph.value(mp_subj, MP.opus)
            piece.save()
            r.piece = piece
            r.save()
            self.stdout.write('  {0}: {1}'.format(status, piece))