Пример #1
0
 def test_make_tag(self):
     # create a new tag
     parent_ns = Namespace('test')
     tag_name = str(uuid.uuid4())
     expected_path = 'test/%s' % tag_name
     result = make_tag(parent_ns, tag_name, 'flimp-test', 'For the'
                       ' purposes of testing flimp')
     self.assertEqual(expected_path, result.path)
     # try to create an existing tag (just return the existing one)
     result = make_tag(parent_ns, tag_name, 'flimp-test', 'For the'
                       ' purposes of testing flimp')
     self.assertEqual(expected_path, result.path)
     result.delete()
Пример #2
0
 def test_make_tag(self):
     # create a new tag
     parent_ns = Namespace('test')
     tag_name = str(uuid.uuid4())
     expected_path = 'test/%s' % tag_name
     result = make_tag(parent_ns, tag_name, 'flimp-test', 'For the'
                       ' purposes of testing flimp')
     self.assertEqual(expected_path, result.path)
     # try to create an existing tag (just return the existing one)
     result = make_tag(parent_ns, tag_name, 'flimp-test', 'For the'
                       ' purposes of testing flimp')
     self.assertEqual(expected_path, result.path)
     result.delete()
Пример #3
0
def push_to_fluiddb(directory, fluiddb_path, name, desc, uuid=None,
                    about=None):
    """
    Pushes the contents of the specified directory as tag-values on a
    specified object (if no uuid is given then it'll create a new object).

    Returns the object to which the tag-values have been added.

    root_dir - the path to the directory on the filesystem that will act as
    the root of the import

    fluiddb_path - the path to locate the namespace that maps to root_dir

    name - the name of the data that's being imported into FluidDB

    desc - a description of the data that's being imported into FluidDB

    uuid - the UUID to identify the object to be tagged

    about - the fluiddb/about tag value of the object to be tagged
    """
    # get the object we'll be using
    obj = get_object(uuid, about)

    # make sure we have the appropriate "fluidinfo_path" based namespaces
    # underneath the user's root namespace
    root_namespace = make_namespace_path(fluiddb_path, name, desc)

    # iterate over the filesystem creating the namespaces and tags (where
    # appropriate) and adding the tag value to the object
    for path, children, files in os.walk(directory):
        # still not pretty (ignoring hidden directories)
        for child in children:
            if os.path.basename(child).startswith('.'):
                children.remove(child)
        # create/check the namespace from the directory
        new_ns_name = path.replace(directory, '')
        if new_ns_name:
            # join the paths whilst remember to knock off the leading
            # slash from the new_ns_name
            ns_path = '/'.join([root_namespace.path, new_ns_name[1:]])
            new_ns = make_namespace(ns_path, name, desc)
        else:
            new_ns = root_namespace
        for f in files:
            if not f.startswith('.'): # ignore hidden files
                # create/check the tag from the filename
                new_tag = make_tag(new_ns, f, name, desc, False)
                file_path = os.path.join(path, f)
                logger.info('Preparing file %r for upload' % file_path)
                content_type, encoding = guess_type(file_path)
                logger.info('Content-Type of %r detected' % content_type)
                # now attach it to the object
                raw_file = open(file_path, 'r')
                logger.info('Pushing file %r to object %r on tag %r' %
                            (file_path, obj.uid, new_tag.path))
                obj.set(new_tag.path, raw_file.read(), content_type)
                logger.info('DONE!')
                raw_file.close()
    logger.info('Finished tagging the object with the uuid %r' % obj.uid)
    return obj
Пример #4
0
def push_to_fluiddb(directory,
                    fluiddb_path,
                    name,
                    desc,
                    uuid=None,
                    about=None):
    """
    Pushes the contents of the specified directory as tag-values on a
    specified object (if no uuid is given then it'll create a new object).

    Returns the object to which the tag-values have been added.

    root_dir - the path to the directory on the filesystem that will act as
    the root of the import

    fluiddb_path - the path to locate the namespace that maps to root_dir

    name - the name of the data that's being imported into FluidDB

    desc - a description of the data that's being imported into FluidDB

    uuid - the UUID to identify the object to be tagged

    about - the fluiddb/about tag value of the object to be tagged
    """
    # get the object we'll be using
    obj = get_object(uuid, about)

    # make sure we have the appropriate "fluidinfo_path" based namespaces
    # underneath the user's root namespace
    root_namespace = make_namespace_path(fluiddb_path, name, desc)

    # iterate over the filesystem creating the namespaces and tags (where
    # appropriate) and adding the tag value to the object
    for path, children, files in os.walk(directory):
        # still not pretty (ignoring hidden directories)
        for child in children:
            if os.path.basename(child).startswith('.'):
                children.remove(child)
        # create/check the namespace from the directory
        new_ns_name = path.replace(directory, '')
        if new_ns_name:
            # join the paths whilst remember to knock off the leading
            # slash from the new_ns_name
            ns_path = '/'.join([root_namespace.path, new_ns_name[1:]])
            new_ns = make_namespace(ns_path, name, desc)
        else:
            new_ns = root_namespace
        for f in files:
            if not f.startswith('.'):  # ignore hidden files
                # create/check the tag from the filename
                new_tag = make_tag(new_ns, f, name, desc, False)
                file_path = os.path.join(path, f)
                logger.info('Preparing file %r for upload' % file_path)
                content_type, encoding = guess_type(file_path)
                logger.info('Content-Type of %r detected' % content_type)
                # now attach it to the object
                raw_file = open(file_path, 'r')
                logger.info('Pushing file %r to object %r on tag %r' %
                            (file_path, obj.uid, new_tag.path))
                obj.set(new_tag.path, raw_file.read(), content_type)
                logger.info('DONE!')
                raw_file.close()
    logger.info('Finished tagging the object with the uuid %r' % obj.uid)
    return obj