Example #1
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
Example #2
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)