Beispiel #1
0
 def get_children(sid):
     sid = Sid(sid)  # make certain it is a Sid
     search_sid = sid + '*'
     if search_sid == sid:
         warn('Can not get children on a final sid.')
         return []
     return FS.get(search_sid)
Beispiel #2
0
    def get_as(self, attribute):  # note : should be used as get_as "cache"
        """
        Returns a copy of the Sid as the given attribute.
        Calls copy(until=attribute).

        Example:
        sid.get_as('task')  # Returns a Sid of type task.

        :param attribute:
        :return:
        """
        if not self.has_a(attribute):
            warn('Asked for a "{}" sid, but sid is incomplete. Returning None'.
                 format(attribute))
            return None
        return self.copy(until=attribute)
Beispiel #3
0
    def is_complete(self, until='project'):
        """
        Checks if a Sid is complete - all keys have values (all attributes return True) - until a given attribute.

        Intermediate optional keys are ignored.

        @param until: the last attribute that is checked
        """
        for key in self.data.keys():
            if not self.data.get(key):
                if key not in optional_keys:
                    return False
            if key == until:
                return bool(self.data.get(key))
        warn('[Sid] could not verify completeness of self "{0}" until "{1}"'.
             format(self, until))
        return False  # malformed or until malformed?
Beispiel #4
0
    def __add__(self, other):
        """
        Adds a value at the end of the Sid and returns the result.

        If the Sid is complete, a copy is returned without anything added.

        :param other:
        :return:
        """
        if len(self) == len(self.keys):
            warn(
                'Sid {} is already complete. Concatenation impossible.'.format(
                    self))
            return self.copy()
        other = str(other)
        if not other.startswith(sip):
            other = sip + other
        result = str(self) + other
        return Sid(result)
def get_members(obj, param=None):  # FIXME : proper attribute test
    result = {}
    for name in get_member_names(obj):
        attribute = getattr(obj, name, '--NOT SET--')
        if callable(attribute):
            #attribute()
            try:
                result[name] = attribute()
            except TypeError as te:
                if param:
                    try:
                        result[name] = attribute(param)
                    except Exception as e:
                        warn(e)
                        result[name] = 'ERROR'
                else:
                    result[name] = 'ERROR'
        else:
            result[name] = attribute
    return result
Beispiel #6
0
def sid_to_dict(sid):

    templates = []

    for name, pattern in six.iteritems(sid_templates):
        template = Template(
            name,
            pattern,
            anchor=lucidity.Template.ANCHOR_BOTH,
            default_placeholder_expression=
            '[^/]*',  # allows for empty keys // should it be '[^|]*' ?
            duplicate_placeholder_mode=lucidity.Template.STRICT)
        # template.template_resolver = resolvers
        templates.append(template)

    try:
        """
        if len(sid.split('/')) >= 8:
            data = []
            for ext in sid.split('/')[-1].split(','):
                sid_copy = sid
                sid_copy = sid_copy.replace(sid_copy.split('/')[-1], ext)
                data.extend(lucidity.parse(str(sid_copy), templates)[0])
        else:
        """
        data, template = lucidity.parse(str(sid), templates)

        # print 'found', data, template
    except Exception as e:
        warn(e)
        return None

    if not data:
        return None
    '''
    for key in list(data.keys()):
        if key not in shot_keys + asset_keys:
            data.pop(key)
    '''
    # return template.name, data  # need the name ?
    return data
