Beispiel #1
0
    def test_manifest_update_existing_aggregate(self):
        manifest = Manifest()
        manifest.add_aggregate("/test",
                               createdBy="Alice W.Land",
                               createdOn="2013-03-05T17:29:03Z",
                               mediatype="text/plain")

        contains = Aggregate("/test") in manifest.aggregates
        self.assertTrue(contains)
        a = manifest.get_aggregate("/test")
        a.createdBy.name = "Deckard"
        a = manifest.get_aggregate("/test")
        self.assertEquals(a.createdBy.name, "Deckard")
Beispiel #2
0
def remove(dir, file_uri_or_pattern, verbose=False, regexp=False):
    """
    Remove a specified research object component or components

    remove [ -d <dir> ] <file-or-uri>
    remove -d <dir> -w <pattern>
    """
    #Get the manifest file for this ro
    manifest_file_path = manifest_file(dir)
    manifest = Manifest(filename=manifest_file_path)

    if regexp:
        try:
            pattern = re.compile(file_uri_or_pattern)
        except re.error as e:
            #print('''%(rocmd)s remove -w "%(rofile)s" <...> : %(err)s''' % ro_options)
            return 1
        for aggregate in [ aggregate for aggregate in manifest.aggregates if pattern.search(str(aggregate.uri)) ]:
            manifest.remove_aggregate(aggregate)
        for annotation in [ annotation for annotation in manifest.annotations if pattern.search(str(annotation.uri)) ]:
            manifest.remove_annotation(annotation)
    else:
        aggregate = manifest.get_aggregate(file_uri_or_pattern)
        if aggregate:
            manifest.remove_aggregate(aggregate)
        annotation = manifest.get_annotation(file_uri_or_pattern)
        if annotation:
            manifest.remove_annotation(annotation)

    with open(manifest_file_path, 'w') as manifest_filehandle:
        manifest_filehandle.write(manifest.to_json())

    return 0
Beispiel #3
0
    def test_manifest_read_from_filename(self):
        m = Manifest(filename=TESTFN)

        a = m.get_aggregate("/README.txt")
        self.assertIsNotNone(a)
        self.assertEquals(a, Aggregate("/README.txt"))
        self.assertEquals(m.createdBy.name, "Alice W. Land")
        self.assertEquals(m.createdBy.orcid,
                          "http://orcid.org/0000-0002-1825-0097")
        self.assertEquals(m.createdBy.uri, "http://example.com/foaf#alice")
        m.add_aggregate(Aggregate("www.example.org/test"))
        m.add_aggregate(Aggregate("www.example.org/test", created_by="test"))
Beispiel #4
0
    def test_manifest_remove_aggregate(self):
        manifest = Manifest()
        manifest.add_aggregate("/test1",
                               createdBy="Alice W.Land",
                               createdOn="2013-03-05T17:29:03Z",
                               mediatype="text/plain")
        manifest.add_aggregate("/test2",
                               createdBy="Deckard",
                               createdOn="2013-04-03T14:12:55Z",
                               mediatype="text/plain")

        self.assertIn(Aggregate("/test1"), manifest.aggregates)
        manifest.remove_aggregate("/test1")
        self.assertNotIn(Aggregate("/test1"), manifest.aggregates)
        self.assertIn(Aggregate("/test2"), manifest.aggregates)

        aggregate = manifest.get_aggregate("/test2")
        manifest.remove_aggregate(aggregate)
        self.assertNotIn(aggregate, manifest.aggregates)