Beispiel #7
0
def path_to_dict(path):

    path = str(path)
    # path = os.path.normcase(path)
    path = path.replace(os.sep, '/')

    templates = []
    for name, pattern in six.iteritems(path_templates):
        template = Template(
            name,
            pattern,
            anchor=lucidity.Template.ANCHOR_BOTH,
            default_placeholder_expression=
            '[^/]*',  # needed to use '#' for a path
            duplicate_placeholder_mode=lucidity.Template.STRICT)
        template.template_resolver = resolvers

        templates.append(template)

    try:
        data, template = lucidity.parse(path, templates)
        # print 'found', data, template
    except Exception as e:
        warn(e)
        return None, None

    if not data:
        return None, None
    for key, value in six.iteritems(data):
        if path_mapping.get(key):
            value = path_mapping.get(key).get(value, value)
            data[key] = value

    for key in list(data.keys()):
        if key not in shot_keys + asset_keys:
            data.pop(key)

    return template.name, data  # need the name ?
def by_sids(tests):

    for test in tests:

        info('Testing : {}'.format(test))
        info('')

        test = Sid(test)

        _dict = test.asdict()
        _type = test.sidtype()
        info('Initial sid dict : {}'.format(_dict))
        info('Initial sid basetype : {}'.format(_type))

        path = None
        try:
            path = dict_to_path(_dict)
            info('Resolved to path : {}'.format(path))
        except SpilException as e:
            info('Unable to resolve path because : {}'.format(e))

            test = test.parent(set_default=True)  # we try to level one up
            if test:
                info('Sid up one level (parent)...')
                warn('Sid is now : {}'.format(test))
                _dict = test.asdict()
                _type = test.sidtype()
                info('Sid dict is now : {}'.format(_dict))
                path = dict_to_path(
                    test.asdict())  # do not catch error if this doesnt work
                info('Resolved to path : {}'.format(path))

        _type, retour = path_to_dict(path)

        if _type:
            info('Retour resolved')
        else:
            info('No match.')
            continue

        info('Resolved retour dict : {}'.format(retour))
        info('')
        # assert (_dict == retour)  # dicts do not need to be identical.

        retour = Sid(data=retour)
        info('Retour sid : {}'.format(retour))
        info('')
        warn('test ' + str(test))
        warn('test ' + str(retour))
        assert (test == retour)

        info('')
        info('*' * 30)
        info('')
Beispiel #9
0
 def get(self, attribute):
     if str(attribute) not in self.data.keys():
         warn('Attribute... "{}" not in Sid definition of {}. Return None'.
              format(attribute, self))
         return None
     return self.data.get(attribute)
Beispiel #10
0
    def get(search_sid):
        """
        Finds Sids based on the given search Sid, using the Glob syntax.

        Returns a sorted, uniqued list

        :param search_sid:
        :return: result list
        """

        search = Sid(search_sid)

        # filling intermediate values with *
        last_key = search.last_key()
        search = search.get_filled(by='*', until=last_key)

        debug('Search : ' + str(search))
        info('PATH : {}'.format(search.path))
        path = search.path

        if not path:
            warn('Search sid {} did not resolve to a path. Cancelled.'.format(
                search))
            return []

        debug('Search path : ' + str(path))

        project = Sid(search.get('project'))
        # TODO need a way to find a root path depending on other sid parts (eg: fx caches)
        project_path = project.path

        pattern = path.split(project_path + '/')[-1]

        for key, value in six.iteritems(search_path_mapping):
            pattern = pattern.replace(key, value)

        debug('pattern : ' + str(pattern))
        debug('project_path : ' + str(project_path))

        if str(pattern) == str(project_path):
            warn('No valid search pattern')
            return []
        """
        found = []
        for ext in pattern.split('.')[-1].split(','):
            new_pattern = pattern.split('.')[0] + '.' + ext
            found.extend(glob.glob(os.path.join(project_path, new_pattern)))
        """
        found = glob.glob(os.path.join(project_path, pattern))
        result = []
        for path in found:
            path = str(path).replace(os.sep, '/')
            try:
                sid = Sid(path=path)
            except SpilException as e:
                debug('Path did not generate sid : {}'.format(path))
                continue
            if not sid:
                warn('Path did not generate sid : {}'.format(path))
                continue
            result.append(sid)

        result = sorted(list(set(result)))
        return result